From 6b7970033fa69f37b748f653642d996db17e7d91 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 3 Feb 2013 12:42:53 +0000 Subject: Now show population data --- resources/map.js | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/resources/map.js b/resources/map.js index 9477114..01c902b 100644 --- a/resources/map.js +++ b/resources/map.js @@ -93,8 +93,7 @@ function displayMap(self, map) { } var catchmentArea = self.catchmentAreas[feature.id]; - var populationAreas = catchmentArea.populationAreas; - console.log(populationAreas); + var settlements = catchmentArea.settlements; var format = new OpenLayers.Format.GeoJSON; var openLayersGeo = format.parseGeometry(catchmentArea.geometry); @@ -106,19 +105,38 @@ function displayMap(self, map) { } var areaProperties; - if (typeof populationAreas == "undefined") { + if (typeof settlements == "undefined") { areaProperties = { area: areaString, - number_of_villages: "Unknown", + number_of_settlements: "Unknown", population: "Unknown", - greatest_village_dist: "Unknown", - average_village_dist: "Unknown" + greatest_settlement_dist: "Unknown", + average_settlement_dist: "Unknown" } } else { + var population = 0; + var numberOfSettlementsWithoutPopulation = 0; + + _.each(settlements, function(settlement) { + if (typeof settlement.properties.population != "undefined") { + console.log(settlement.properties.population); + population += parseInt(settlement.properties.population); + } else { + numberOfSettlementsWithoutPopulation++; + }}); + + if (numberOfSettlementsWithoutPopulation != 0) { + if (numberOfSettlementsWithoutPopulation == 1) { + population = population + " (but " + numberOfSettlementsWithoutPopulation + " has no population set)"; + } else { + population = population + " (but " + numberOfSettlementsWithoutPopulation + " have no population set)"; + } + } + areaProperties = { area: areaString, - number_of_villages: populationAreas.length, - population: "Unknown", - greatest_village_dist: "Unknown", - average_village_dist: "Unknown" + number_of_settlements: settlements.length, + population: population, + greatest_settlement_dist: "Unknown", + average_settlement_dist: "Unknown" } } @@ -149,7 +167,7 @@ function displayMap(self, map) { return _.contains(_.keys(feature.properties), "place") || feature.properties["landuse"] == "residential"; }); - catchmentArea.populationAreas = data.features; + catchmentArea.settlements = data.features; if (typeof self.villageLayers[catchmentArea.id] == 'undefined') { self.villageLayers[catchmentArea.id] = L.geoJson(data, { @@ -239,10 +257,10 @@ $(document).ready(function() {

Catchment Area

\ \ \ -\ +\ \ -\ -\ +\ +\
Surface Area<%= properties["area"] %>
Number of villages<%= properties["number_of_villages"] %>
Number of Settlements<%= properties["number_of_settlements"] %>
Population<%= properties["population"] %>
Furthest Village from health structure<%= properties["greatest_village_dist"] %>
Average distance of all villages from health structure<%= properties["average_village_dist"] %>
Furthest distance from settlement to health structure<%= properties["greatest_settlement_dist"] %>
Average distance of all settlements from health structure<%= properties["average_settlement_dist"] %>
'); self.tileLayer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { -- cgit v1.2.3