diff options
author | Christopher Baines <cb15g11@soton.ac.uk> | 2014-04-11 12:22:54 +0100 |
---|---|---|
committer | Christopher Baines <cb15g11@soton.ac.uk> | 2014-04-11 12:22:54 +0100 |
commit | 9b2e9210f9e3a152124a071946d7a8d8b343963f (patch) | |
tree | aca9730ead82109deea870065f9158ba2962a8a7 /src | |
parent | 9ad37c250e0e607960ee3068465976752992f7b9 (diff) | |
download | leaflet-soton-9b2e9210f9e3a152124a071946d7a8d8b343963f.tar leaflet-soton-9b2e9210f9e3a152124a071946d7a8d8b343963f.tar.gz |
Add ability to get vending machines layer
Diffstat (limited to 'src')
-rw-r--r-- | src/leaflet-soton.js | 54 |
1 files changed, 42 insertions, 12 deletions
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 || {}; |