diff --git a/module/dca/tl_leaflet_control.php b/module/dca/tl_leaflet_control.php index 678005c..e4f7e03 100644 --- a/module/dca/tl_leaflet_control.php +++ b/module/dca/tl_leaflet_control.php @@ -282,7 +282,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['layer'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Control', 'getLayers'), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getLayers'), 'eval' => array( 'style' => 'width: 300px', 'chosen' => true, diff --git a/module/dca/tl_leaflet_map.php b/module/dca/tl_leaflet_map.php index c44e478..372c686 100644 --- a/module/dca/tl_leaflet_map.php +++ b/module/dca/tl_leaflet_map.php @@ -95,7 +95,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'default' => array( 'title' => array('title', 'alias'), 'zoom' => array('center', 'zoom', 'adjustZoomExtra', 'adjustBounds'), - 'controls' => array('zoomControl', 'controls'), + 'locate' => array('locate'), 'layers' => array('layers'), 'interaction' => array( 'dragging', @@ -107,6 +107,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'keyboard' ), 'behaviour' => array( + 'zoomControl', 'trackResize', 'closeOnClick', 'bounceAtZoomLimits' @@ -116,12 +117,25 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array ) ), ), - 'metasubpalettes' => array( - 'keyboard' => array('keyboardPanOffset', 'keyboardZoomOffset'), - 'adjustZoomExtra' => array('minZoom', 'maxZoom'), + 'keyboard' => array( + 'keyboardPanOffset', + 'keyboardZoomOffset' + ), + 'adjustZoomExtra' => array( + 'minZoom', + 'maxZoom' + ), + 'locate' => array( + 'locateWatch', + 'locateSetView', + 'locateMaxZoom', + 'locateTimeout', + 'locateMaximumAge', + 'enableHighAccuracy' + ), ), - + 'fields' => array ( 'id' => array @@ -175,8 +189,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'], 'exclude' => true, - 'inputType' => 'checkboxWizard', - 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getLayers'), + 'inputType' => 'multiColumnWizard', 'load_callback' => array( array('Netzmacht\Contao\Leaflet\Dca\Map', 'loadLayerRelations'), ), @@ -186,6 +199,24 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'eval' => array( 'multiple' => true, 'doNotSaveEmpty' => true, + 'columnFields' => array( + 'reference' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['reference'], + 'exclude' => true, + 'inputType' => 'select', + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getLayers'), + 'eval' => array( + 'mandatory' => true, + 'tl_class' => 'w50', + 'chosen' => true, + 'includeBlankOption' => true, + 'style' => 'width: 300px' + ), + 'sql' => "int(10) unsigned NOT NULL default '0'", + ), + ), + 'flatArray' => true ), 'sql' => "mediumblob NULL" ), @@ -385,8 +416,76 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'default' => false, 'options' => array('load', 'deferred'), 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBoundsOptions'], - 'eval' => array('tl_class' => 'w50', 'multiple' => true, 'helpwizard' => true), + 'eval' => array('tl_class' => 'clr w50', 'multiple' => true, 'helpwizard' => true), 'sql' => "varchar(255) NOT NULL default ''" ), + 'locate' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locate'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => false, + 'eval' => array('tl_class' => 'w50', 'submitOnChange' => true), + 'sql' => "char(1) NOT NULL default ''" + ), + 'locateWatch' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateWatch'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => false, + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'locateSetView' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateSetView'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50', 'submitOnChange' => false), + 'sql' => "char(1) NOT NULL default ''" + ), + 'locateTimeout' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateTimeout'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('maxlength' => 5, 'rgxp' => 'digit', 'tl_class' => 'w50', 'nullIfEmpty' => true), + 'sql' => "int(9) NULL" + ), + 'locateMaximumAge' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaximumAge'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('maxlength' => 5, 'rgxp' => 'digit', 'tl_class' => 'w50', 'nullIfEmpty' => true), + 'sql' => "int(9) NULL" + ), + 'enableHighAccuracy' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['enableHighAccuracy'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => false, + 'eval' => array('tl_class' => 'w50 m12'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'locateMaxZoom' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaxZoom'], + 'exclude' => true, + 'inputType' => 'select', + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getZoomLevels'), + 'eval' => array( + 'maxlength' => 4, + 'rgxp' => 'digit', + 'tl_class' => 'clr w50', + 'includeBlankOption' => true, + 'nullIfEmpty' => true + ), + 'sql' => "int(4) NULL" + ), ), ); diff --git a/module/languages/en/tl_leaflet_map.php b/module/languages/en/tl_leaflet_map.php index 819480f..e77d844 100644 --- a/module/languages/en/tl_leaflet_map.php +++ b/module/languages/en/tl_leaflet_map.php @@ -3,7 +3,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_map']['title_legend'] = 'Title'; $GLOBALS['TL_LANG']['tl_leaflet_map']['interaction_legend'] = 'Interaction controls'; $GLOBALS['TL_LANG']['tl_leaflet_map']['zoom_legend'] = 'Center and zoom'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['controls_legend'] = 'Control widgets'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locate_legend'] = 'Locate user position'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['layers_legend'] = 'Default layers'; $GLOBALS['TL_LANG']['tl_leaflet_map']['expert_legend'] = 'Expert settings'; $GLOBALS['TL_LANG']['tl_leaflet_map']['behaviour_legend'] = 'Behaviour'; @@ -20,52 +21,66 @@ $GLOBALS['TL_LANG']['tl_leaflet_map']['delete'][1] = 'Delete map ID $GLOBALS['TL_LANG']['tl_leaflet_map']['show'][0] = 'Show details'; $GLOBALS['TL_LANG']['tl_leaflet_map']['show'][1] = 'Show map ID %s details'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['title'][0] = 'Title'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['title'][1] = 'Title of the map.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['alias'][0] = 'Alias'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['alias'][1] = 'Alias of the map.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['center'][0] = 'Center'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['center'][1] = 'Initial geographical center of the map. Comma separated coordinates.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['dragging'][0] = 'Dragging'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['dragging'][1] = 'Whether the map be draggable with mouse/touch or not.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['touchZoom'][0] = 'Touch zoom'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['touchZoom'][1] = 'Whether the map can be zoomed by touch-dragging with two fingers.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['scrollWheelZoom'][0] = 'Scroll wheel zoom'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['scrollWheelZoom'][1] = 'Whether the map can be zoomed by using the mouse wheel.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['doubleClickZoom'][0] = 'Double click zoom'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['doubleClickZoom'][1] = 'Whether the map can be zoomed in by double clicking on it and zoomed out by double clicking while holding shift.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['boxZoom'][0] = 'Box zoom'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['boxZoom'][1] = 'Whether the map can be zoomed to a rectangular area specified by dragging the mouse while pressing shift.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['tap'][0] = 'Instant taps'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['tap'][1] = 'Enables mobile hacks for supporting instant taps.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['trackResize'][0] = 'Track window resize'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['trackResize'][1] = 'Whether the map automatically handles browser window resize to update itself.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['closeOnClick'][0] = 'Close popup on click'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['closeOnClick'][1] = 'Disable if you don\'t want popups to close when user clicks the map'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboard'][0] = 'Keyboard navigation'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboard'][1] = 'Makes the map focusable and allows users to navigate the map with keyboard arrows and +/- keys'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardPanOffset'][0] = 'Keyboard pan offset'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardPanOffset'][1] = 'Amount of pixels to pan when pressing an arrow key.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardZoomOffset'][0] = 'Keyboard zoom offset'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardZoomOffset'][1] = 'Number of zoom levels to change when pressing + or - key.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'][0] = 'Zoom level'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'][1] = 'Initial map zoom.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'][0] = 'Minimum zoom level'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'][1] = 'Minimum zoom level of the map. Overrides any minZoom set on map layers.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'][0] = 'Maximum zoom level'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'][1] = 'Maximum zoom level of the map. This overrides any maxZoom set on map layers.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomControl'][0] = 'Add default zoom control'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomControl'][1] = 'Whether the zoom control is added to the map by default.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['bounceAtZoomLimits'][0] = 'Bounce at zoom limits'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['bounceAtZoomLimits'][1] = 'Disable if you don\'t want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['options'][0] = 'Extra options'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['options'][1] = 'Add extra map options as valid json. See http://leafletjs.com/reference.html#map-options'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustZoomExtra'][0] = 'Adjust extra zoom settings'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustZoomExtra'][1] = 'Enable if you want to adjust minimum and maximum zoom as well'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][0] = 'Default layers'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][1] = 'Inital visible layers of the map. For optional layers use the layers control.'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBounds'][0] = 'Adjust bounds'; -$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBounds'][1] = 'If enabled the map will fit to bounds to objects being marked to affect the bounds.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['title'][0] = 'Title'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['title'][1] = 'Title of the map.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['alias'][0] = 'Alias'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['alias'][1] = 'Alias of the map.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['center'][0] = 'Center'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['center'][1] = 'Initial geographical center of the map. Comma separated coordinates.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['dragging'][0] = 'Dragging'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['dragging'][1] = 'Whether the map be draggable with mouse/touch or not.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['touchZoom'][0] = 'Touch zoom'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['touchZoom'][1] = 'Whether the map can be zoomed by touch-dragging with two fingers.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['scrollWheelZoom'][0] = 'Scroll wheel zoom'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['scrollWheelZoom'][1] = 'Whether the map can be zoomed by using the mouse wheel.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['doubleClickZoom'][0] = 'Double click zoom'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['doubleClickZoom'][1] = 'Whether the map can be zoomed in by double clicking on it and zoomed out by double clicking while holding shift.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['boxZoom'][0] = 'Box zoom'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['boxZoom'][1] = 'Whether the map can be zoomed to a rectangular area specified by dragging the mouse while pressing shift.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['tap'][0] = 'Instant taps'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['tap'][1] = 'Enables mobile hacks for supporting instant taps.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['trackResize'][0] = 'Track window resize'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['trackResize'][1] = 'Whether the map automatically handles browser window resize to update itself.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['closeOnClick'][0] = 'Close popup on click'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['closeOnClick'][1] = 'Disable if you don\'t want popups to close when user clicks the map'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboard'][0] = 'Keyboard navigation'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboard'][1] = 'Makes the map focusable and allows users to navigate the map with keyboard arrows and +/- keys'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardPanOffset'][0] = 'Keyboard pan offset'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardPanOffset'][1] = 'Amount of pixels to pan when pressing an arrow key.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardZoomOffset'][0] = 'Keyboard zoom offset'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['keyboardZoomOffset'][1] = 'Number of zoom levels to change when pressing + or - key.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'][0] = 'Zoom level'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'][1] = 'Initial map zoom.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'][0] = 'Minimum zoom level'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'][1] = 'Minimum zoom level of the map. Overrides any minZoom set on map layers.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'][0] = 'Maximum zoom level'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'][1] = 'Maximum zoom level of the map. This overrides any maxZoom set on map layers.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomControl'][0] = 'Add default zoom control'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomControl'][1] = 'Whether the zoom control is added to the map by default.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['bounceAtZoomLimits'][0] = 'Bounce at zoom limits'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['bounceAtZoomLimits'][1] = 'Disable if you don\'t want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['options'][0] = 'Extra options'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['options'][1] = 'Add extra map options as valid json. See http://leafletjs.com/reference.html#map-options'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustZoomExtra'][0] = 'Adjust extra zoom settings'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustZoomExtra'][1] = 'Enable if you want to adjust minimum and maximum zoom as well'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][0] = 'Default layers'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][1] = 'Inital visible layers of the map. For optional layers use the layers control.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBounds'][0] = 'Adjust bounds'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBounds'][1] = 'If enabled the map will fit to bounds to objects being marked to affect the bounds.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locate'][0] = 'Locate user position'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locate'][1] = 'Initial map zoom.Tries to locate the user using the Geolocation API.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateWatch'][0] = 'Watch continuously'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateWatch'][1] = 'If true, starts continous watching of location changes '; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateSetView'][0] = 'Update map center'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateSetView'][1] = 'If enabled, automatically sets the map view to the user location. Otherwise only the locationfound event is triggered.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaxZoom'][0] = 'Locate max zoom'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaxZoom'][1] = 'Max zoom when setting updating map view.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateTimeout'][0] = 'Locate timeout'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateTimeout'][1] = 'Number of milliseconds to wait for a response from geolocation.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['enableHighAccuracy'][0] = 'High accuracy'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['enableHighAccuracy'][1] = 'Enables high accuracy, see description in the W3C spec.'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaximumAge'][0] = 'Locate maximum age'; +$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaximumAge'][1] = 'Maximum age of detected location in milliseconds. Use cached value if time has not passed.'; $GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBoundsOptions']['load'][0] = 'At map initialization'; $GLOBALS['TL_LANG']['tl_leaflet_map']['adjustBoundsOptions']['load'][1] = 'Calculate bounds when the map is initialized. All static and already loaded deferred featured are included.'; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php index a65e38d..cd2a94c 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php @@ -13,6 +13,8 @@ namespace Netzmacht\Contao\Leaflet\Mapper; use Netzmacht\Contao\Leaflet\Model\ControlModel; use Netzmacht\Contao\Leaflet\Model\MapModel; +use Netzmacht\JavascriptBuilder\Type\AnonymousFunction; +use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Control; use Netzmacht\LeafletPHP\Definition\Layer; @@ -68,6 +70,7 @@ class MapMapper extends AbstractMapper $this->buildControls($map, $model, $mapper, $bounds); $this->buildLayers($map, $model, $mapper, $bounds); $this->buildBoundsCalculation($map, $model); + $this->buildLocate($map, $model); } } @@ -176,4 +179,46 @@ class MapMapper extends AbstractMapper $map->calculateFeatureBounds(); } } + + + /** + * Build map bounds calculations. + * + * @param Map $map The map being built. + * @param MapModel $model The map model. + * + * @return void + */ + private function buildLocate(Map $map, MapModel $model) + { + if ($model->locate) { + $options = array(); + + $mapping = array( + 'setView' => 'locateSetView', + 'watch' => 'locateWatch', + 'enableHighAccuracy' => 'enableHighAccuracy', + ); + + foreach ($mapping as $option => $property) { + if ($model->$property) { + $options[$option] = (bool) $model->$property; + } + } + + $mapping = array( + 'maxZoom' => 'locateMaxZoom', + 'timeout' => 'locateTimeout', + 'maximumAge' => 'locateMaximumAge', + ); + + foreach ($mapping as $option => $property) { + if ($model->$property) { + $options[$option] = (int) $model->$property; + } + } + + $map->locate($options); + } + } } diff --git a/src/Netzmacht/Contao/Leaflet/Model/MapModel.php b/src/Netzmacht/Contao/Leaflet/Model/MapModel.php index 175c794..a3795f1 100644 --- a/src/Netzmacht/Contao/Leaflet/Model/MapModel.php +++ b/src/Netzmacht/Contao/Leaflet/Model/MapModel.php @@ -16,6 +16,7 @@ use Model\Collection; /** * Class MapModel for the tl_leaflet_map table. * + * @property mixed|null locate * @package Netzmacht\Contao\Leaflet\Model */ class MapModel extends \Model