diff --git a/assets/maps/contao-leaflet.js b/assets/maps/contao-leaflet.js
index c6ac251..7770339 100644
--- a/assets/maps/contao-leaflet.js
+++ b/assets/maps/contao-leaflet.js
@@ -1 +1 @@
-L.Contao=L.Class.extend({includes:L.Mixin.Events,statics:{ATTRIBUTION:' | netzmacht'},maps:{},icons:{},initialize:function(){L.Icon.Default.imagePath="assets/leaflet/libs/leaflet/images/",this.setGeoJsonListeners(L.GeoJSON)},addMap:function(t,o){return this.maps[t]=o,this.fire("map:added",{id:t,map:o}),this},getMap:function(t){return"undefined"==typeof this.maps[t]?null:this.maps[t]},addIcon:function(t,o){return this.icons[t]=o,this.fire("icon:added",{id:t,icon:o}),this},loadIcons:function(t){for(var o=0;o=200&&t<300||304===t}function i(){void 0===a.status||n(a.status)?o.call(a,null,a):o.call(a,a,null)}var s=!1;if("undefined"==typeof window.XMLHttpRequest)return o(Error("Browser not supported"));if("undefined"==typeof e){var r=t.match(/^\s*https?:\/\/[^\/]*/);e=r&&r[0]!==location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")}var a=new window.XMLHttpRequest;if(e&&!("withCredentials"in a)){a=new window.XDomainRequest;var p=o;o=function(){if(s)p.apply(this,arguments);else{var t=this,o=arguments;setTimeout(function(){p.apply(t,o)},0)}}}return"onload"in a?a.onload=i:a.onreadystatechange=function(){4===a.readyState&&i()},a.onerror=function(t){o.call(this,t||!0,null),o=function(){}},a.onprogress=function(){},a.ontimeout=function(t){o.call(this,t,null),o=function(){}},a.onabort=function(t){o.call(this,t,null),o=function(){}},a.open("GET",t,!0),a.send(null),s=!0,a}});
\ No newline at end of file
+L.Contao=L.Class.extend({includes:L.Mixin.Events,statics:{ATTRIBUTION:' | netzmacht'},maps:{},icons:{},initialize:function(){L.Icon.Default.imagePath="assets/leaflet/libs/leaflet/images/",this.setGeoJsonListeners(L.GeoJSON)},addMap:function(t,o){return this.maps[t]=o,this.fire("map:added",{id:t,map:o}),this},getMap:function(t){return"undefined"==typeof this.maps[t]?null:this.maps[t]},addIcon:function(t,o){return this.icons[t]=o,this.fire("icon:added",{id:t,icon:o}),this},loadIcons:function(t){for(var o=0;o=200&&t<300||304===t}function i(){void 0===r.status||n(r.status)?o.call(r,null,r):o.call(r,r,null)}var s=!1;if("undefined"==typeof window.XMLHttpRequest)return o(Error("Browser not supported"));if("undefined"==typeof e){var a=t.match(/^\s*https?:\/\/[^\/]*/);e=a&&a[0]!==location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")}var r=new window.XMLHttpRequest;if(e&&!("withCredentials"in r)){r=new window.XDomainRequest;var p=o;o=function(){if(s)p.apply(this,arguments);else{var t=this,o=arguments;setTimeout(function(){p.apply(t,o)},0)}}}return"onload"in r?r.onload=i:r.onreadystatechange=function(){4===r.readyState&&i()},r.onerror=function(t){o.call(this,t||!0,null),o=function(){}},r.onprogress=function(){},r.ontimeout=function(t){o.call(this,t,null),o=function(){}},r.onabort=function(t){o.call(this,t,null),o=function(){}},r.open("GET",t,!0),r.send(null),s=!0,r}});
\ No newline at end of file
diff --git a/assets/maps/src/OverpassLayer.js b/assets/maps/src/OverpassLayer.js
index 2018903..df909f9 100644
--- a/assets/maps/src/OverpassLayer.js
+++ b/assets/maps/src/OverpassLayer.js
@@ -18,7 +18,8 @@ L.OverPassLayer = L.FeatureGroup.extend({
options: {
minZoom: 0,
endpoint: '//overpass-api.de/api/',
- query: '(node(BBOX)[organic];node(BBOX)[second_hand];);out qt;'
+ query: '(node(BBOX)[organic];node(BBOX)[second_hand];);out qt;',
+ amenityIcons: {}
},
/**
* Initialize the layer.
@@ -87,6 +88,7 @@ L.OverPassLayer = L.FeatureGroup.extend({
},
pointToLayer: function (feature, latlng) {
var type = 'marker';
+ var icon = null;
var marker = L.marker(latlng, feature.properties.options);
if (feature.properties) {
@@ -95,11 +97,18 @@ L.OverPassLayer = L.FeatureGroup.extend({
}
if (feature.properties.icon) {
- var icon = this._map.getIcon(feature.properties.icon);
+ icon = this._map.getIcon(feature.properties.icon);
- if (icon) {
- marker.setIcon(icon);
- }
+ } else if (feature.properties.tags
+ && 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]);
+ }
+
+ if (icon) {
+ marker.setIcon(icon);
}
L.contao.bindPopupFromFeature(marker, feature);
diff --git a/module/config/leaflet_amenities.php b/module/config/leaflet_amenities.php
new file mode 100644
index 0000000..07e5210
--- /dev/null
+++ b/module/config/leaflet_amenities.php
@@ -0,0 +1,213 @@
+
+ * @copyright 2014-2016 netzmacht David Molineus
+ * @license LGPL 3.0
+ * @filesource
+ *
+ */
+
+return [
+ 'administration',
+ 'advertising',
+ 'alm',
+ 'animal_boarding',
+ 'animal_breeding',
+ 'animal_shelter',
+ 'architect_office',
+ 'arts_centre',
+ 'artwork',
+ 'atm',
+ 'audiologist',
+ 'baby_hatch',
+ 'bank',
+ 'bar',
+ 'bbq',
+ 'bench',
+ 'bicycle_parking',
+ 'bicycle_rental',
+ 'bicycle_repair_station',
+ 'bicycle_trailer_sharing',
+ 'biergarten',
+ 'bikeshed',
+ 'boat_rental',
+ 'boat_sharing',
+ 'boat_storage',
+ 'brothel',
+ 'bts',
+ 'bureau_de_change',
+ 'bus_station',
+ 'cafe',
+ 'canoe_hire',
+ 'car_rental',
+ 'car_repair',
+ 'car_sharing',
+ 'car_wash',
+ 'casino',
+ 'charging_station',
+ 'childcare',
+ 'cinema',
+ 'citymap_post',
+ 'clinic',
+ 'clock',
+ 'club',
+ 'coast_guard',
+ 'coast_radar_station',
+ 'college',
+ 'community_center',
+ 'community_centre',
+ 'compressed_air',
+ 'concert_hall',
+ 'conference_centre',
+ 'courthouse',
+ 'coworking_space',
+ 'crematorium',
+ 'crucifix',
+ 'crypt',
+ 'customs',
+ 'dancing_school',
+ 'dead_pub',
+ 'dentist',
+ 'disused',
+ 'dive_centre',
+ 'doctors',
+ 'dog_bin',
+ 'dog_waste_bin',
+ 'dojo',
+ 'drinking_water',
+ '_driving_school',
+ 'education',
+ 'embassy',
+ 'emergency_phone',
+ 'emergency_service',
+ 'events_venue',
+ 'ev_charging',
+ 'exhibition_centre',
+ 'fast_food',
+ 'ferry_terminal',
+ 'festival_grounds',
+ 'financial_advice',
+ 'fire_hydrant',
+ 'fire_station',
+ 'first_aid',
+ 'fish_spa',
+ 'food_court',
+ 'fountain',
+ 'fuel',
+ 'gambling',
+ 'game_feeding',
+ 'garages',
+ 'grave_yard',
+ 'grit_bin',
+ 'harbourmaster',
+ 'hospice',
+ 'hospital',
+ 'hotel',
+ 'hunting_stand',
+ 'ice_cream',
+ 'internet_cafe',
+ 'jobcentre',
+ 'kindergarten',
+ 'kiosk',
+ 'kitchen',
+ 'Kneippbecken',
+ 'kneipp_water_cure',
+ 'language_school',
+ 'lavoir',
+ 'library',
+ 'lifeboat_station',
+ 'life_ring',
+ 'loading_dock',
+ 'love_hotel',
+ 'marae',
+ 'marketplace',
+ 'milk_dispenser',
+ 'mobile_library',
+ 'monastery',
+ 'money_transfer',
+ 'mortuary',
+ 'motorcycle_parking',
+ 'motorcycle_rental',
+ 'music_school',
+ 'music_venue',
+ 'nameplate',
+ 'nightclub',
+ 'nursery',
+ 'nursing_home',
+ 'park',
+ 'parking',
+ 'parking_entrance',
+ 'parking_space',
+ 'pharmacy',
+ 'photo_booth',
+ 'place_of_worship',
+ 'planetarium',
+ 'police',
+ 'post_box',
+ 'post_office',
+ 'preschool',
+ 'printer',
+ 'prison',
+ 'prison_camp',
+ 'proposed',
+ 'pub',
+ 'public_bath',
+ 'public_bookcase',
+ 'public_building',
+ 'public_hall',
+ 'ranger_station',
+ 'recycling',
+ 'refugee_housing',
+ 'register_office',
+ 'rescue_box',
+ 'rescue_station',
+ 'research_institute',
+ 'restaurant',
+ 'retirement_home',
+ 'sanatorium',
+ 'sanitary_dump_station',
+ 'sauna',
+ 'school',
+ 'scout_hut',
+ 'shelter',
+ 'shop',
+ 'shower',
+ 'ski_school',
+ 'smoking_area',
+ 'social_centre',
+ 'social_facility',
+ 'spa',
+ 'stables',
+ 'stripclub',
+ 'studio',
+ 'swimming_pool',
+ 'swingerclub',
+ 'table',
+ 'taxi',
+ 'telephone',
+ 'theatre',
+ 'ticket_booth',
+ 'ticket_validator',
+ 'toilets',
+ 'townhall',
+ 'trolley_bay',
+ 'university',
+ 'vacuum_cleaner',
+ 'vehicle_inspection',
+ 'vending_machine',
+ 'veterinary',
+ 'vivarium',
+ 'wash_center',
+ 'waste_basket',
+ 'waste_disposal',
+ 'waste_transfer_station',
+ 'water',
+ 'watering_place',
+ 'water_point',
+ 'weighbridge',
+ 'winery',
+ 'yacht_club',
+ 'youth_centre',
+];
diff --git a/module/config/services.php b/module/config/services.php
index 56c5585..8ed2ab0 100644
--- a/module/config/services.php
+++ b/module/config/services.php
@@ -242,7 +242,8 @@ $container['leaflet.dca.layer-callbacks'] = $container->share(
$container[Services::DATABASE_CONNECTION],
$container[Services::TRANSLATOR],
$GLOBALS['LEAFLET_LAYERS'],
- $GLOBALS['LEAFLET_TILE_PROVIDERS']
+ $GLOBALS['LEAFLET_TILE_PROVIDERS'],
+ require TL_ROOT . '/system/modules/leaflet/config/leaflet_amenities.php'
);
}
);
diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php
index fa7710a..fd9f175 100644
--- a/module/dca/tl_leaflet_layer.php
+++ b/module/dca/tl_leaflet_layer.php
@@ -153,6 +153,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'default' => array(
'title' => array('title', 'alias', 'type'),
'config' => array(),
+ 'style' => array(),
'expert' => array(':hide'),
'active' => array('active'),
),
@@ -217,9 +218,12 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'overpass extends default' => array(
'config' => array(
'overpassQuery',
- 'overpassEndpoint',
+ 'boundsMode',
'minZoom',
- 'boundsMode'
+ 'overpassEndpoint',
+ ),
+ 'style' => array(
+ 'amenityIcons'
),
'+expert' => array(
'onEachFeature',
@@ -871,5 +875,41 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('tl_class' => 'w50 m12'),
'sql' => "char(1) NOT NULL default ''"
),
+ 'amenityIcons' => array
+ (
+ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'],
+ 'exclude' => true,
+ 'inputType' => 'multiColumnWizard',
+ 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getIcons'),
+ 'eval' => array(
+ 'columnFields' => array(
+ 'amenity' => array(
+ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'],
+ 'exclude' => true,
+ 'inputType' => 'select',
+ 'options_callback' => \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks::callback('getAmenities'),
+ 'eval' => array(
+ 'mandatory' => true,
+ 'tl_class' => 'w50',
+ 'style' => 'width: 200px',
+ 'chosen' => true,
+ ),
+ ),
+ 'icon' => array(
+ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'],
+ 'exclude' => true,
+ 'inputType' => 'select',
+ 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getIcons'),
+ 'eval' => array(
+ 'mandatory' => true,
+ 'tl_class' => 'w50',
+ 'style' => 'width: 200px',
+ 'chosen' => true,
+ ),
+ ),
+ ),
+ ),
+ 'sql' => "blob NULL",
+ ),
)
);
diff --git a/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php b/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php
index 402985c..727a474 100644
--- a/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php
+++ b/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php
@@ -66,6 +66,17 @@ class LayerCallbacks extends Callbacks
*/
private $translator;
+ /**
+ * OSM amenities.
+ *
+ * @var array
+ */
+ private $amenities;
+ /**
+ * @var Manager
+ */
+ private $manager;
+
/**
* Construct.
*
@@ -74,23 +85,26 @@ class LayerCallbacks extends Callbacks
* @param Translator $translator Translator.
* @param array $layers Leaflet layer configuration.
* @param array $tileProviders Tile providers.
+ * @param array $amenities OSM amenities
*/
public function __construct(
Manager $manager,
\Database $database,
Translator $translator,
array $layers,
- array $tileProviders
+ array $tileProviders,
+ array $amenities
) {
parent::__construct($manager);
+ \Controller::loadLanguageFile('leaflet_layer');
+
$this->database = $database;
$this->layers = $layers;
$this->tileProviders = $tileProviders;
-
- \Controller::loadLanguageFile('leaflet_layer');
-
- $this->translator = $translator;
+ $this->manager = $manager;
+ $this->translator = $translator;
+ $this->amenities = $amenities;
}
/**
@@ -359,6 +373,16 @@ class LayerCallbacks extends Callbacks
->getOptions();
}
+ /**
+ * Get all know osm amenities as options.
+ *
+ * @return array
+ */
+ public function getAmenities()
+ {
+ return $this->amenities;
+ }
+
/**
* Generate a button.
*
diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php
index 36fb44d..398c354 100644
--- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php
+++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php
@@ -14,6 +14,7 @@ use Model;
use Netzmacht\Contao\Leaflet\Definition\Layer\OverpassLayer;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
+use Netzmacht\Contao\Leaflet\Model\IconModel;
use Netzmacht\JavascriptBuilder\Type\Expression;
use Netzmacht\LeafletPHP\Definition;
@@ -66,6 +67,9 @@ class OverpassLayerMapper extends AbstractLayerMapper
return;
}
+ $amenityIconsMap = $this->buildAmenityIconsMap($model);
+ $definition->setOption('amenityIcons', $amenityIconsMap);
+
if ($model->pointToLayer) {
$definition->setPointToLayer(new Expression($model->pointToLayer));
}
@@ -74,4 +78,43 @@ class OverpassLayerMapper extends AbstractLayerMapper
$definition->setOnEachFeature(new Expression($model->onEachFeature));
}
}
+
+ /**
+ * Build the amenity icons map.
+ *
+ * @param Model $model Definition model.
+ *
+ * @return array
+ */
+ protected function buildAmenityIconsMap(Model $model)
+ {
+ $amenityIconsConfig = deserialize($model->amenityIcons, true);
+ $amenityIconsMap = [];
+ foreach ($amenityIconsConfig as $config) {
+ if (!$config['amenity'] || !$config['icon']) {
+ continue;
+ }
+
+ $amenityIconsMap[$config['amenity']] = $config['icon'];
+ }
+
+ if ($amenityIconsMap) {
+ $collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap));
+ $icons = [];
+
+ if ($collection) {
+ foreach ($collection as $iconModel) {
+ $icons[$iconModel->id] = $iconModel->alias ?: $iconModel->id;
+ }
+
+ foreach ($amenityIconsMap as $amenity => $iconId) {
+ if (isset($icons[$iconId])) {
+ $amenityIconsMap[$amenity] = $icons[$iconId];
+ }
+ }
+ }
+ }
+
+ return $amenityIconsMap;
+ }
}