aboutsummaryrefslogtreecommitdiff
path: root/resources/op2geojson.js
diff options
context:
space:
mode:
authorKatie Filbert <filbertk@gmail.com>2012-12-01 17:53:34 +0100
committerKatie Filbert <filbertk@gmail.com>2012-12-01 17:53:34 +0100
commit34026213a1d6aa2377b16aaa503fc12077980ce1 (patch)
treef93153b9472e60f628eca9d5dccefd7fa080cf2c /resources/op2geojson.js
parent0a94d892169f26c17326b7840e420530b4bb9176 (diff)
downloadhealth-map-34026213a1d6aa2377b16aaa503fc12077980ce1.tar
health-map-34026213a1d6aa2377b16aaa503fc12077980ce1.tar.gz
hospital layer has hospitals
Diffstat (limited to 'resources/op2geojson.js')
-rw-r--r--resources/op2geojson.js32
1 files changed, 18 insertions, 14 deletions
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;