mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Add DivIcon support.
This commit is contained in:
@@ -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: ' | <a href="http://contao-leaflet.netzmacht.de/" title="Leaflet extension for Contao CMS">netzmacht <em>creative</em></a>',
|
||||
|
||||
/**
|
||||
* The map registry.
|
||||
*/
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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"
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
61
src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php
Normal file
61
src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2015 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user