From c9c2bd3cce4b037c1becb5d56a8417019679a96f Mon Sep 17 00:00:00 2001 From: David Molineus Date: Tue, 27 Jan 2015 17:14:58 +0100 Subject: [PATCH] Add popup support. --- module/assets/img/popup.png | Bin 0 -> 588 bytes module/config/config.php | 7 + module/dca/tl_leaflet_icon.php | 7 + module/dca/tl_leaflet_layer.php | 7 + module/dca/tl_leaflet_marker.php | 25 +- module/dca/tl_leaflet_popup.php | 290 ++++++++++++++++++ module/dca/tl_leaflet_style.php | 7 + module/dca/tl_leaflet_vector.php | 8 +- module/languages/en/tl_leaflet_icon.php | 2 + module/languages/en/tl_leaflet_layer.php | 2 + module/languages/en/tl_leaflet_marker.php | 2 + module/languages/en/tl_leaflet_popup.php | 58 ++++ module/languages/en/tl_leaflet_style.php | 2 + module/languages/en/tl_leaflet_vector.php | 2 + src/Netzmacht/Contao/Leaflet/Dca/Marker.php | 14 + .../Contao/Leaflet/Mapper/UI/MarkerMapper.php | 19 +- .../Contao/Leaflet/Mapper/UI/PopupMapper.php | 117 +++++++ .../Contao/Leaflet/Model/PopupModel.php | 29 ++ .../Leaflet/Subscriber/GeoJsonSubscriber.php | 4 + 19 files changed, 597 insertions(+), 5 deletions(-) create mode 100644 module/assets/img/popup.png create mode 100644 module/dca/tl_leaflet_popup.php create mode 100644 module/languages/en/tl_leaflet_popup.php create mode 100644 src/Netzmacht/Contao/Leaflet/Mapper/UI/PopupMapper.php create mode 100644 src/Netzmacht/Contao/Leaflet/Model/PopupModel.php diff --git a/module/assets/img/popup.png b/module/assets/img/popup.png new file mode 100644 index 0000000000000000000000000000000000000000..dce262593f097a0282c257e80f8fc7d9db299d4f GIT binary patch literal 588 zcmV-S0<-;zP)D2w0^MAw;Wy;9sC3A~uQy1XH9o66})Zu89_b_$NpRLgXx>f|ger zH1T$3e6zcEazO;mV?SnR-h1D?Un87zIF3-|=^LcZcC2;t8PyR!htWd^0U-pG6um%- zvy@ufnVYK4Upjv}H{gg|;o^hK05{wlsQ{(0`?YuG)y~H@_4(%63lq5Z{2fptkS3Hv z!dNI#){0j`5~%Dfi4>AjjAsunVyoRnXM68D6Ih(k0p^+$NZ2V*3@Jd0;a4dcj-j%> zVEvQjZQL5yNR0*c4KP#DjOsrZFttopO4Xq<38tK a0t^6#K(NyERI+*i0000 'system/modules/leaflet/assets/img/layers.png', 'stylesheet' => 'system/modules/leaflet/assets/css/backend.css', @@ -51,21 +52,25 @@ array_insert( ) ); + /* * Content elements. */ $GLOBALS['TL_CTE']['includes']['leaflet'] = 'Netzmacht\Contao\Leaflet\Frontend\MapElement'; + /* * Frontend modules */ $GLOBALS['FE_MOD']['includes']['leaflet'] = 'Netzmacht\Contao\Leaflet\Frontend\MapModule'; + /* * Hooks */ $GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('Netzmacht\Contao\Leaflet\Frontend\Hooks', 'replaceInsertTags'); + /* * Models. */ @@ -74,6 +79,7 @@ $GLOBALS['TL_MODELS']['tl_leaflet_icon'] = 'Netzmacht\Contao\Leaflet\Model\Ic $GLOBALS['TL_MODELS']['tl_leaflet_layer'] = 'Netzmacht\Contao\Leaflet\Model\LayerModel'; $GLOBALS['TL_MODELS']['tl_leaflet_map'] = 'Netzmacht\Contao\Leaflet\Model\MapModel'; $GLOBALS['TL_MODELS']['tl_leaflet_marker'] = 'Netzmacht\Contao\Leaflet\Model\MarkerModel'; +$GLOBALS['TL_MODELS']['tl_leaflet_popup'] = 'Netzmacht\Contao\Leaflet\Model\PopupModel'; $GLOBALS['TL_MODELS']['tl_leaflet_style'] = 'Netzmacht\Contao\Leaflet\Model\StyleModel'; $GLOBALS['TL_MODELS']['tl_leaflet_vector'] = 'Netzmacht\Contao\Leaflet\Model\VectorModel'; @@ -114,6 +120,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\Rectangl // Miscellaneous mappers. $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper'; +$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\PopupMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Type\ImageIconMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Type\DivIconMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Style\FixedStyleMapper'; diff --git a/module/dca/tl_leaflet_icon.php b/module/dca/tl_leaflet_icon.php index 347255f..b218be9 100644 --- a/module/dca/tl_leaflet_icon.php +++ b/module/dca/tl_leaflet_icon.php @@ -55,6 +55,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'icon' => 'system/modules/leaflet/assets/img/style.png', 'attributes' => 'onclick="Backend.getScrollOffset();"' ), + 'popups' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['popups'], + 'href' => 'table=tl_leaflet_popup', + 'icon' => 'system/modules/leaflet/assets/img/popup.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index 9c146e9..1cf3870 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -66,6 +66,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'icon' => 'system/modules/leaflet/assets/img/icons.png', 'attributes' => 'onclick="Backend.getScrollOffset();"' ), + 'popups' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['popups'], + 'href' => 'table=tl_leaflet_popup', + 'icon' => 'system/modules/leaflet/assets/img/popup.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], diff --git a/module/dca/tl_leaflet_marker.php b/module/dca/tl_leaflet_marker.php index 2df1e91..78b8012 100644 --- a/module/dca/tl_leaflet_marker.php +++ b/module/dca/tl_leaflet_marker.php @@ -56,6 +56,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'icon' => 'system/modules/leaflet/assets/img/icons.png', 'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"' ), + 'popups' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popups'], + 'href' => 'table=tl_leaflet_popup', + 'icon' => 'system/modules/leaflet/assets/img/popup.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], @@ -124,7 +131,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array ), ), 'metasubpalettes' => array( - 'addPopup' => array('popupContent'), + 'addPopup' => array('popup', 'popupContent'), 'customIcon' => array('icon') ), @@ -249,9 +256,23 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'exclude' => true, 'inputType' => 'checkbox', 'filter' => true, - 'eval' => array('tl_class' => 'w50', 'submitOnChange' => true), + 'eval' => array('tl_class' => 'w50 m12', 'submitOnChange' => true), 'sql' => "char(1) NOT NULL default ''" ), + 'popup' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popup'], + 'exclude' => true, + 'inputType' => 'select', + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'getPopups'), + 'eval' => array( + 'mandatory' => false, + 'tl_class' => 'w50', + 'chosen' => true, + 'includeBlankOption' => true, + ), + 'sql' => "int(10) unsigned NOT NULL default '0'", + ), 'popupContent' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'], diff --git a/module/dca/tl_leaflet_popup.php b/module/dca/tl_leaflet_popup.php new file mode 100644 index 0000000..2f55354 --- /dev/null +++ b/module/dca/tl_leaflet_popup.php @@ -0,0 +1,290 @@ + + * @copyright 2014 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +$GLOBALS['TL_DCA']['tl_leaflet_popup'] = array +( + 'config' => array( + 'dataContainer' => 'Table', + 'enableVersioning' => true, + 'sql' => array + ( + 'keys' => array + ( + 'id' => 'primary', + 'alias' => 'unique', + ) + ) + ), + + 'list' => array + ( + 'sorting' => array + ( + 'mode' => 1, + 'fields' => array('title'), + 'flag' => 1, + 'panelLayout' => 'limit', + 'headerFields' => array('title', 'type'), + ), + 'label' => array + ( + 'fields' => array('title', 'type'), + 'format' => '%s [%s]', + ), + 'global_operations' => array + ( + 'layers' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['layersBtn'], + 'href' => 'table=tl_leaflet_layer', + 'icon' => 'system/modules/leaflet/assets/img/layers.png', + 'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"' + ), + 'styles' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['styles'], + 'href' => 'table=tl_leaflet_style', + 'icon' => 'system/modules/leaflet/assets/img/style.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), + 'icons' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['icons'], + 'href' => 'table=tl_leaflet_icon', + 'icon' => 'system/modules/leaflet/assets/img/icons.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), + '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_popup']['edit'], + 'href' => 'act=edit', + 'icon' => 'edit.gif' + ), + 'copy' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['copy'], + 'href' => 'act=copy', + 'icon' => 'copy.gif' + ), + 'delete' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['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_popup']['toggle'], + 'icon' => 'visible.gif', + 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', + 'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback( + 'tl_leaflet_popup', + 'active' + ) + ), + 'show' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['show'], + 'href' => 'act=show', + 'icon' => 'show.gif' + ) + ) + ), + + 'palettes' => array( + '__selector__' => array('type') + ), + + 'metapalettes' => array( + 'default' => array( + 'title' => array('title', 'alias'), + 'size' => array('maxWidth', 'minWidth', 'maxHeight'), + 'config' => array( + ':hide', + 'closeButton', + 'keepInView', + 'closeOnClick', + 'zoomAnimation', + 'offset', + 'className', + 'autoPan' + ), + 'active' => array('active'), + ), + ), + + 'metasubpalettes' => array( + 'autoPan' => array('autoPanPadding') + ), + + 'fields' => array + ( + 'id' => array + ( + 'sql' => "int(10) unsigned NOT NULL auto_increment" + ), + 'tstamp' => array + ( + 'sql' => "int(10) unsigned NOT NULL default '0'" + ), + 'title' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['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_popup']['alias'], + 'exclude' => true, + 'inputType' => 'text', + 'save_callback' => array( + \Netzmacht\Contao\DevTools\Dca::createGenerateAliasCallback('tl_leaflet_popup', 'title'), + ), + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'maxWidth' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['maxWidth'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('mandatory' => false, 'maxlength' => 4, 'rgxp' => 'digit', 'tl_class' => 'w50'), + 'sql' => "int(4) NULL" + ), + 'minWidth' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['minWidth'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('mandatory' => false, 'maxlength' => 4, 'rgxp' => 'digit', 'tl_class' => 'w50'), + 'sql' => "int(4) NULL" + ), + 'maxHeight' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['maxHeight'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('mandatory' => false, 'maxlength' => 4, 'rgxp' => 'digit', 'tl_class' => 'w50'), + 'sql' => "int(4) NULL" + ), + 'autoPan' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['autoPan'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50 m12', 'submitOnChange' => true), + 'sql' => "char(1) NOT NULL default '1'" + ), + 'keepInView' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['keepInView'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => false, + 'eval' => array('tl_class' => 'w50', 'submitOnChange' => false), + 'sql' => "char(1) NOT NULL default ''" + ), + 'closeButton' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['closeButton'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50', 'submitOnChange' => false), + 'sql' => "char(1) NOT NULL default '1'" + ), + 'offset' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['offset'], + '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" + ), + 'autoPanPadding' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['autoPanPadding'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array( + 'maxlength' => 255, + 'tl_class' => 'w50', + 'nullIfEmpty' => true, + 'multiple' => true, + 'size' => 2, + ), + 'sql' => "varchar(255) NULL" + ), + 'zoomAnimation' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['zoomAnimation'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50', 'submitOnChange' => false), + 'sql' => "char(1) NOT NULL default '1'" + ), + 'closeOnClick' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['closeOnClick'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class' => 'w50', 'submitOnChange' => false), + 'sql' => "char(1) NOT NULL default '1'" + ), + 'className' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['className'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => false, 'maxlength' => 64, 'tl_class' => 'w50'), + 'sql' => "varchar(64) NOT NULL default ''" + ), + 'active' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_popup']['active'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'filter' => true, + 'sorting' => true, + 'search' => false, + 'flag' => 12, + 'eval' => array('tl_class' => 'w50'), + 'sql' => "char(1) NOT NULL default ''" + ), + ), +); diff --git a/module/dca/tl_leaflet_style.php b/module/dca/tl_leaflet_style.php index 39a7e96..2410dd1 100644 --- a/module/dca/tl_leaflet_style.php +++ b/module/dca/tl_leaflet_style.php @@ -54,6 +54,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'icon' => 'system/modules/leaflet/assets/img/icons.png', 'attributes' => 'onclick="Backend.getScrollOffset();"' ), + 'popups' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_style']['popups'], + 'href' => 'table=tl_leaflet_popup', + 'icon' => 'system/modules/leaflet/assets/img/popup.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], diff --git a/module/dca/tl_leaflet_vector.php b/module/dca/tl_leaflet_vector.php index 8f3bcfd..8cf4b44 100644 --- a/module/dca/tl_leaflet_vector.php +++ b/module/dca/tl_leaflet_vector.php @@ -56,7 +56,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'icon' => 'system/modules/leaflet/assets/img/style.png', 'attributes' => 'onclick="Backend.getScrollOffset();"' ), - + 'popups' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['popups'], + 'href' => 'table=tl_leaflet_popup', + 'icon' => 'system/modules/leaflet/assets/img/popup.png', + 'attributes' => 'onclick="Backend.getScrollOffset();"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], diff --git a/module/languages/en/tl_leaflet_icon.php b/module/languages/en/tl_leaflet_icon.php index cdcfff5..3c3fce2 100644 --- a/module/languages/en/tl_leaflet_icon.php +++ b/module/languages/en/tl_leaflet_icon.php @@ -9,6 +9,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_icon']['layersBtn'][0] = 'Manage layers'; $GLOBALS['TL_LANG']['tl_leaflet_icon']['layersBtn'][1] = 'Manage leaflet layers'; $GLOBALS['TL_LANG']['tl_leaflet_icon']['styles'][0] = 'Manage styles'; $GLOBALS['TL_LANG']['tl_leaflet_icon']['styles'][1] = 'Manage vector styles'; +$GLOBALS['TL_LANG']['tl_leaflet_icon']['popups'][0] = 'Manage popups'; +$GLOBALS['TL_LANG']['tl_leaflet_icon']['popups'][1] = 'Manage popups icons'; $GLOBALS['TL_LANG']['tl_leaflet_icon']['new'][0] = 'Create icon'; $GLOBALS['TL_LANG']['tl_leaflet_icon']['new'][1] = 'Create new icon'; $GLOBALS['TL_LANG']['tl_leaflet_icon']['edit'][0] = 'Edit icon'; diff --git a/module/languages/en/tl_leaflet_layer.php b/module/languages/en/tl_leaflet_layer.php index df61b1f..479589b 100644 --- a/module/languages/en/tl_leaflet_layer.php +++ b/module/languages/en/tl_leaflet_layer.php @@ -9,6 +9,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['map'][0] = 'Manage maps'; $GLOBALS['TL_LANG']['tl_leaflet_layer']['map'][1] = 'Manage leaflet maps'; $GLOBALS['TL_LANG']['tl_leaflet_layer']['icons'][0] = 'Manage icons'; $GLOBALS['TL_LANG']['tl_leaflet_layer']['icons'][1] = 'Manage marker icons'; +$GLOBALS['TL_LANG']['tl_leaflet_layer']['popups'][0] = 'Manage popups'; +$GLOBALS['TL_LANG']['tl_leaflet_layer']['popups'][1] = 'Manage popups icons'; $GLOBALS['TL_LANG']['tl_leaflet_layer']['styles'][0] = 'Manage styles'; $GLOBALS['TL_LANG']['tl_leaflet_layer']['styles'][1] = 'Manage vector styles'; $GLOBALS['TL_LANG']['tl_leaflet_layer']['new'][0] = 'Create layer'; diff --git a/module/languages/en/tl_leaflet_marker.php b/module/languages/en/tl_leaflet_marker.php index 7303aec..9f03d90 100644 --- a/module/languages/en/tl_leaflet_marker.php +++ b/module/languages/en/tl_leaflet_marker.php @@ -21,6 +21,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_marker']['toggle'][0] = 'Toggle activation'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['toggle'][1] = 'Toggle marker ID %s activation'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['icons'][0] = 'Manage icons'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['icons'][1] = 'Manage marker icons.'; +$GLOBALS['TL_LANG']['tl_leaflet_marker']['popups'][0] = 'Manage popups'; +$GLOBALS['TL_LANG']['tl_leaflet_marker']['popups'][1] = 'Manage popups icons'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][0] = 'Title'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][1] = 'Title of the map.'; diff --git a/module/languages/en/tl_leaflet_popup.php b/module/languages/en/tl_leaflet_popup.php new file mode 100644 index 0000000..7e839af --- /dev/null +++ b/module/languages/en/tl_leaflet_popup.php @@ -0,0 +1,58 @@ +getOptions(); } + /** + * Get all popups. + * + * @return array + */ + public function getPopups() + { + $collection = PopupModel::findAll(array('order' => 'title')); + $builder = OptionsBuilder::fromCollection($collection, 'id', 'title'); + + return $builder->getOptions(); + } + /** * Save the coordinates. * diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php index ae24135..b01ca2b 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php @@ -15,10 +15,12 @@ use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; +use Netzmacht\Contao\Leaflet\Model\PopupModel; use Netzmacht\Contao\Leaflet\ServiceContainerTrait; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\UI\Marker; +use Netzmacht\LeafletPHP\Definition\UI\Popup; /** * Class MarkerMapper maps the marker model to the marker definition. @@ -53,7 +55,7 @@ class MarkerMapper extends AbstractMapper $elementId = null ) { $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId); - $arguments[] = $model->coordinates ?: null; + $arguments[] = array($model->latitude, $model->longitude, $model->altitude ?: null) ?: null; return $arguments; } @@ -82,12 +84,25 @@ class MarkerMapper extends AbstractMapper ) { if ($definition instanceof Marker) { if ($model->addPopup) { + $popup = null; $content = $this ->getServiceContainer() ->getFrontendValueFilter() ->filter($model->popupContent); - $definition->bindPopup($content); + if ($model->popup) { + $popupModel = PopupModel::findActiveByPK($model->popup); + + if ($popupModel) { + $popup = $mapper->handle($popupModel, $filter, null, $definition); + } + } + + if ($popup instanceof Popup) { + $definition->bindPopup($content, $popup->getOptions()); + } else { + $definition->bindPopup($content); + } } if ($model->customIcon) { diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/UI/PopupMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/UI/PopupMapper.php new file mode 100644 index 0000000..7b43077 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/UI/PopupMapper.php @@ -0,0 +1,117 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Mapper\UI; + +use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; +use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Model\PopupModel; +use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\UI\Popup; + +/** + * Class PopupMapper. + * + * @package Netzmacht\Contao\Leaflet\Mapper\UI + */ +class PopupMapper extends AbstractMapper +{ + /** + * The definition class. + * + * @var string + */ + protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\UI\Popup'; + + /** + * The model class. + * + * @var string + */ + protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\PopupModel'; + + /** + * {@inheritdoc} + */ + protected function initialize() + { + parent::initialize(); + + $this->optionsBuilder + ->addConditionalOption('maxWidth') + ->addConditionalOption('minWidth') + ->addConditionalOption('maxHeight') + ->addConditionalOption('className') + ->addOptions('autoPan', 'keepInView', 'closeButton', 'zoomAnimation'); + } + + /** + * {@inheritdoc} + */ + protected function build( + Definition $definition, + \Model $model, + DefinitionMapper $mapper, + Filter $filter = null, + Definition $parent = null + ) { + parent::build($definition, $model, $mapper, $filter, $parent); + + /** @var Popup $definition */ + /** @var PopupModel $model */ + + $this->deserializePoint('offset', $definition, $model); + + if ($model->autoPan) { + $padding = array_map( + function ($value) { + return array_map('intval', trimsplit(',', $value)); + }, + deserialize($model->autoPanPadding, true) + ); + + if ($padding[0] === $padding[1]) { + $definition->setAutoPanPadding($padding[0]); + } else { + if ($padding[0]) { + $definition->setAutoPanPaddingTopLeft($padding[0]); + } + if ($padding[1]) { + $definition->setAutoPanPaddingBottomRight($padding[1]); + } + } + } + + if (!$model->closeOnClick) { + $definition->setCloseOnClick(false); + } + } + + /** + * Deserialize point value and add it as option. + * + * @param string $option The option name. + * @param Popup $definition The popup definition. + * @param PopupModel $model The popup model. + * + * @return $this + */ + protected function deserializePoint($option, Popup $definition, PopupModel $model) + { + if ($model->$option) { + $setter = 'set' . ucfirst($option); + $definition->$setter(array_map('intval', explode(',', $model->$option, 2))); + } + + return $this; + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Model/PopupModel.php b/src/Netzmacht/Contao/Leaflet/Model/PopupModel.php new file mode 100644 index 0000000..e9789b3 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Model/PopupModel.php @@ -0,0 +1,29 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Model; + +/** + * Class PopupModel. + * + * @property mixed|null offset + * + * @package Netzmacht\Contao\Leaflet\Model + */ +class PopupModel extends AbstractActiveModel +{ + /** + * The table name. + * + * @var string + */ + protected static $strTable = 'tl_leaflet_popup'; +} diff --git a/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php b/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php index 809e6a0..03f5b78 100644 --- a/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php +++ b/src/Netzmacht/Contao/Leaflet/Subscriber/GeoJsonSubscriber.php @@ -63,6 +63,10 @@ class GeoJsonSubscriber implements EventSubscriberInterface if ($definition->getPopupContent()) { $feature->setProperty('popupContent', $definition->getPopupContent()); } + + if ($definition->getPopupOptions()) { + $feature->setProperty('popupOptions', $definition->getPopupOptions()); + } } }