mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 20:13:49 +01:00
Ongoing development.
This commit is contained in:
@@ -34,8 +34,14 @@ class GeoJsonController
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$collection = $this->mapService->getFeatureCollection(\Input::get('id'));
|
||||
try {
|
||||
$collection = $this->mapService->getFeatureCollection(\Input::get('id'));
|
||||
|
||||
return json_encode($collection);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($collection, JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
header('HTTP/1.0 403 Forbidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,30 @@ class Layer
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
|
||||
}
|
||||
|
||||
public function generateVectorsButton($row, $href, $label, $title, $icon, $attributes)
|
||||
{
|
||||
if (empty($this->layers[$row['type']]['vectors'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
* @param $href
|
||||
* @param $label
|
||||
* @param $title
|
||||
* @param $icon
|
||||
* @param $attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateButton($row, $href, $label, $title, $icon, $attributes)
|
||||
{
|
||||
return sprintf(
|
||||
'<a href="%s" title="%s">%s</a> ',
|
||||
\Backend::addToUrl($href . '&id=' . $row['id']),
|
||||
|
||||
@@ -51,8 +51,8 @@ class Leaflet
|
||||
$template->field = 'ctrl_' . $dataContainer->field;
|
||||
|
||||
try {
|
||||
$latLng = LatLng::fromString($dataContainer->value);
|
||||
$template->marker = $latLng->toJson();
|
||||
$latLng = LatLng::fromString($dataContainer->value);
|
||||
$template->marker = json_encode($latLng);
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -21,4 +21,11 @@ class AbstractLayerMapper extends AbstractTypeMapper
|
||||
* @var string
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addOption('label', 'title');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,12 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
|
||||
use Netzmacht\Javascript\Type\Value\Reference;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
|
||||
|
||||
class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
@@ -58,21 +59,25 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
protected function doBuild(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
) {
|
||||
if ($definition instanceof GeoJsonAjax) {
|
||||
$base = \Config::get('websitePath') . '/system/modules/leaflet/public/geojson.php?id=';
|
||||
$base = \Config::get('websitePath') . '/assets/leaflet/geojson.php?id=';
|
||||
$definition->setUrl($base . $model->id);
|
||||
} elseif ($definition instanceof LayerGroup) {
|
||||
$collection = $this->loadMarkerModels($model);
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $item) {
|
||||
$definition->addLayer($this->createMarker($item));
|
||||
$definition->addLayer($mapper->handle($item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition instanceof GeoJson) {
|
||||
$definition->setPointToLayer(new Reference('ContaoLeaflet.pointToLayer', 'ContaoLeaflet'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,26 +94,13 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $item) {
|
||||
$feature->addFeature($this->createMarker($item)->getFeature());
|
||||
$feature->addFeature($mapper->handle($item)->toGeoJson());
|
||||
}
|
||||
}
|
||||
|
||||
return $feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $item
|
||||
*
|
||||
* @return Marker
|
||||
*/
|
||||
protected function createMarker($item)
|
||||
{
|
||||
$marker = new Marker('marker_' . $item->id, $item->coordinates);
|
||||
$marker->setTitle($item->tooltip);
|
||||
|
||||
return $marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Model $model
|
||||
*
|
||||
|
||||
74
src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php
Normal file
74
src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2015 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\UI;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
|
||||
class MarkerMapper extends AbstractMapper
|
||||
{
|
||||
/**
|
||||
* Class of the model being build.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\MarkerModel';
|
||||
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\UI\Marker';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
$arguments = parent::buildConstructArguments($model, $mapper, $bounds);
|
||||
$arguments[] = $model->coordinates ?: null;
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
$this
|
||||
->addConditionalOption('tooltip', 'title', 'tooltip')
|
||||
->addConditionalOption('alt')
|
||||
->addOptions('clickable', 'keyboard', 'draggable');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doBuild(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
) {
|
||||
if ($definition instanceof Marker) {
|
||||
if ($model->addPopup) {
|
||||
$definition->bindPopup($model->popupContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ HTML;
|
||||
$object = $event->getObject();
|
||||
|
||||
if ($object instanceof Map) {
|
||||
$line = sprintf('window.ContaoLeaflet.addMap(\'%s\', (function() {', $object->getId());
|
||||
$line = sprintf('ContaoLeaflet.addMap(\'%s\', (function() {', $object->getId());
|
||||
$event->getOutput()->addLine($line);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user