From 8f5a4db59286a083ecd9ab2ba20d0566783b0332 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Sun, 3 Feb 2013 12:50:50 +0000 Subject: Put settlements into one layer, add to control --- resources/map.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/resources/map.js b/resources/map.js index 9477114..ef1f63d 100644 --- a/resources/map.js +++ b/resources/map.js @@ -127,13 +127,13 @@ function displayMap(self, map) { markers[feature.id] = layer; }, filter: function(feature, layer) { + // TODO: Fix and make more efficient return _.contains(_.values(feature.properties), amenity); } }); } function createCatchmentAreaVillageLayer(catchmentArea) { - var poly = ""; _.each(catchmentArea.geometry.coordinates[0], function(coordinatePair) { poly += coordinatePair[1] + " " + coordinatePair[0] + " "; @@ -143,31 +143,14 @@ function displayMap(self, map) { var query = 'data=[out:json];(node(poly:"' + poly + '");<;node(w););out;'; // Convert the data to GeoJSON - + // TODO: Don't refetch villages on every map move self.converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, function(data) { data.features = _.filter(data.features, function(feature) { return _.contains(_.keys(feature.properties), "place") || feature.properties["landuse"] == "residential"; }); catchmentArea.populationAreas = data.features; - - if (typeof self.villageLayers[catchmentArea.id] == 'undefined') { - self.villageLayers[catchmentArea.id] = L.geoJson(data, { - style: function(feature) { - return {fillColor: 'green', - weight: 2, - opacity: 1, - color: 'black', - dashArray: '3', - fillOpacity: 0.1}; - } - }); - - map.addLayer(self.villageLayers[catchmentArea.id]); - } else { - self.villageLayers[catchmentArea.id].clearLayers(); - self.villageLayers[catchmentArea.id].addData(data); - } + self.villageLayer.addData(data); }); } @@ -177,6 +160,19 @@ function displayMap(self, map) { self.converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, function(data) { if (jQuery.isEmptyObject(self.amenityLayers)) { + self.villageLayer = L.geoJson(data, { + style: function(feature) { + return {fillColor: 'green', + weight: 2, + opacity: 1, + color: 'black', + dashArray: '3', + fillOpacity: 0.1}; + } + }); + map.addLayer(self.villageLayer); + self.layersControl.addOverlay(self.villageLayer, "Settlements"); + self.villageLayer.clearLayers(); // For each catchment area polygon _.each( _.filter(data.features, -- cgit v1.2.3