From c0fdf6bf27ed17cdfd46f96aeebd4668409d7574 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 9 Feb 2013 23:57:54 +0000 Subject: Add scale bar, and fix distances --- resources/map.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/map.js b/resources/map.js index 1e962af..347d86e 100644 --- a/resources/map.js +++ b/resources/map.js @@ -70,7 +70,9 @@ function catchmentAreaProperties(catchmentArea, healthPost) { _.each(catchmentArea.settlements, function (settlement) { var settlementGeo = format.parseGeometry(settlement.geometry); - var distance = settlementGeo.distanceTo(healthPostPoint); + var line = new OpenLayers.Geometry.LineString([healthPostPoint, settlementGeo]); + var distance = line.getGeodesicLength(Geographic); + //var distance = settlementGeo.distanceTo(healthPostPoint); sumOfDistances += distance; if (distance > maxDistance) maxDistance = distance; @@ -140,6 +142,8 @@ function initMap(self) { var miniMapTileLayer = new L.TileLayer(tileUrl, {minZoom: 0, maxZoom: 13, attribution: tileAttribution }); var miniMap = new L.Control.MiniMap(miniMapTileLayer, { toggleDisplay: true }).addTo(map); + L.control.scale().addTo(map); + self.amenitiesShown = ["hospital"]; self.amenities = {}; self.amenityLayers = {}; // contains the layers for each amenity type @@ -262,6 +266,14 @@ function initMap(self) { return map; } +function formatDistance(distance) { + if (distance > 1000) { + return (distance/1000).toFixed(2) + "km"; + } else { + return distance.toFixed(0) + "m"; + } +} + function displayMap(self, map) { function createQueryData(bbox) { @@ -435,8 +447,8 @@ $(document).ready(function() { Surface Area<%= area %>\ Number of Settlements<%= number_of_settlements %>\ Population<%= population %>\ -Furthest distance from settlement to health structure<%= greatest_settlement_dist %>\ -Average distance of all settlements from health structure<%= average_settlement_dist %>\ +Furthest distance from settlement to health structure<%= formatDistance(greatest_settlement_dist) %>\ +Average distance of all settlements from health structure<%= formatDistance(average_settlement_dist) %>\ '); self.settlementTemplate = _.template('

Settlement

\ -- cgit v1.2.3