From facf5fb7a60be0364595a2a3813c553ee985a68e Mon Sep 17 00:00:00 2001 From: Katie Filbert Date: Sat, 1 Dec 2012 17:49:56 +0100 Subject: hospitals in the layer --- resources/map.js | 19 +++++++++++-------- resources/op2geojson.js | 32 ++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/resources/map.js b/resources/map.js index e5c9b06..e6878ca 100644 --- a/resources/map.js +++ b/resources/map.js @@ -16,15 +16,18 @@ $(document).ready(function() { initLayerControl(); 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(); - data = converter.geojson(); - var style = { - "color": "#ff7800", - "weight" : 5, - "opacity" : 0.65 - }; - layer = L.geoJson(data, style); - return layer; + converter.fetch(url, function(data) { + console.log(data); + var style = { + "color": "#ff7800", + "weight" : 5, + "opacity" : 0.65 + }; + layer = L.geoJson(data, style); + return layer; + }); } function fetchLayers() { diff --git a/resources/op2geojson.js b/resources/op2geojson.js index 8850fa9..1285fc1 100644 --- a/resources/op2geojson.js +++ b/resources/op2geojson.js @@ -5,42 +5,46 @@ op2geojson = function() { var instance = {}, geojson; - instance.fetch = function(url) { - $.getJSON("http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;", { - format: "json" - }, + instance.fetch = function(url, callback) { + $.getJSON(url, { format: "json" }, function(data) { - $.each(data, function(i, item) { - console.log(item); + var features = []; + $.each(data.elements, function(i, item) { + if( item.type === 'node' ) { + features.push( instance.point(item) ); + } }); + geojson = instance.featureCollection(features); + callback(geojson); } ); }; - instance.feature = function() { + instance.point = function(node) { point = { + "type" : "Feature", "geometry" : { "type" : "Point", - "coordinates" : [13.3172386,52.480732] + "coordinates" : [node.lon,node.lat] }, - "type" : "Feature", "properties" : { "name" : "Sankt Gertrauden-Krankenhaus" }, }; return point; } - instance.featureCollection = function() { + instance.featureCollection = function(features) { collection = { "type" : "FeatureCollection", - "features" : [ - instance.feature(), - ] + "features" : features }; return collection; } instance.geojson = function() { - return instance.featureCollection(); + url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;"; + instance.fetch(url, function(data) { + return data; + }); } return instance; -- cgit v1.2.3