mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Ongoing development.
This commit is contained in:
@@ -47,7 +47,8 @@
|
||||
},
|
||||
"contao": {
|
||||
"sources":{
|
||||
"module": "system/modules/leaflet"
|
||||
"module": "system/modules/leaflet",
|
||||
"assets": "assets/leaflet"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ L.Contao = L.Class.extend( {
|
||||
addMap: function (id, map) {
|
||||
this.maps[id] = map;
|
||||
|
||||
this.fire('mapadded', { id: id, map: map});
|
||||
this.fire('map:added', { id: id, map: map});
|
||||
|
||||
return this;
|
||||
},
|
||||
@@ -17,9 +17,28 @@ L.Contao = L.Class.extend( {
|
||||
}
|
||||
|
||||
return this.maps[id];
|
||||
},
|
||||
|
||||
pointToLayer: function(feature, latlng) {
|
||||
var marker = L.marker(latlng, feature.properties.options);
|
||||
|
||||
this.applyFeatureMethods(marker, feature);
|
||||
this.fire('marker:created', { marker: marker, feature: feature, latlng: latlng });
|
||||
|
||||
return marker;
|
||||
},
|
||||
|
||||
applyFeatureMethods: function(obj, feature) {
|
||||
if (feature.properties && feature.properties.methods) {
|
||||
for (var i=0; i < feature.properties.methods.length; i++) {
|
||||
var method = feature.properties.methods[i];
|
||||
|
||||
obj[method[0]].apply(obj, method[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
L.Icon.Default.imagePath = 'system/modules/leaflet/assets/leaflet/leaflet/images';
|
||||
L.Icon.Default.imagePath = 'assets/leaflet/libs/leaflet/images';
|
||||
|
||||
window.ContaoLeaflet = new L.Contao();
|
||||
|
||||
@@ -4,7 +4,14 @@
|
||||
* Backend module.
|
||||
*/
|
||||
$GLOBALS['BE_MOD']['content']['leaflet'] = array(
|
||||
'tables' => array('tl_leaflet_map', 'tl_leaflet_layer', 'tl_leaflet_control', 'tl_leaflet_marker'),
|
||||
'tables' => array(
|
||||
'tl_leaflet_map',
|
||||
'tl_leaflet_layer',
|
||||
'tl_leaflet_control',
|
||||
'tl_leaflet_marker',
|
||||
'tl_leaflet_vector',
|
||||
'tl_leaflet_icon',
|
||||
),
|
||||
'icon' => 'system/modules/leaflet/assets/img/leaflet.png',
|
||||
'stylesheet' => 'system/modules/leaflet/assets/css/backend.css',
|
||||
);
|
||||
@@ -37,6 +44,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ZoomCon
|
||||
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ScaleControlMapper';
|
||||
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\LayersControlMapper';
|
||||
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\AttributionControlMapper';
|
||||
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper';
|
||||
|
||||
/*
|
||||
* Leaflet encoders.
|
||||
@@ -98,6 +106,7 @@ $GLOBALS['LEAFLET_LAYERS'] = array
|
||||
(
|
||||
'children' => false,
|
||||
'icon' => 'system/modules/leaflet/assets/img/vectors.png',
|
||||
'vectors' => true,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -132,22 +141,22 @@ require_once TL_ROOT . '/system/modules/leaflet/config/leaflet_providers.php';
|
||||
*/
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet'] = array(
|
||||
'css' => array(
|
||||
array('system/modules/leaflet/assets/leaflet/leaflet/leaflet.css', 'file')
|
||||
array('assets/leaflet/libs/leaflet/leaflet.css', 'file')
|
||||
),
|
||||
'javascript' => array(
|
||||
array('system/modules/leaflet/assets/leaflet/leaflet/leaflet.js', 'file')
|
||||
array('assets/leaflet/libs/leaflet/leaflet.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet-providers'] = array(
|
||||
'javascript' => array(
|
||||
array('system/modules/leaflet/assets/leaflet/leaflet-providers/leaflet-providers.js', 'file')
|
||||
array('assets/leaflet/libs/leaflet-providers/leaflet-providers.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['LEAFLET_ASSETS']['leaflet-ajax'] = array(
|
||||
'javascript' => array(
|
||||
array('system/modules/leaflet/assets/leaflet/leaflet-ajax/leaflet.ajax.min.js', 'file')
|
||||
array('assets/leaflet/libs/leaflet-ajax/leaflet.ajax.min.js', 'file')
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
257
module/dca/tl_leaflet_icon.php
Normal file
257
module/dca/tl_leaflet_icon.php
Normal file
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
|
||||
(
|
||||
'config' => array(
|
||||
'dataContainer' => 'Table',
|
||||
'enableVersioning' => true,
|
||||
'ptable' => 'tl_leaflet_layer',
|
||||
'sql' => array
|
||||
(
|
||||
'keys' => array
|
||||
(
|
||||
'id' => 'primary'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
'list' => array
|
||||
(
|
||||
'sorting' => array
|
||||
(
|
||||
'mode' => 1,
|
||||
'fields' => array('title'),
|
||||
'flag' => 1,
|
||||
'headerFields' => array('title', 'type'),
|
||||
'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'generateRow'),
|
||||
),
|
||||
'label' => array
|
||||
(
|
||||
'fields' => array('title'),
|
||||
'format' => '%s',
|
||||
),
|
||||
'global_operations' => array
|
||||
(
|
||||
'map' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['map'],
|
||||
'href' => 'table=tl_leaflet_map',
|
||||
'icon' => 'system/modules/leaflet/assets/img/leaflet.png',
|
||||
'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="m"'
|
||||
),
|
||||
'all' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
|
||||
'href' => 'act=select',
|
||||
'class' => 'header_edit_all',
|
||||
'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"'
|
||||
),
|
||||
),
|
||||
'operations' => array
|
||||
(
|
||||
'edit' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['edit'],
|
||||
'href' => 'act=edit',
|
||||
'icon' => 'edit.gif'
|
||||
),
|
||||
'copy' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['copy'],
|
||||
'href' => 'act=copy',
|
||||
'icon' => 'copy.gif'
|
||||
),
|
||||
'delete' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['delete'],
|
||||
'href' => 'act=delete',
|
||||
'icon' => 'delete.gif',
|
||||
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
|
||||
),
|
||||
'toggle' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['toggle'],
|
||||
'icon' => 'visible.gif',
|
||||
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
|
||||
'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback(
|
||||
'tl_leaflet_icon',
|
||||
'active'
|
||||
)
|
||||
),
|
||||
'show' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['show'],
|
||||
'href' => 'act=show',
|
||||
'icon' => 'show.gif'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
'metapalettes' => array(
|
||||
'default' => array(
|
||||
'title' => array('title', 'alias', 'type'),
|
||||
'content' => array('tooltip', 'alt',),
|
||||
'config' => array(
|
||||
':hide',
|
||||
'iconUrl',
|
||||
'iconRetinaUrl',
|
||||
'iconAnchor',
|
||||
'popupAnchor',
|
||||
'iconClassName',
|
||||
'shadowImage',
|
||||
'shadowRetinaImage',
|
||||
'shadowAnchor',
|
||||
),
|
||||
'active' => array('active')
|
||||
),
|
||||
),
|
||||
|
||||
'fields' => array
|
||||
(
|
||||
'id' => array
|
||||
(
|
||||
'sql' => "int(10) unsigned NOT NULL auto_increment"
|
||||
),
|
||||
'tstamp' => array
|
||||
(
|
||||
'sql' => "int(10) unsigned NOT NULL default '0'"
|
||||
),
|
||||
'pid' => array
|
||||
(
|
||||
'sql' => "int(10) unsigned NOT NULL default '0'"
|
||||
),
|
||||
'title' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['title'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'),
|
||||
'sql' => "varchar(255) NOT NULL default ''"
|
||||
),
|
||||
'alias' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['alias'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
|
||||
'sql' => "varchar(255) NOT NULL default ''"
|
||||
),
|
||||
'active' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['active'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'checkbox',
|
||||
'eval' => array('tl_class' => 'w50'),
|
||||
'sql' => "char(1) NOT NULL default ''"
|
||||
),
|
||||
'iconUrl' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_content']['iconUrl'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'fileTree',
|
||||
'eval' => array(
|
||||
'filesOnly' => true,
|
||||
'fieldType' => 'radio',
|
||||
'mandatory' => true,
|
||||
'tl_class' => 'clr w50',
|
||||
'extensions' => 'gif,png,svg,jpg'
|
||||
),
|
||||
'sql' => "binary(16) NULL",
|
||||
),
|
||||
'iconRetinaUrl' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_content']['iconRetinaUrl'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'fileTree',
|
||||
'eval' => array(
|
||||
'filesOnly' => true,
|
||||
'fieldType' => 'radio',
|
||||
'mandatory' => false,
|
||||
'tl_class' => 'w50',
|
||||
'extensions' => 'gif,png,svg,jpg'
|
||||
),
|
||||
'sql' => "binary(16) NULL",
|
||||
),
|
||||
'shadowImage' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowImage'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'fileTree',
|
||||
'eval' => array(
|
||||
'filesOnly' => true,
|
||||
'fieldType' => 'radio',
|
||||
'mandatory' => false,
|
||||
'tl_class' => 'clr w50',
|
||||
'extensions' => 'gif,png,svg,jpg'
|
||||
),
|
||||
'sql' => "binary(16) NULL",
|
||||
),
|
||||
'shadowRetinaImage' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowRetinaImage'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'fileTree',
|
||||
'eval' => array(
|
||||
'filesOnly' => true,
|
||||
'fieldType' => 'radio',
|
||||
'mandatory' => false,
|
||||
'tl_class' => 'w50',
|
||||
'extensions' => 'gif,png,svg,jpg'
|
||||
),
|
||||
'sql' => "binary(16) NULL",
|
||||
),
|
||||
'iconAnchor' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconAnchor'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'save_callback' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
|
||||
),
|
||||
'eval' => array(
|
||||
'maxlength' => 255,
|
||||
'tl_class' => 'w50',
|
||||
'nullIfEmpty' => true,
|
||||
),
|
||||
'sql' => "varchar(255) NULL"
|
||||
),
|
||||
'shadowAnchor' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowAnchor'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'save_callback' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
|
||||
),
|
||||
'eval' => array(
|
||||
'maxlength' => 255,
|
||||
'tl_class' => 'w50',
|
||||
'nullIfEmpty' => true,
|
||||
),
|
||||
'sql' => "varchar(255) NULL"
|
||||
),
|
||||
'popupAnchor' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['popupAnchor'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'save_callback' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
|
||||
),
|
||||
'eval' => array(
|
||||
'maxlength' => 255,
|
||||
'tl_class' => 'w50',
|
||||
'nullIfEmpty' => true,
|
||||
),
|
||||
'sql' => "varchar(255) NULL"
|
||||
),
|
||||
'className' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['className'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
|
||||
'sql' => "varchar(255) NOT NULL default ''"
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -55,6 +55,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
||||
'icon' => 'edit.gif',
|
||||
'button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateMarkersButton'),
|
||||
),
|
||||
'vectors' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['vectors'],
|
||||
'href' => 'table=tl_leaflet_vector',
|
||||
'icon' => 'edit.gif',
|
||||
'button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateVectorsButton'),
|
||||
),
|
||||
'edit' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['edit'],
|
||||
@@ -108,10 +115,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
||||
'default' => array(
|
||||
'title' => array('title', 'alias', 'type'),
|
||||
'active' => array('active'),
|
||||
'expert' => array('deferred'),
|
||||
),
|
||||
'markers extends default' => array(
|
||||
'+title' => array('markerCluster'),
|
||||
'+title' => array('markerCluster'),
|
||||
'+active' => array('deferred')
|
||||
),
|
||||
),
|
||||
|
||||
@@ -243,7 +250,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
||||
),
|
||||
'deferred' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['deferred'],
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'checkbox',
|
||||
'eval' => array('tl_class' => 'w50', 'submitOnChange' => false),
|
||||
|
||||
@@ -37,6 +37,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
|
||||
'icon' => 'system/modules/leaflet/assets/img/layers.png',
|
||||
'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"'
|
||||
),
|
||||
'icons' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['icons'],
|
||||
'href' => 'table=tl_leaflet_icon',
|
||||
'icon' => 'system/modules/leaflet/assets/img/layers.png',
|
||||
'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"'
|
||||
),
|
||||
'all' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
|
||||
|
||||
@@ -189,7 +189,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'checkbox',
|
||||
'default' => true,
|
||||
'eval' => array('tl_class' => 'w50', 'submitOnChange' => true),
|
||||
'sql' => "char(1) NOT NULL default ''"
|
||||
),
|
||||
@@ -198,7 +197,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'default' => true,
|
||||
'eval' => array('mandatory' => true, 'rte' => 'tinyMCE', 'helpwizard' => true, 'tl_class' => 'clr'),
|
||||
'explanation' => 'insertTags',
|
||||
'sql' => "mediumtext NULL"
|
||||
@@ -208,7 +206,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'checkbox',
|
||||
'default' => true,
|
||||
'eval' => array('tl_class' => 'w50', 'submitOnChange' => true),
|
||||
'sql' => "char(1) NOT NULL default ''"
|
||||
),
|
||||
|
||||
@@ -34,3 +34,5 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['active'][0] = 'Activate
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['active'][1] = 'Activate layer on the map.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][0] = 'Marker cluster';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][1] = 'Choose a marker cluster layer so that markers get clustered.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][0] = 'Deferred loading';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][1] = 'Load data of the layer deferred using ajax.';
|
||||
|
||||
@@ -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