diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/map.js | 82 | ||||
m--------- | resources/openlayers | 0 |
2 files changed, 53 insertions, 29 deletions
diff --git a/resources/map.js b/resources/map.js index 2dbf8e4..a503d66 100644 --- a/resources/map.js +++ b/resources/map.js @@ -7,13 +7,13 @@ $(document).ready(function() { <a href="http://www.openstreetmap.org/edit?editor=remote&lat=<%= coordinate[1] %>&lon=<%= coordinate[0] %>&zoom=18">\ <img src="resources/img/josm.png"></a>\ <h2>Hospital</h2>\ -<table>\ -<tr><td>Name</td><td><%= properties["name"] %></td></tr>\ -<tr><td>Emergency</td><td><%= properties["emergency"] %></td></tr>\ +<table width="100%">\ +<tr><td>Name</td><td align="right"><%= properties["name"] %></td></tr>\ +<tr><td>Emergency</td><td align="right"><%= properties["emergency"] %></td></tr>\ </table>\ <h2>Catchment Area</h2>\ <table>\ -<tr><td>Surface Area</td><td></td></tr>\ +<tr><td>Surface Area</td><td><%= properties["area"] %></td></tr>\ <tr><td>Number of villages</td><td></td></tr>\ <tr><td>Population</td><td></td></tr>\ <tr><td>Furthest Village from health structure</td><td></td></tr>\ @@ -84,6 +84,42 @@ $(document).ready(function() { 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; + }); + + console.log(catchmentAreaForAmenity); + + // 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, { @@ -102,7 +138,19 @@ $(document).ready(function() { center = feature.geometry.coordinates[0]; } - layer.bindPopup(self.popupTemplate({ properties: feature.properties, coordinate: center })); + 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; }, @@ -116,30 +164,6 @@ $(document).ready(function() { 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) { - 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 { diff --git a/resources/openlayers b/resources/openlayers new file mode 160000 +Subproject 47e7c300a81011257d4e34739ce14f02f71c5d0 |