From 7f791254950d85ef56f78ff2866b6ad0de88d5cd Mon Sep 17 00:00:00 2001 From: David Molineus Date: Thu, 8 Jan 2015 15:21:45 +0100 Subject: [PATCH] Add DivIcon support. --- assets/libs/contao/contao-leaflet.js | 8 ++- module/config/config.php | 1 + module/dca/tl_leaflet_icon.php | 41 ++++++++++++- module/dca/tl_leaflet_marker.php | 7 +++ module/languages/en/tl_leaflet_marker.php | 2 + .../Mapper/Type/AbstractIconMapper.php | 8 +++ .../Leaflet/Mapper/Type/DivIconMapper.php | 61 +++++++++++++++++++ .../Leaflet/Mapper/Type/ImageIconMapper.php | 22 +++---- .../Contao/Leaflet/Mapper/UI/MarkerMapper.php | 4 +- .../Leaflet/Subscriber/BootSubscriber.php | 4 +- 10 files changed, 137 insertions(+), 21 deletions(-) create mode 100644 src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php diff --git a/assets/libs/contao/contao-leaflet.js b/assets/libs/contao/contao-leaflet.js index b47fe81..7ce9143 100644 --- a/assets/libs/contao/contao-leaflet.js +++ b/assets/libs/contao/contao-leaflet.js @@ -1,7 +1,13 @@ -L.Contao = L.Class.extend( { +L.Contao = L.Class.extend({ includes: L.Mixin.Events, + /** + * Contao extension attribution. + * + * You are not allowed to remove or change it. Contact me if you want to buy an removal license. + */ attribution: ' | netzmacht creative', + /** * The map registry. */ diff --git a/module/config/config.php b/module/config/config.php index f73e9d1..8471ad8 100644 --- a/module/config/config.php +++ b/module/config/config.php @@ -51,6 +51,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\Attribu $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\LoadingControlMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper'; $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\Vector\PolylineMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\MultiPolylineMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\PolygonMapper'; diff --git a/module/dca/tl_leaflet_icon.php b/module/dca/tl_leaflet_icon.php index d838152..30debed 100644 --- a/module/dca/tl_leaflet_icon.php +++ b/module/dca/tl_leaflet_icon.php @@ -102,7 +102,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array ), 'image extends default' => array( 'config' => array( - '', 'iconImage', 'iconRetinaImage', 'iconAnchor', @@ -117,6 +116,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'active' => array( 'active' ) + ), + + 'div extends default' => array( + 'config' => array( + 'html', + 'iconSize', + 'iconAnchor', + 'popupAnchor', + 'className', + ), + 'active' => array( + 'active' + ) ) ), @@ -283,5 +295,32 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'eval' => array('mandatory' => false, 'maxlength' => 64, 'tl_class' => 'w50'), 'sql' => "varchar(64) NOT NULL default ''" ), + 'iconSize' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconSize'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array( + 'maxlength' => 64, + 'tl_class' => 'w50', + 'nullIfEmpty' => true, + ), + 'sql' => "varchar(64) NULL" + ), + 'html' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['html'], + 'exclude' => true, + 'inputType' => 'textarea', + 'eval' => array( + 'style' => 'height:60px', + 'preserveTags' => true, + 'decodeEntities' => true, + 'allowHtml' => true, + 'rte' => 'ace|html', + 'tl_class' => 'clr' + ), + 'sql' => "mediumtext NULL" + ), ), ); diff --git a/module/dca/tl_leaflet_marker.php b/module/dca/tl_leaflet_marker.php index fbf83e3..c46373a 100644 --- a/module/dca/tl_leaflet_marker.php +++ b/module/dca/tl_leaflet_marker.php @@ -35,6 +35,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array ), 'global_operations' => array ( + 'icons' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['icons'], + 'href' => 'table=tl_leaflet_icon&id=', + 'icon' => 'system/modules/leaflet/assets/img/icons.png', + 'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], diff --git a/module/languages/en/tl_leaflet_marker.php b/module/languages/en/tl_leaflet_marker.php index 25fc9cf..ca4ac97 100644 --- a/module/languages/en/tl_leaflet_marker.php +++ b/module/languages/en/tl_leaflet_marker.php @@ -17,6 +17,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_marker']['show'][0] = 'Show details'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['show'][1] = 'Show marker ID %s details'; $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']['title'][0] = 'Title'; $GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][1] = 'Title of the map.'; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Type/AbstractIconMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Type/AbstractIconMapper.php index 3b0aa85..18d6837 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Type/AbstractIconMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Type/AbstractIconMapper.php @@ -22,4 +22,12 @@ class AbstractIconMapper extends AbstractTypeMapper * @var string */ protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\IconModel'; + + /** + * {@inheritdoc} + */ + protected function initialize() + { + $this->addConditionalOption('className'); + } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php new file mode 100644 index 0000000..4e02f81 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php @@ -0,0 +1,61 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Mapper\Type; + + +use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\Type\DivIcon; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; + +class DivIconMapper extends AbstractIconMapper +{ + /** + * Class of the definition being created. + * + * @var string + */ + protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Type\DivIcon'; + + /** + * Layer type. + * + * @var string + */ + protected static $type = 'div'; + + /** + * {@inheritdoc} + */ + protected function initialize() + { + parent::initialize(); + + $this->addOption('html'); + } + + /** + * {@inheritdoc} + */ + protected function build( + Definition $definition, + \Model $model, + DefinitionMapper $mapper, + LatLngBounds $bounds = null + ) { + parent::build($definition, $model, $mapper, $bounds); + + if ($definition instanceof DivIcon && $model->iconSize) { + $definition->setIconSize(explode(',', $model->iconSize, 2)); + } + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php index b3660c7..68e7288 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Type/ImageIconMapper.php @@ -15,7 +15,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Type; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\LeafletPHP\Definition; -use Netzmacht\LeafletPHP\Definition\Type\Icon; +use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; class ImageIconMapper extends AbstractIconMapper @@ -25,7 +25,7 @@ class ImageIconMapper extends AbstractIconMapper * * @var string */ - protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Type\Icon'; + protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Type\ImageIcon'; /** * Layer type. @@ -34,14 +34,6 @@ class ImageIconMapper extends AbstractIconMapper */ protected static $type = 'image'; - /** - * {@inheritdoc} - */ - protected function initialize() - { - $this->addConditionalOption('className'); - } - /** * {@inheritdoc} */ @@ -69,7 +61,7 @@ class ImageIconMapper extends AbstractIconMapper DefinitionMapper $mapper, LatLngBounds $bounds = null ) { - if ($definition instanceof Icon) { + if ($definition instanceof ImageIcon) { $this->addIcon($definition, $model); $this->addShadow($definition, $model); } @@ -78,12 +70,12 @@ class ImageIconMapper extends AbstractIconMapper /** * Add icon image. * - * @param Icon $definition The icon definition. + * @param ImageIcon $definition The icon definition. * @param IconModel $model The model. * * @return void */ - private function addIcon(Icon $definition, IconModel $model) + private function addIcon(ImageIcon $definition, IconModel $model) { if ($model->iconImage) { $file = \FilesModel::findByUuid($model->iconImage); @@ -120,12 +112,12 @@ class ImageIconMapper extends AbstractIconMapper /** * Add shadow if defined. * - * @param Icon $definition The icon definition. + * @param ImageIcon $definition The icon definition. * @param IconModel $model The model. * * @return void */ - private function addShadow(Icon $definition, $model) + private function addShadow(ImageIcon $definition, $model) { if ($model->shadowImage) { $file = \FilesModel::findByUuid($model->shadowImage); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php index 6ed7f13..9e8cf15 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php @@ -16,7 +16,7 @@ use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\LeafletPHP\Definition; -use Netzmacht\LeafletPHP\Definition\Type\Icon; +use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\UI\Marker; @@ -80,7 +80,7 @@ class MarkerMapper extends AbstractMapper ); if ($iconModel) { - /** @var Icon $icon */ + /** @var ImageIcon $icon */ $icon = $builder->handle($iconModel); $definition->setIcon($icon); } diff --git a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php index 1b09110..5655bab 100644 --- a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php +++ b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php @@ -19,7 +19,7 @@ use Netzmacht\Contao\Leaflet\Event\InitializeLeafletBuilderEvent; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\LeafletPHP\Assets; -use Netzmacht\LeafletPHP\Definition\Type\Icon; +use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -136,7 +136,7 @@ class BootSubscriber implements EventSubscriberInterface $icons = array(); foreach ($collection as $model) { - /** @var Icon $icon */ + /** @var ImageIcon $icon */ $icon = $mapper->handle($model); $icons[] = array( 'id' => $icon->getId(),