From 9b2e9210f9e3a152124a071946d7a8d8b343963f Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 11 Apr 2014 12:22:54 +0100 Subject: Add ability to get vending machines layer --- src/leaflet-soton.js | 54 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js index f1a3fe9..3e6ffc3 100644 --- a/src/leaflet-soton.js +++ b/src/leaflet-soton.js @@ -91,6 +91,32 @@ return null; }, + getVendingMachinesLayer: function() { + var features = []; + + this.data.buildingFeatures.features.forEach(function(feature) { + if ("vending" in feature.properties) { + features.push(feature); + } + }); + + var layer = new L.GeoJSON(features, { + pointToLayer: vendingPointToLayer, + onEachFeature: function(feature, layer) { + layer.on('click', function(e) { + var popupOptions = { + offset: icons.vendingHotDrinks.options.popupAnchor + }; + + var content = vendingPopupTemplate(feature.properties); + + showPopup(map, content, e.latlng, popupOptions); + }); + } + }); + + return layer; + }, _updateWorkstationData: function() { var query; @@ -562,21 +588,11 @@ SELECT * WHERE {\ }); }, pointToLayer: function (feature, latlng) { - var icon; - if ('vending' in feature.properties) { - if (feature.properties.vending === 'drinks') { - icon = icons.vendingHotDrinks; - } else if (feature.properties.vending === 'sweets') { - icon = icons.vendingSweets; - } else { - console.warn("Unrecognired vending " + feature.properties.vending); - } + return vendingPointToLayer(feature, latlng); } else { - icon = icons.printer; + return L.marker(latlng, {icon: icons.printer}); } - - return L.marker(latlng, {icon: icon}); } }); @@ -743,6 +759,20 @@ SELECT * WHERE {\ return new LS.Map(id, options); }; + function vendingPointToLayer(feature, latlng) { + var icon; + + if (feature.properties.vending === 'drinks') { + icon = icons.vendingHotDrinks; + } else if (feature.properties.vending === 'sweets') { + icon = icons.vendingSweets; + } else { + console.warn("Unrecognired vending " + feature.properties.vending); + } + + return L.marker(latlng, {icon: icon}); + } + function showPopup(map, content, latlng, popupOptions) { popupOptions = popupOptions || {}; -- cgit v1.2.3