From af54d6f83f8d51f5528c53056ff41bbeaabf319d Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 15 Feb 2013 10:47:34 +0000 Subject: Fix a bug with missing tags --- resources/map.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/map.js b/resources/map.js index 1298c73..17cf48d 100644 --- a/resources/map.js +++ b/resources/map.js @@ -122,6 +122,18 @@ function catchmentAreaProperties(catchmentArea, healthPost) { return areaProperties; } +function fillObjectWithUnknowns(object, expectedProperties) { + var newObject = {}; + _.each(expectedProperties, function(property) { + if (_.isUndefined(object[property])) { + newObject[property] = "Unknown"; + } else { + newObject[property] = object[property]; + } + }); + return newObject; +} + function initMap(self) { var tileUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; var tileAttribution = 'Map data © OpenStreetMap contributors'; @@ -231,8 +243,10 @@ function initMap(self) { var catchmentArea = self.catchmentAreas[feature.id]; + var healthPostProperties = fillObjectWithUnknowns(feature.properties, ["name", "emergency"]); + layer.bindPopup(self.editorTemplate({coordinate: center}) + - self.healthPostTemplate(feature.properties) + + self.healthPostTemplate(healthPostProperties) + self.catchmentAreaTemplate(catchmentAreaProperties(catchmentArea, feature))); self.markers[feature.id] = layer; -- cgit v1.2.3