diff --git a/module/assets/css/backend.css b/module/assets/css/backend.css index 187249c..1ebc060 100644 --- a/module/assets/css/backend.css +++ b/module/assets/css/backend.css @@ -3,6 +3,10 @@ background: url('./../img/fol-placeholder.gif') no-repeat 6px 1px; } +.tl_listing_container.tree_view ul > li.tl_file > div { + line-height: 18px; +} + .tl_listing_container.tree_view > ul > li.tl_file { padding-left: 26px; } diff --git a/module/assets/img/group.png b/module/assets/img/group.png new file mode 100644 index 0000000..25c6ca2 Binary files /dev/null and b/module/assets/img/group.png differ diff --git a/module/assets/img/map.png b/module/assets/img/map.png new file mode 100644 index 0000000..b440e72 Binary files /dev/null and b/module/assets/img/map.png differ diff --git a/module/assets/img/geotag.png b/module/assets/img/markers.png similarity index 100% rename from module/assets/img/geotag.png rename to module/assets/img/markers.png diff --git a/module/dca/tl_leaflet_control.php b/module/dca/tl_leaflet_control.php index 8344af9..7dccc40 100644 --- a/module/dca/tl_leaflet_control.php +++ b/module/dca/tl_leaflet_control.php @@ -89,7 +89,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'default' => array( 'name' => array('title', 'alias', 'type', 'position'), 'config' => array(), - 'active' => array('active') + 'active' => array('active'), ), 'zoom extends default' => array( 'config' => array('zoomInText', 'zoomOutText', 'zoomInTitle', 'zoomOutTitle'), @@ -160,7 +160,8 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'exclude' => true, 'inputType' => 'select', 'options' => array('topleft', 'topright', 'bottomleft', 'bottomright'), - 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), + 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_control'], + 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50', 'helpwizard' => true), 'sql' => "varchar(255) NOT NULL default ''" ), 'active' => array @@ -189,7 +190,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array ), 'zoomInTitle' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInText'], + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInTitle'], 'exclude' => true, 'inputType' => 'text', 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), @@ -197,7 +198,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array ), 'zoomOutTitle' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInText'], + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomOutTitle'], 'exclude' => true, 'inputType' => 'text', 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), @@ -245,12 +246,14 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array ), 'mode' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['layer'], + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['layerMode'], 'exclude' => true, 'inputType' => 'select', 'options' => array('base', 'overlay'), + 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_control'], 'eval' => array( - 'style' => 'width: 200px' + 'style' => 'width: 200px', + 'helpwizard' => true, ), ), ) diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index 8a2d861..82c8b2f 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -26,7 +26,8 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'label' => array ( 'fields' => array('title'), - 'format' => '%s' + 'format' => '%s', + 'label_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateRow') ), 'global_operations' => array ( @@ -47,6 +48,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array ), 'operations' => array ( + 'markers' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['markers'], + 'href' => 'table=tl_leaflet_marker', + 'icon' => 'edit.gif', + 'button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateMarkersButton'), + ), 'edit' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['edit'], @@ -73,6 +81,16 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'icon' => 'delete.gif', 'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"' ), + 'toggle' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['toggle'], + 'icon' => 'visible.gif', + 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', + 'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback( + 'tl_leaflet_layer', + 'active' + ) + ), 'show' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['show'], @@ -82,9 +100,17 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array ) ), + 'palettes' => array( + '__selector__' => array('type'), + ), + 'metapalettes' => array( 'default' => array( - 'title' => array('title', 'alias', 'type'), + 'title' => array('title', 'alias', 'type'), + 'active' => array('active'), + ), + 'markers extends default' => array( + '+title' => array('markerCluster'), ), ), @@ -97,26 +123,25 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'HERE' => array('tile_provider_key', 'tile_provider_code'), ), ), - 'fields' => array ( - 'id' => array + 'id' => array ( - 'sql' => "int(10) unsigned NOT NULL auto_increment" + 'sql' => "int(10) unsigned NOT NULL auto_increment" ), - 'pid' => array + 'pid' => array ( - 'sql' => "int(10) unsigned NOT NULL default '0'" + 'sql' => "int(10) unsigned NOT NULL default '0'" ), - 'sorting' => array + 'sorting' => array ( - 'sql' => "int(10) unsigned NOT NULL default '0'" + 'sql' => "int(10) unsigned NOT NULL default '0'" ), - 'tstamp' => array + 'tstamp' => array ( - 'sql' => "int(10) unsigned NOT NULL default '0'" + 'sql' => "int(10) unsigned NOT NULL default '0'" ), - 'title' => array + 'title' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['title'], 'exclude' => true, @@ -124,7 +149,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), - 'alias' => array + 'alias' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['alias'], 'exclude' => true, @@ -132,7 +157,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), - 'type' => array + 'type' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['type'], 'exclude' => true, @@ -145,9 +170,18 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'chosen' => true, ), 'options' => array_keys($GLOBALS['LEAFLET_LAYERS']), + 'reference' => &$GLOBALS['TL_LANG']['leaflet_layer'], 'sql' => "varchar(32) NOT NULL default ''" ), - 'tile_provider' => array( + 'active' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['active'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'tile_provider' => array( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider'], 'exclude' => true, 'inputType' => 'select', @@ -162,19 +196,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'sql' => "varchar(32) NOT NULL default ''" ), 'tile_provider_variant' => array( - 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_variant'], - 'exclude' => true, - 'inputType' => 'select', - 'eval' => array( - 'mandatory' => false, - 'tl_class' => 'w50', - 'submitOnChange' => true, - 'chosen' => false, + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_variant'], + 'exclude' => true, + 'inputType' => 'select', + 'eval' => array( + 'mandatory' => false, + 'tl_class' => 'w50', + 'submitOnChange' => true, + 'chosen' => false, ), 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getVariants'), - 'sql' => "varchar(32) NOT NULL default ''" + 'sql' => "varchar(32) NOT NULL default ''" ), - 'tile_provider_key' => array + 'tile_provider_key' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_key'], 'exclude' => true, @@ -182,7 +216,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'clr w50'), 'sql' => "varchar(255) NOT NULL default ''" ), - 'tile_provider_code' => array + 'tile_provider_code' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_code'], 'exclude' => true, @@ -190,5 +224,21 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), + 'markerCluster' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'], + 'exclude' => true, + 'inputType' => 'select', + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getMarkerClusterLayers'), + 'reference' => &$GLOBALS['TL_LANG']['leaflet_layer'], + 'eval' => array( + 'mandatory' => false, + 'maxlength' => 255, + 'tl_class' => 'w50', + 'chosen' => true, + 'includeBlankOption' => true + ), + 'sql' => "varchar(255) NOT NULL default ''" + ), ) ); diff --git a/module/dca/tl_leaflet_marker.php b/module/dca/tl_leaflet_marker.php new file mode 100644 index 0000000..308ad3a --- /dev/null +++ b/module/dca/tl_leaflet_marker.php @@ -0,0 +1,361 @@ + array( + 'dataContainer' => 'Table', + 'enableVersioning' => true, + 'ptable' => 'tl_leaflet_layer', + 'sql' => array + ( + 'keys' => array + ( + 'id' => 'primary' + ) + ) + ), + + 'list' => array + ( + 'sorting' => array + ( + 'mode' => 4, + '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 + ( + '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_marker']['edit'], + 'href' => 'act=edit', + 'icon' => 'edit.gif' + ), + 'copy' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['copy'], + 'href' => 'act=copy', + 'icon' => 'copy.gif' + ), + 'delete' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['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_marker']['toggle'], + 'icon' => 'visible.gif', + 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', + 'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback( + 'tl_leaflet_marker', + 'active' + ) + ), + 'show' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['show'], + 'href' => 'act=show', + 'icon' => 'show.gif' + ) + ) + ), + + 'metapalettes' => array( + 'default' => array( + 'title' => array('title', 'alias', 'coordinates'), + 'content' => array('tooltip', 'alt', 'addPopup'), + 'icon' => array(':hide', 'customIcon'), + 'config' => array( + ':hide', + 'clickable', + 'draggable', + 'keyboard', + 'zIndexOffset', + 'opacity', + 'riseOnHover', + 'riseOffset' + ), + 'active' => array('active') + ), + ), + 'metasubpalettes' => array( + 'addPopup' => array('popupContent'), + 'customIcon' => array( + 'icon', + 'retinaIcon', + 'iconAnchor', + 'popupAnchor', + 'iconClassName', + 'shadowImage', + 'shadowRetinaImage', + 'shadowAnchor', + ) + ), + + '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_marker']['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_marker']['alias'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'coordinates' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['coordinates'], + 'exclude' => true, + 'inputType' => 'text', + 'save_callback' => array( + array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate') + ), + 'wizard' => array( + array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getGeocoder') + ), + 'eval' => array( + 'maxlength' => 255, + 'tl_class' => 'long clr', + 'nullIfEmpty' => true, + ), + 'sql' => "varchar(255) NULL" + ), + 'active' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['active'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'tooltip' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['tooltip'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'alt' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'addPopup' => 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 ''" + ), + 'popupContent' => 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" + ), + 'customIcon' => 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 ''" + ), + 'icon' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_content']['icon'], + '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", + ), + 'retinaIcon' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_content']['retinaIcon'], + '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", + ), + 'draggable' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['draggable'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'clickable' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'keyboard' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['keyboard'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'zIndexOffset' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zIndexOffset'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => 0, + 'eval' => array('mandatory' => true, 'maxlength' => 4, 'rgxp' => 'digit', 'tl_class' => 'clr w50'), + 'sql' => "int(4) NOT NULL default '0'" + ), + 'iconAnchor' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['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_marker']['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_marker']['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" + ), + 'iconClassName' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['iconClassName'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + ), +); diff --git a/module/dca/tl_leaflet_vector.php b/module/dca/tl_leaflet_vector.php new file mode 100644 index 0000000..e69de29 diff --git a/module/languages/en/leaflet_layer.php b/module/languages/en/leaflet_layer.php new file mode 100644 index 0000000..75ea2cb --- /dev/null +++ b/module/languages/en/leaflet_layer.php @@ -0,0 +1,6 @@ + + Order allow,deny + Allow from all + + + Require all granted + \ No newline at end of file diff --git a/module/public/geojson.php b/module/public/geojson.php new file mode 100644 index 0000000..e9cff61 --- /dev/null +++ b/module/public/geojson.php @@ -0,0 +1,11 @@ +execute(); diff --git a/src/Netzmacht/Contao/Leaflet/Controller/GeoJsonController.php b/src/Netzmacht/Contao/Leaflet/Controller/GeoJsonController.php new file mode 100644 index 0000000..7b678bd --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Controller/GeoJsonController.php @@ -0,0 +1,41 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Controller; + + +use Netzmacht\Contao\Leaflet\MapService; + +class GeoJsonController +{ + /** + * @var MapService + */ + private $mapService; + + /** + * @var \Input + */ + private $input; + + public function __construct(MapService $mapService, \Input $input) + { + $this->mapService = $mapService; + $this->input = $input; + } + + public function execute() + { + $collection = $this->mapService->getFeatureCollection(\Input::get('id')); + + return json_encode($collection); + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Layer.php b/src/Netzmacht/Contao/Leaflet/Dca/Layer.php index 44037c2..bda9818 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Layer.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/Layer.php @@ -12,6 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Dca; +use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder; +use Netzmacht\Contao\Leaflet\Model\LayerModel; + class Layer { private $layers; @@ -19,7 +22,10 @@ class Layer public function __construct() { $this->layers = &$GLOBALS['LEAFLET_LAYERS']; + + \Controller::loadLanguageFile('leaflet_layer'); } + public function getVariants($dataContainer) { if ($dataContainer->activeRecord @@ -32,6 +38,48 @@ class Layer return array(); } + public function generateRow($row, $label) + { + $alt = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0]) + ? $row['type'] + : $GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0]; + + $title = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][1]) + ? $row['type'] + : $GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][1]; + + if (!empty($this->layers[$row['type']]['icon'])) { + $icon = \Image::getHtml($this->layers[$row['type']]['icon'], $alt, sprintf('title="%s"', $title)); + } else { + $icon = \Image::getHtml('iconPLAIN.gif', $alt, sprintf('title="%s"', $title)); + } + + return $icon . ' ' . $label; + } + + public function getMarkerClusterLayers() + { + $types = array_keys( + array_filter( + $GLOBALS['LEAFLET_LAYERS'], + function ($item) { + return !empty($item['markerCluster']); + } + ) + ); + + $collection = LayerModel::findMultipleByTypes($types); + $builder = OptionsBuilder::fromCollection( + $collection, + 'id', + function($row) { + return sprintf('%s [%s]', $row['title'], $row['type']); + } + ); + + return $builder->getOptions(); + } + // Call paste_button_callback (&$dc, $row, $table, $cr, $childs, $previous, $next) public function getPasteButtons($dataContainer, $row, $table, $whatever, $children) { @@ -76,4 +124,18 @@ class Layer return $buffer; } + + public function generateMarkersButton($row, $href, $label, $title, $icon, $attributes) + { + if (empty($this->layers[$row['type']]['markers'])) { + return ''; + } + + return sprintf( + '%s ', + \Backend::addToUrl($href . '&id=' . $row['id']), + $title, + \Image::getHtml($icon, $label, $attributes) + ); + } } diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Marker.php b/src/Netzmacht/Contao/Leaflet/Dca/Marker.php new file mode 100644 index 0000000..5505dbd --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Dca/Marker.php @@ -0,0 +1,22 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Dca; + + +class Marker +{ + public function generateRow($row) + { + return $row['title']; + } + +} diff --git a/src/Netzmacht/Contao/Leaflet/Event/BuildDefinitionEvent.php b/src/Netzmacht/Contao/Leaflet/Event/BuildDefinitionEvent.php index 7a91d5d..1ce2149 100644 --- a/src/Netzmacht/Contao/Leaflet/Event/BuildDefinitionEvent.php +++ b/src/Netzmacht/Contao/Leaflet/Event/BuildDefinitionEvent.php @@ -12,6 +12,7 @@ namespace Netzmacht\Contao\Leaflet\Event; use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Symfony\Component\EventDispatcher\Event; /** @@ -37,16 +38,25 @@ class BuildDefinitionEvent extends Event */ private $model; + /** + * Optional bounds where elements should be in. + * + * @var LatLngBounds + */ + private $bounds; + /** * Construct. * - * @param Definition $definition The leaflet definition. - * @param \Model $model The definition model. + * @param Definition $definition The leaflet definition. + * @param \Model $model The definition model. + * @param LatLngBounds $bounds Optional bounds where elements should be in. */ - public function __construct(Definition $definition, \Model $model) + public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null) { $this->definition = $definition; - $this->model = $model; + $this->model = $model; + $this->bounds = $bounds; } /** @@ -68,4 +78,14 @@ class BuildDefinitionEvent extends Event { return $this->model; } + + /** + * Get the bounds. + * + * @return LatLngBounds|null + */ + public function getBounds() + { + return $this->bounds; + } } diff --git a/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php b/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php index 212285a..7236698 100644 --- a/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php +++ b/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php @@ -52,7 +52,7 @@ class LeafletMapElement extends \ContentElement { try { $mapId = 'map_' . ($this->cssID[0] ?: $this->id); - $map = $this->mapService->getJavascript($this->leaflet_map, $mapId); + $map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId); $GLOBALS['TL_BODY'][] = ''; diff --git a/src/Netzmacht/Contao/Leaflet/MapService.php b/src/Netzmacht/Contao/Leaflet/MapService.php index 7d6b452..f6b433a 100644 --- a/src/Netzmacht/Contao/Leaflet/MapService.php +++ b/src/Netzmacht/Contao/Leaflet/MapService.php @@ -13,9 +13,13 @@ namespace Netzmacht\Contao\Leaflet; use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\LeafletPHP\Assets; +use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection; +use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollectionAggregate; use Netzmacht\LeafletPHP\Definition\Map; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Leaflet; use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcher; @@ -61,16 +65,17 @@ class MapService /** * Get map definition. * - * @param int $mapId The map database id. - * @param string $elementId Optional element id. If none given the mapId or alias is used. + * @param int $mapId The map database id. + * @param LatLngBounds $bounds Optional bounds where elements should be in. + * @param string $elementId Optional element id. If none given the mapId or alias is used. * * @return Map */ - public function getDefinition($mapId, $elementId = null) + public function getDefinition($mapId, LatLngBounds $bounds = null, $elementId = null) { $model = $this->getModel($mapId); - return $this->mapper->handle($model, $elementId); + return $this->mapper->handle($model, $bounds, $elementId); } /** @@ -96,16 +101,15 @@ class MapService /** * Get map javascript. * - * @param int $mapId The map id. - * @param string $elementId Optional element id. If none given the mapId or alias is used. + * @param int $mapId The map id. + * @param LatLngBounds $bounds Optional bounds where elements should be in. + * @param string $elementId Optional element id. If none given the mapId or alias is used. * * @return string - * - * @throws \Exception If an error occurred in the process. */ - public function getJavascript($mapId, $elementId = null) + public function getJavascript($mapId, LatLngBounds $bounds = null, $elementId = null) { - $definition = $this->getDefinition($mapId, $elementId); + $definition = $this->getDefinition($mapId, $bounds, $elementId); $assets = new ContaoAssets(); $javascript = $this->leaflet->build($definition, $assets); @@ -114,4 +118,23 @@ class MapService return $event->getJavascript(); } + + /** + * Get feature collection of a layer. + * + * @param int $layerId The layer id. + * @param LatLngBounds $bounds Filter features in the bounds. + * + * @return FeatureCollection + */ + public function getFeatureCollection($layerId, LatLngBounds $bounds = null) + { + $model = LayerModel::findByPK($layerId); + + if (!$model || !$model->active) { + throw new \InvalidArgumentException(sprintf('Could not find layer "%s"', $layerId)); + } + + return $this->mapper->handleGeoJson($model, $bounds); + } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php index ca4f484..00483c8 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php @@ -12,6 +12,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper; use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; /** * Class AbstractBuilder. @@ -148,13 +149,13 @@ abstract class AbstractMapper implements Mapper /** * {@inheritdoc} */ - public function handle(\Model $model, DefinitionMapper $builder) + public function handle(\Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) { - $definition = $this->createInstance($model, $builder); + $definition = $this->createInstance($model, $builder, $bounds); $this->buildOptions($definition, $model); $this->buildConditionals($definition, $model); - $this->doBuild($definition, $model, $builder); + $this->doBuild($definition, $model, $builder, $bounds); return $definition; } @@ -182,14 +183,19 @@ abstract class AbstractMapper implements Mapper /** * Use for specific build methods. * - * @param Definition $definition The definition being built. - * @param \Model $model The model. - * @param DefinitionMapper $builder The definition builder. + * @param Definition $definition The definition being built. + * @param \Model $model The model. + * @param DefinitionMapper $builder The definition builder. + * @param LatLngBounds $bounds Optional bounds where elements should be in. * * @return void */ - protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder) - { + protected function doBuild( + Definition $definition, + \Model $model, + DefinitionMapper $builder, + LatLngBounds $bounds = null + ) { } /** @@ -197,13 +203,14 @@ abstract class AbstractMapper implements Mapper * * @param \Model $model The model. * @param DefinitionMapper $mapper The definition mapper. + * @param LatLngBounds $bounds Optional bounds where elements should be in. * * @return Definition */ - protected function createInstance(\Model $model, DefinitionMapper $mapper) + protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { $reflector = new \ReflectionClass(static::$definitionClass); - $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper)); + $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds)); return $instance; } @@ -213,10 +220,11 @@ abstract class AbstractMapper implements Mapper * * @param \Model $model The model. * @param DefinitionMapper $mapper The definition mapper. + * @param LatLngBounds $bounds Optional bounds where elements should be in. * * @return array */ - protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper) + protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { return array( $model->alias ?: (str_replace('tl_leaflet_', '', $model->getTable()) . '_' . $model->id) diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php index 7924a7f..e488a2f 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Control/AttributionControlMapper.php @@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Control\Attribution; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; /** * AttributionControlMapper maps the the attribution database definition to the definition class. @@ -49,7 +50,7 @@ class AttributionControlMapper extends AbstractControlMapper /** * {@inheritdoc} */ - protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder) + protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) { if (!$definition instanceof Attribution) { return; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Control/LayersControlMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Control/LayersControlMapper.php index 521f417..eee6e1f 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Control/LayersControlMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Control/LayersControlMapper.php @@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; class LayersControlMapper extends AbstractControlMapper { @@ -31,9 +32,9 @@ class LayersControlMapper extends AbstractControlMapper */ protected static $type = 'layers'; - protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper) + protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { - $arguments = parent::buildConstructArguments($model, $mapper); + $arguments = parent::buildConstructArguments($model, $mapper, $bounds); $arguments[1] = array(); $arguments[2] = array(); @@ -44,7 +45,7 @@ class LayersControlMapper extends AbstractControlMapper foreach ($collection as $layer) { $argument = ($definition[$layer->id] === 'overlay') ? 2 : 1; - $arguments[$argument][] = $mapper->handle($layer); + $arguments[$argument][] = $mapper->handle($layer, $bounds); } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php index 1ffcdbb..bacc801 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/DefinitionMapper.php @@ -13,6 +13,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper; use Netzmacht\Contao\Leaflet\Event\BuildDefinitionEvent; use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\GeoJson\Feature; +use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcher; /** @@ -70,6 +73,8 @@ class DefinitionMapper { $this->builders[$priority][] = $builder; + ksort($this->builders); + return $this; } @@ -86,12 +91,13 @@ class DefinitionMapper /** * Build a model. * - * @param \Model $model The definition model. - * @param string $elementId Optional element id. If none given the mapId or alias is used. + * @param \Model $model The definition model. + * @param LatLngBounds $bounds Optional bounds where elements should be in. + * @param string $elementId Optional element id. If none given the mapId or alias is used. * * @return Definition */ - public function handle(\Model $model, $elementId = null) + public function handle(\Model $model, LatLngBounds $bounds = null, $elementId = null) { $hash = $model->getTable() . '.' . $model->{$model->getPk()}; @@ -99,16 +105,14 @@ class DefinitionMapper return $this->mapped[$hash]; } - krsort($this->builders); - $this->mapId = $elementId ?: ($model->alias ?: ('map_' . $model->id)); foreach ($this->builders as $builders) { foreach($builders as $builder) { if ($builder->match($model)) { - $definition = $builder->handle($model, $this); + $definition = $builder->handle($model, $this, $bounds); - $event = new BuildDefinitionEvent($definition, $model); + $event = new BuildDefinitionEvent($definition, $model, $bounds); $this->eventDispatcher->dispatch($event::NAME, $event); $this->mapped[$hash] = $definition; @@ -126,4 +130,43 @@ class DefinitionMapper ) ); } + + /** + * Build a model. + * + * @param \Model $model The definition model. + * @param LatLngBounds $bounds Optional bounds where elements should be in. + * + * @return FeatureCollection|Feature + */ + public function handleGeoJson(\Model $model, LatLngBounds $bounds = null) + { + foreach ($this->builders as $builders) { + foreach ($builders as $builder) { + if (!$builder->match($model)) { + continue; + } + + if ($builder instanceof GeoJsonMapper) { + return $builder->handleGeoJson($model, $this, $bounds); + } + + throw new \RuntimeException( + sprintf( + 'Builder for model "%s::%s" is not a GeoJsonMapper', + $model->getTable(), + $model->{$model->getPk()} + ) + ); + } + } + + throw new \RuntimeException( + sprintf( + 'Could not build geo json of model "%s::%s". No matching builders found.', + $model->getTable(), + $model->{$model->getPk()} + ) + ); + } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/GeoJsonMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/GeoJsonMapper.php new file mode 100644 index 0000000..4e1171f --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/GeoJsonMapper.php @@ -0,0 +1,26 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Mapper; + +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; + +interface GeoJsonMapper +{ + /** + * @param \Model $model + * @param DefinitionMapper $mapper + * @param LatLngBounds $bounds + * + * @return mixed + */ + public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null); +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/AbstractLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/AbstractLayerMapper.php new file mode 100644 index 0000000..b85fe26 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/AbstractLayerMapper.php @@ -0,0 +1,24 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Mapper\Layer; + +use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; + +class AbstractLayerMapper extends AbstractTypeMapper +{ + /** + * Class of the model being build. + * + * @var string + */ + protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel'; +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php new file mode 100644 index 0000000..9264b80 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php @@ -0,0 +1,90 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +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\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection; +use Netzmacht\LeafletPHP\Definition\Group\LayerGroup; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; +use Netzmacht\LeafletPHP\Definition\UI\Marker; + +class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper +{ + /** + * Class of the definition being created. + * + * @var string + */ + protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Group\GeoJson'; + + /** + * Layer type. + * + * @var string + */ + protected static $type = 'markers'; + + protected function doBuild( + Definition $definition, + \Model $model, + DefinitionMapper $builder, + LatLngBounds $bounds = null + ) { + if ($definition instanceof LayerGroup) { + $collection = MarkerModel::findBy( + array('active=1', 'pid=?'), + array($model->id) + ); + + if ($collection) { + foreach ($collection as $item) { + $marker = new Marker('marker_' . $item->id, $item->coordinates); + $marker->setTitle($item->tooltip); + + $definition->addLayer($marker); + } + } + } + } + + /** + * @param \Model $model + * @param DefinitionMapper $mapper + * @param LatLngBounds $bounds + * + * @return mixed + */ + public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) + { + $feature = new FeatureCollection(); + + $collection = MarkerModel::findBy( + array('active=1', 'pid=?'), + array($model->id) + ); + + if ($collection) { + foreach ($collection as $item) { + $marker = new Marker('marker_' . $item->id, $item->coordinates); + $marker->setTitle($item->tooltip); + + $feature->addFeature($marker->getFeature()); + } + } + + return $feature; + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php index f605f39..6859880 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php @@ -11,20 +11,12 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; - -use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; -class ProviderLayerMapper extends AbstractTypeMapper +class ProviderLayerMapper extends AbstractLayerMapper { - /** - * Class of the model being build. - * - * @var string - */ - protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel'; - /** * Class of the definition being created. * @@ -61,7 +53,7 @@ class ProviderLayerMapper extends AbstractTypeMapper /** * {@inheritdoc} */ - protected function createInstance(\Model $model, DefinitionMapper $mapper) + protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { if (isset($this->providers[$model->tile_provider]['class'])) { $class = $this->providers[$model->tile_provider]['class']; @@ -70,7 +62,7 @@ class ProviderLayerMapper extends AbstractTypeMapper } $reflector = new \ReflectionClass($class); - $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper)); + $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds)); return $instance; } @@ -78,7 +70,7 @@ class ProviderLayerMapper extends AbstractTypeMapper /** * {@inheritdoc} */ - protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder) + protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) { if (!empty($this->providers[$model->tile_provider]['options'])) { $this->applyOptions( @@ -92,7 +84,7 @@ class ProviderLayerMapper extends AbstractTypeMapper /** * {@inheritdoc} */ - protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper) + protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { return array( $model->alias ?: ('layer_' . $model->id), diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php index 67e10d8..9aaa57b 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php @@ -16,6 +16,7 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Map; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Plugins\LeafletProviders\Provider; class MapMapper extends AbstractMapper @@ -50,19 +51,19 @@ class MapMapper extends AbstractMapper /** * @inheritdoc */ - protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder) + protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) { if ($map instanceof Map && $model instanceof MapModel) { $this->buildCustomOptions($map, $model); - $this->buildControls($map, $model, $builder); - $this->buildLayers($map, $model, $builder); + $this->buildControls($map, $model, $builder, $bounds); + $this->buildLayers($map, $model, $builder, $bounds); } } /** * @inheritdoc */ - protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper) + protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { return array( $mapper->getMapId(), @@ -91,8 +92,9 @@ class MapMapper extends AbstractMapper * @param Map $map The map being built. * @param MapModel $model The map model. * @param DefinitionMapper $mapper The definition mapper. + * @param LatLngBounds $bounds Optional bounds. */ - private function buildControls(Map $map, MapModel$model, DefinitionMapper $mapper) + private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { $collection = ControlModel::findBy( array('pid=?', 'active=1'), @@ -102,7 +104,7 @@ class MapMapper extends AbstractMapper if ($collection) { foreach ($collection as $control) { - $control = $mapper->handle($control); + $control = $mapper->handle($control, $bounds); $map->addControl($control); } } @@ -114,16 +116,22 @@ class MapMapper extends AbstractMapper * @param Map $map The map being built. * @param MapModel $model The map model. * @param DefinitionMapper $mapper Definition mapper. + * @param LatLngBounds $bounds Optional bounds. */ - private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper) + private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { $ids = deserialize($model->layers, true); $collection = LayerModel::findMultipleByIds($ids); if ($collection) { foreach ($collection as $layer) { + if (!$layer->active) { + continue; + } + + $layer = $mapper->handle($layer, $bounds); + /** @var Provider $layer */ - $layer = $mapper->handle($layer); $map->addLayer($layer); } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php index bc35548..c26ecfd 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php @@ -12,21 +12,23 @@ namespace Netzmacht\Contao\Leaflet\Mapper; use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; interface Mapper { /** * Map model to the definition. * - * @param \Model $model The model being built. - * @param DefinitionMapper $builder The definition builder. + * @param \Model $model The model being built. + * @param DefinitionMapper $mapper The definition builder. + * @param LatLngBounds $bounds Optional bounds where elements should be in. * * @return Definition */ - public function handle(\Model $model, DefinitionMapper $builder); + public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null); /** - * Check if builder is responsible for the model. + * Check if mapper is responsible for the model. * * @param \Model $model The model being build. * diff --git a/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php b/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php index 3cd46e3..db2a6d4 100644 --- a/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php +++ b/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php @@ -16,4 +16,21 @@ class LayerModel extends \Model { protected static $strTable = 'tl_leaflet_layer'; + public static function findMultipleByTypes(array $types, $options = array()) + { + if (empty($types)) { + return null; + } + + $options['column'] = array( + sprintf( + 'type IN (%s)', + substr(str_repeat('?,', count($types)), 0, -1) + ) + ); + + $options['value'] = $types; + + return static::find($options); + } } diff --git a/src/Netzmacht/Contao/Leaflet/Model/MarkerModel.php b/src/Netzmacht/Contao/Leaflet/Model/MarkerModel.php new file mode 100644 index 0000000..c0553b0 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Model/MarkerModel.php @@ -0,0 +1,19 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Model; + + +class MarkerModel extends \Model +{ + protected static $strTable = 'tl_leaflet_marker'; + +}