aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatie Filbert <filbertk@gmail.com>2012-12-01 17:49:56 +0100
committerKatie Filbert <filbertk@gmail.com>2012-12-01 17:49:56 +0100
commitfacf5fb7a60be0364595a2a3813c553ee985a68e (patch)
treea2a3785962b01f9569c4028d1d35b628463b3c74
parent856bdb5466050a810214296775070b6466404431 (diff)
downloadhealth-map-facf5fb7a60be0364595a2a3813c553ee985a68e.tar
health-map-facf5fb7a60be0364595a2a3813c553ee985a68e.tar.gz
hospitals in the layer
-rw-r--r--resources/map.js19
-rw-r--r--resources/op2geojson.js32
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;