Add icon support.

This commit is contained in:
David Molineus
2015-01-06 21:30:57 +01:00
parent 3608f7cd48
commit adc8de55ae
11 changed files with 367 additions and 136 deletions

View File

@@ -3,6 +3,8 @@ L.Contao = L.Class.extend( {
maps: {},
icons: {},
addMap: function (id, map) {
this.maps[id] = map;
@@ -19,9 +21,32 @@ L.Contao = L.Class.extend( {
return this.maps[id];
},
addIcon: function(id, icon) {
this.icons[id] = icon;
this.fire('icon:added', { id: id, icon: icon});
return this;
},
getIcon: function(id) {
if (typeof (this.icons[id]) === 'undefined') {
return null;
}
return this.icons[id];
},
pointToLayer: function(feature, latlng) {
var marker = L.marker(latlng, feature.properties.options);
if (feature.properties && feature.properties.icon) {
var icon = this.getIcon(feature.properties.icon);
if (icon) {
marker.setIcon(icon);
}
}
this.applyFeatureMethods(marker, feature);
this.fire('marker:created', { marker: marker, feature: feature, latlng: latlng });

View File

@@ -25,9 +25,10 @@ $GLOBALS['TL_CTE']['includes']['leaflet'] = 'Netzmacht\Contao\Leaflet\LeafletMap
/*
* Models.
*/
$GLOBALS['TL_MODELS']['tl_leaflet_map'] = 'Netzmacht\Contao\Leaflet\Model\MapModel';
$GLOBALS['TL_MODELS']['tl_leaflet_layer'] = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
$GLOBALS['TL_MODELS']['tl_leaflet_control'] = 'Netzmacht\Contao\Leaflet\Model\ControlModel';
$GLOBALS['TL_MODELS']['tl_leaflet_icon'] = 'Netzmacht\Contao\Leaflet\Model\IconModel';
$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';
@@ -45,6 +46,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ScaleCo
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\LayersControlMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\AttributionControlMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Type\ImageIconMapper';
/*
* Leaflet encoders.
@@ -121,6 +123,7 @@ $GLOBALS['LEAFLET_CONTROLS'][] = 'layers';
$GLOBALS['LEAFLET_CONTROLS'][] = 'scale';
$GLOBALS['LEAFLET_CONTROLS'][] = 'attribution';
$GLOBALS['LEAFLET_ICONS'] = array('image', 'div');
/*
* Leaflet tile layer providers.

View File

@@ -5,7 +5,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'config' => array(
'dataContainer' => 'Table',
'enableVersioning' => true,
'ptable' => 'tl_leaflet_layer',
'sql' => array
(
'keys' => array
@@ -23,12 +22,11 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'fields' => array('title'),
'flag' => 1,
'headerFields' => array('title', 'type'),
'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'generateRow'),
),
'label' => array
(
'fields' => array('title'),
'format' => '%s',
'fields' => array('title', 'type'),
'format' => '%s <span class="tl_gray">[%s]</span>',
),
'global_operations' => array
(
@@ -87,23 +85,32 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
)
),
'palettes' => array(
'__selector__' => array('type')
),
'metapalettes' => array(
'default' => array(
'title' => array('title', 'alias', 'type'),
'content' => array('tooltip', 'alt',),
),
'image extends default' => array(
'config' => array(
':hide',
'iconUrl',
'iconRetinaUrl',
'',
'iconImage',
'iconRetinaImage',
'iconAnchor',
'popupAnchor',
'iconClassName',
),
'shadow' => array(
'shadowImage',
'shadowRetinaImage',
'shadowAnchor',
),
'active' => array('active')
),
'active' => array(
'active'
)
)
),
'fields' => array
@@ -136,6 +143,22 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'type' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['type'],
'exclude' => true,
'inputType' => 'select',
'eval' => array(
'mandatory' => true,
'tl_class' => 'w50',
'includeBlankOption' => true,
'submitOnChange' => true,
'chosen' => true,
),
'options' => &$GLOBALS['LEAFLET_ICONS'],
'reference' => &$GLOBALS['TL_LANG']['leaflet_icon'],
'sql' => "varchar(32) NOT NULL default ''"
),
'active' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['active'],
@@ -144,58 +167,58 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'iconUrl' => array
'iconImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['iconUrl'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => true,
'tl_class' => 'clr w50',
'tl_class' => 'clr',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'iconRetinaUrl' => array
'iconRetinaImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['iconRetinaUrl'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconRetinaImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'w50',
'tl_class' => 'clr',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'shadowImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowImage'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'clr w50',
'tl_class' => 'clr',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'shadowRetinaImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowRetinaImage'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowRetinaImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'w50',
'tl_class' => 'clr',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",

View File

@@ -84,7 +84,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'default' => array(
'title' => array('title', 'alias', 'coordinates'),
'content' => array('tooltip', 'alt', 'addPopup'),
'icon' => array(':hide', 'customIcon'),
'config' => array(
':hide',
'clickable',
@@ -93,23 +92,15 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'zIndexOffset',
'opacity',
'riseOnHover',
'riseOffset'
'riseOffset',
'customIcon',
),
'active' => array('active')
),
),
'metasubpalettes' => array(
'addPopup' => array('popupContent'),
'customIcon' => array(
'icon',
'retinaIcon',
'iconAnchor',
'popupAnchor',
'iconClassName',
'shadowImage',
'shadowRetinaImage',
'shadowAnchor',
)
'customIcon' => array('icon')
),
'fields' => array
@@ -206,64 +197,20 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class' => 'w50', 'submitOnChange' => true),
'eval' => array('tl_class' => 'clr w50 m12', 'submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''"
),
'icon' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['icon'],
'exclude' => true,
'inputType' => 'fileTree',
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'getIcons'),
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => true,
'tl_class' => 'clr w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'retinaIcon' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['retinaIcon'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'shadowImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'clr w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'shadowRetinaImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowRetinaImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
'sql' => "int(10) unsigned NOT NULL default '0'",
),
'draggable' => array
(
@@ -301,58 +248,5 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'eval' => array('mandatory' => true, 'maxlength' => 4, 'rgxp' => 'digit', 'tl_class' => 'clr w50'),
'sql' => "int(4) NOT NULL default '0'"
),
'iconAnchor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['iconAnchor'],
'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"
),
'shadowAnchor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['shadowAnchor'],
'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"
),
'popupAnchor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupAnchor'],
'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"
),
'iconClassName' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['iconClassName'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
),
);

View File

@@ -0,0 +1,29 @@
<?php
$GLOBALS['TL_LANG']['tl_leaflet_icon']['title_legend'] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['config_legend'] = 'Configuration';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadow_legend'] = 'Shadow';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['active_legend'] = 'Activation';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['title'][1] = 'Title of the icon.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['alias'][1] = 'Alias of the icon.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['type'][1] = 'Choose the icon type.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconImage'][0] = 'Icon image';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconImage'][1] = 'Choose an icon image.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconRetinaImage'][0] = 'Retina icon image';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconRetinaImage'][1] = 'Choose an retina icon image.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconAnchor'][0] = 'Icon anchor';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['iconAnchor'][1] = 'The coordinates of the "tip" of the icon (relative to its top left corner).';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['popupAnchor'][0] = 'Popup anchor';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['popupAnchor'][1] = 'The coordinates of the point from which popups will "open", relative to the icon anchor.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowImage'][0] = 'Shadow image';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowImage'][1] = 'Choose an shadow image.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowRetinaImage'][0] = 'Retina shadow image';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowRetinaImage'][1] = 'Choose an retina shadow image.';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowAnchor'][0] = 'Shadow anchor';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['shadowAnchor'][1] = 'The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified).';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['active'][0] = 'Activate the icon';
$GLOBALS['TL_LANG']['tl_leaflet_icon']['active'][1] = 'Activate the icon.';