From b4ee6a2fc76e0ad29e61a5c8646599ca9547d400 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Sat, 2 Feb 2013 17:36:30 +0000 Subject: Begin work on data analysis --- index.html | 1 + resources/data.js | 9 ++++++ resources/map.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 resources/data.js diff --git a/index.html b/index.html index 071f0a9..66d7327 100644 --- a/index.html +++ b/index.html @@ -18,6 +18,7 @@ +
diff --git a/resources/data.js b/resources/data.js new file mode 100644 index 0000000..85a77c2 --- /dev/null +++ b/resources/data.js @@ -0,0 +1,9 @@ +function getVillages(area, zoom) { + var poly = "12.3 -12.3 12.4 -12.3 12.48 -12.25 12.35 -12.19"; + var query = 'data=[out:json];(node(poly:"' + poly + '");<;);out;'; + + converter = new op2geojson(); + converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, function(data) { + + }); +} diff --git a/resources/map.js b/resources/map.js index 5601167..cdeefd2 100644 --- a/resources/map.js +++ b/resources/map.js @@ -47,7 +47,6 @@ function displayMap(self, map) { var ne = bounds.getNorthEast(); bbox = [sw.lat, sw.lng, ne.lat, ne.lng].join(','); - // Get the data var data = createQueryData(bbox); // Convert the data to GeoJSON @@ -146,6 +145,101 @@ function displayMap(self, map) { }); } }); + + converter.fetch("http://overpass-api.de/api/interpreter", data, zoom, function(data) { + if (jQuery.isEmptyObject(self.amenityLayers)) { + var markers = {}; + var catchmentAreaForAmenity = {}; + + _.each( + _.filter(data.features, + function(feature) { + return _.contains(_.values(feature.properties), "catchment_area"); + }), + function(catchmentArea) { + catchmentAreaForAmenity[catchmentArea.properties["subject"]] = catchmentArea; + }); + + // Now deal with the catchment areas + self.catchmentAreaLayer = L.geoJson(data, { + style: function(feature) { + return {fillColor: 'green', + weight: 2, + opacity: 1, + color: 'black', + dashArray: '3', + fillOpacity: 0.1}; + }, + onEachFeature: function(feature, layer) { + layer.on({ + mouseover: highlightFeature, + mouseout: resetHighlight, + click: function() { + markers[feature.properties.subject].openPopup(); + } + }); + }, + filter: function(feature, layer) { + return _.contains(_.values(feature.properties), "catchment_area"); + } + }); + + _.each(self.amenities, function(amenity, i) { + self.amenityLayers[amenity] = L.geoJson(data, { + style: function(feature) { + return {color: 'red', + fillColor: 'red', + fillOpacity: 0.2, + weight: 10}; + }, + onEachFeature: function(feature, layer) { + var center; + if (feature.geometry.type === "Point") { + layer.options.icon = hospitalIcon; + center = feature.geometry.coordinates; + } else { + center = feature.geometry.coordinates[0]; + } + + var catchmentArea = catchmentAreaForAmenity[feature.id]; + + var format = new OpenLayers.Format.GeoJSON; + var openLayersGeo = format.parseGeometry(catchmentArea.geometry); + + var areaInSquareMeters = openLayersGeo.getGeodesicArea(); + var areaString = areaInSquareMeters.toFixed(2) + "m" + "2".sup(); + if (areaInSquareMeters > 1000000) { + areaString = (areaInSquareMeters / 1000000).toFixed(2) + "km" + "2".sup(); + } + var areaProperties = { area: areaString } + + layer.bindPopup(self.popupTemplate({ properties: $.extend(feature.properties, areaProperties), coordinate: center })); + + markers[feature.id] = layer; + }, + filter: function(feature, layer) { + return _.contains(_.values(feature.properties), amenity); + } + }); + + map.addLayer(self.amenityLayers[amenity]); + self.layersControl.addOverlay(self.amenityLayers[amenity], + self.amenities[i].charAt(0).toUpperCase() + self.amenities[i].slice(1)); + }); + + map.addLayer(self.catchmentAreaLayer); + self.layersControl.addOverlay(self.catchmentAreaLayer, "Catchment Areas"); + } else { + self.catchmentAreaLayer.clearLayers(); + self.catchmentAreaLayer.addData(data); + + _.each(self.amenities, function(amenity, i) { + // Update the data for each amenity layer + self.amenityLayers[amenity].clearLayers(); + self.amenityLayers[amenity].addData(data); + }); + } + }); } $(document).ready(function() { -- cgit v1.2.3