Implement the extra markers icons.

This commit is contained in:
David Molineus
2016-11-14 13:31:19 +01:00
parent 3f05bd8783
commit d95f45d35a
6 changed files with 169 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -89,7 +89,14 @@ L.Contao = L.Class.extend({
*/
loadIcons: function (icons) {
for (var i = 0; i < icons.length; i++) {
var icon = L[icons[i].type](icons[i].options);
var icon;
if (icons[i].type === 'extraMarkers.icon') {
icon = L.ExtraMarkers.icon(icons[i].options);
} else {
icon = L[icons[i].type](icons[i].options);
}
this.addIcon(icons[i].id, icon);
}
},

View File

@@ -103,7 +103,6 @@ L.OverPassLayer = L.FeatureGroup.extend({
&& feature.properties.tags.amenity
&& this.options.amenityIcons[feature.properties.tags.amenity]
) {
console.log(this.options.amenityIcons[feature.properties.tags.amenity]);
icon = L.contao.getIcon(this.options.amenityIcons[feature.properties.tags.amenity]);
}

View File

@@ -154,6 +154,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = function () {
$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\Type\ExtraMarkersIconMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Style\FixedStyleMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = function () {
return new \Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper(
@@ -301,7 +302,7 @@ $GLOBALS['LEAFLET_CONTROLS'] = array('zoom', 'layers', 'scale', 'attribution',
*
* Supported leaflet icon types. Register you type for the database driven definition here.
*/
$GLOBALS['LEAFLET_ICONS'] = array('image', 'div');
$GLOBALS['LEAFLET_ICONS'] = array('image', 'div', 'extra');
/*

View File

@@ -150,8 +150,22 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'active' => array(
'active'
)
),
'extra extends default' => array(
'config' => array(
'icon',
'prefix',
'shape',
'markerColor',
'number',
'iconColor',
),
'active' => array(
'active'
)
),
),
'fields' => array
(
@@ -351,5 +365,82 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
),
'sql' => "mediumtext NULL"
),
'icon' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['icon'],
'exclude' => true,
'inputType' => 'text',
'eval' => array(
'maxlength' => 64,
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(64) NULL"
),
'prefix' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['prefix'],
'exclude' => true,
'inputType' => 'text',
'eval' => array(
'maxlength' => 64,
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(64) NULL"
),
'shape' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['shape'],
'exclude' => true,
'inputType' => 'select',
'default' => 'circle',
'options' => ['circle', 'square', 'star', 'penta'],
'eval' => array(
'tl_class' => 'w50',
),
'sql' => "varchar(64) NULL"
),
'iconColor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconColor'],
'exclude' => true,
'inputType' => 'text',
'eval' => array(
'maxlength' => 64,
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(16) NULL"
),
'markerColor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['markerColor'],
'exclude' => true,
'inputType' => 'select',
'default' => 'circle',
'options' => [
'blue',
'red',
'orange-dark',
'orange',
'yellow',
'blue-dark',
'cyan',
'purple',
'violet',
'pink',
'green-dark',
'green',
'green-light',
'black',
'white'
],
'eval' => array(
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(16) NULL"
),
),
);

View File

@@ -0,0 +1,66 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\DivIcon;
/**
* Class DivIconMapper maps the icon model to the div icon definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Type
*/
class ExtraMarkersIconMapper extends AbstractIconMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Plugins\ExtraMarkers\ExtraMarkersIcon';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'extra';
/**
* {@inheritdoc}
*/
protected function initialize()
{
parent::initialize();
$this->optionsBuilder->addOptions(['icon', 'iconColor', 'markerColor', 'shape', 'number', 'prefix']);
}
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $filter);
if ($definition instanceof DivIcon && $model->iconSize) {
$definition->setIconSize(explode(',', $model->iconSize, 2));
}
}
}