diff options
Diffstat (limited to 'resources/map.js')
-rw-r--r-- | resources/map.js | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/resources/map.js b/resources/map.js index 8a006bc..8a7bac4 100644 --- a/resources/map.js +++ b/resources/map.js @@ -184,7 +184,7 @@ function initMap(self) { } }); - map.addLayer(self.populationHeatMap); + //map.addLayer(self.populationHeatMap); self.layersControl.addOverlay(self.populationHeatMap, "Population Heat Map"); var emptyFeatureCollection = { type: "FeatureCollection", features: [] }; @@ -253,7 +253,9 @@ function initMap(self) { layer.options.icon = hospitalIcon; center = feature.geometry.coordinates; } else { - center = feature.geometry.coordinates[0]; + var format = new OpenLayers.Format.GeoJSON; + var geom = format.parseGeometry(feature.geometry); + center = geom.getCentroid(); } var catchmentArea = self.catchmentAreas[feature.id]; @@ -332,8 +334,6 @@ function displayMap(self, map) { var ne = bounds.getNorthEast(); bbox = [sw.lat, sw.lng, ne.lat, ne.lng].join(','); - self.converter = new op2geojson(); - function addSettlementsForArea(catchmentArea) { // Create the bounding polygon for the query var poly = ""; @@ -357,11 +357,10 @@ function displayMap(self, map) { } else { self.catchmentAreaSettlementsLayers[catchmentArea.id] = L.geoJson(data, { style: function(feature) { - return {fillColor: 'green', - weight: 2, + return {fillColor: 'grey', + weight: 1, opacity: 1, color: 'black', - dashArray: '3', fillOpacity: 0.1}; }, onEachFeature: function(feature, layer) { @@ -369,7 +368,9 @@ function displayMap(self, map) { if (feature.geometry.type === "Point") { center = feature.geometry.coordinates; } else { - center = feature.geometry.coordinates[0]; + var format = new OpenLayers.Format.GeoJSON; + var geom = format.parseGeometry(feature.geometry); + center = geom.getCentroid(); } var displayProperties = { name: feature.properties["name"], population: feature.properties["population"] }; @@ -391,21 +392,28 @@ function displayMap(self, map) { var healthPost = self.healthPosts[catchmentArea.properties.subject]; - var center; - if (healthPost.geometry.type === "Point") { - center = healthPost.geometry.coordinates; + if (_.isUndefined(healthPost)) { + console.log("No health post found for catchment area"); } else { - center = healthPost.geometry.coordinates[0]; - } + var center; + if (healthPost.geometry.type === "Point") { + center = healthPost.geometry.coordinates; + } else { + var format = new OpenLayers.Format.GeoJSON; + var geom = format.parseGeometry(healthPost.geometry); + center = geom.getCentroid(); + } + + self.markers[catchmentArea.properties.subject].bindPopup(self.editorTemplate({coordinate: center}) + + self.healthPostTemplate(healthPost.properties) + + self.catchmentAreaTemplate(catchmentAreaProperties(catchmentArea, healthPost))); - self.markers[catchmentArea.properties.subject].bindPopup(self.editorTemplate({coordinate: center}) + - self.healthPostTemplate(healthPost.properties) + - self.catchmentAreaTemplate(catchmentAreaProperties(catchmentArea, healthPost))); + } } } // Fetch settlement data - self.converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, + self.converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, map.getCenter().lat, (function(catchmentArea) { return function (data) { processSettlements(data, catchmentArea); }; })(catchmentArea)); } @@ -417,7 +425,7 @@ function displayMap(self, map) { self.populationHeatMapData = []; // Convert the data to GeoJSON - self.converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, function(data) { + self.converter.fetch("http://overpass-api.de/api/interpreter", query, zoom, map.getCenter().lat, function(data) { self.catchmentAreaLayer.clearLayers(); var oldCatchmentAreas = self.catchmentAreas; @@ -514,12 +522,12 @@ $(document).ready(function() { } function onLocationError(e) { - alert(e.message); + //alert(e.message); } map.on('locationfound', onLocationFound); map.on('locationerror', onLocationError); map.locate({setView: true, maxZoom: 12}); - displayMap(self, map); + //displayMap(self, map); }); |