Implement amenity icons mapping.

This commit is contained in:
David Molineus
2016-11-14 11:35:09 +01:00
parent c61e2d9cc9
commit f462a11c1d
7 changed files with 344 additions and 14 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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);

View File

@@ -0,0 +1,213 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @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',
];

View File

@@ -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'
);
}
);

View File

@@ -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",
),
)
);

View File

@@ -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.
*

View File

@@ -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;
}
}