aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilli <willi@jups42.de>2012-12-01 21:28:48 +0100
committerWilli <willi@jups42.de>2012-12-01 21:28:48 +0100
commite1754a438b5ff288805d878683fba9526e061791 (patch)
treeae4a6b0b9e2578fb55cd7c777e9d7d57ca95b87c
parent48e03c07eff6ac5d19bbddfd53ebbc36738bd824 (diff)
downloadhealth-map-e1754a438b5ff288805d878683fba9526e061791.tar
health-map-e1754a438b5ff288805d878683fba9526e061791.tar.gz
removed duplication n API calling code as best as I could :-)
-rw-r--r--resources/map.js27
1 files changed, 12 insertions, 15 deletions
diff --git a/resources/map.js b/resources/map.js
index 1ecfe0a..9a07f3a 100644
--- a/resources/map.js
+++ b/resources/map.js
@@ -2,7 +2,7 @@ $(document).ready(function() {
var self = this;
- self.template = _.template('<dl> <% _.each(properties, function(val, key) { %> \
+ self.popupTemplate = _.template('<dl> <% _.each(properties, function(val, key) { %> \
<% if (/\:/.exec(key)) { %> \
<dl> \
<dt><%= key.split(":")[1] %> </dt> \
@@ -15,6 +15,7 @@ $(document).ready(function() {
<% }); %> \
</dl>');
+
fetchLayers();
var map = L.map( 'map', {
zoom: 12,
@@ -47,30 +48,26 @@ $(document).ready(function() {
var url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](" + bbox + ");out;";
converter = new op2geojson();
converter.fetch(url, function(data) {
- console.log(data);
- layer = L.geoJson(data, {
- onEachFeature: function(feature, layer) {
- debugger;
- layer.bindPopup(self.template({ properties: feature.properties }));
- }
- });
+ layer = buildLayer(data)
self.hospitalLayer.addData(data);
});
-
-
})
map.locate({setView: true, maxZoom: 12});
+ function buildLayer(data) {
+ return L.geoJson(data, {
+ onEachFeature: function(feature, layer) {
+ layer.bindPopup(self.popupTemplate({ properties: feature.properties }));
+ }
+ });
+ }
+
function geojsonLayer() {
url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;";
converter = new op2geojson();
converter.fetch(url, function(data) {
- layer = L.geoJson(data, {
- onEachFeature: function(feature, layer) {
- layer.bindPopup(self.template({ properties: feature.properties }));
- }
- });
+ layer = buildLayer(data);
self.hospitalLayer = layer;
map.fireEvent('hospitalsfetched');
});