From eec66224805eccb9d3ac2a8c1b7202f82019e66e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 11 Dec 2012 21:58:52 +0000 Subject: Clicking on the catchment areas will now open the hospital popup The hospital popup now includes information for the hospital and the catchment area, this informaiton is also now presented in a human readable form, instead of a key value table. The information in the popup is not complete. --- resources/map.js | 104 +++++++++++++++++++++++++++--------------------- resources/op2geojson.js | 5 +++ 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/resources/map.js b/resources/map.js index 308caae..a2c16f5 100644 --- a/resources/map.js +++ b/resources/map.js @@ -2,27 +2,24 @@ $(document).ready(function() { var self = this; - self.popupTemplate = _.template('\ + self.hospitalTemplate = _.template('\ \ \ \ \ \ +

Hospital

\ \ -\ -<% _.each(properties, function(val, key) { %> \ -<% if (/\:/.exec(key)) { %> \ - \ - \ - \ - \ -<% } else {%> \ -\ - \ - \ -\ -<% } %> \ -<% }); %> \ +\ +\ +
KeyValue
<%= key.split(":")[1] %> <%= val %>
<%= key %> <%= val %>
Name<%= properties["name"] %>
Emergency<%= properties["emergency"] %>
\ +

Catchment Area

\ +\ +\ +\ +\ +\ +\
Surface Area
Number of villages
Population
Furthest Village from health structure
Average distance of all villages from health structure
'); self.catchmentTemplate = _.template('\ @@ -104,32 +101,7 @@ $(document).ready(function() { converter.fetch("http://overpass-api.de/api/interpreter", data, zoom, function(data) { if (jQuery.isEmptyObject(self.amenityLayers)) { - // 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: zoomToFeature - }); - - layer.bindPopup(self.catchmentTemplate({ properties: feature.properties })); - }, - filter: function(feature, layer) { - return _.contains(_.values(feature.properties), "catchment_area"); - } - }); - - map.addLayer(self.catchmentAreaLayer); - self.layersControl.addOverlay(self.catchmentAreaLayer, "Catchment Areas"); + var markers = {}; _.each(self.amenities, function(amenity, i) { self.amenityLayers[amenity] = L.geoJson(data, { @@ -148,15 +120,47 @@ $(document).ready(function() { center = feature.geometry.coordinates[0]; } - layer.bindPopup(self.popupTemplate({ properties: feature.properties, coordinate: center })); + layer.bindPopup(self.hospitalTemplate({ properties: feature.properties, 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)); }); + + // 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) { + var marker_layer = markers[feature.properties.subject]; + var popup = markers[feature.properties.subject].openPopup; + layer.on({ + mouseover: highlightFeature, + mouseout: resetHighlight, + click: function() { + markers[feature.properties.subject].openPopup(); + } + }); + }, + filter: function(feature, layer) { + return _.contains(_.values(feature.properties), "catchment_area"); + } + }); + + map.addLayer(self.catchmentAreaLayer); + self.layersControl.addOverlay(self.catchmentAreaLayer, "Catchment Areas"); } else { self.catchmentAreaLayer.clearLayers(); self.catchmentAreaLayer.addData(data); @@ -190,10 +194,6 @@ $(document).ready(function() { self.catchmentAreaLayer.resetStyle(e.target); } - function zoomToFeature(e) { - map.fitBounds(e.target.getBounds()); - } - function onLocationFound(e) { self.currentLocation = e.latlng; var radius = e.accuracy / 2; @@ -205,6 +205,18 @@ $(document).ready(function() { alert(e.message); } + function polygonArea(X, Y, numPoints) + { + area = 0; // Accumulates area in the loop + j = numPoints-1; // The last vertex is the 'previous' one to the first + + for (i=0; i