aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilli Müller <willi.mueller@jups42.de>2012-12-02 05:14:01 -0800
committerWilli Müller <willi.mueller@jups42.de>2012-12-02 05:14:01 -0800
commita673734084a8decd4c9c007587847a6b167301c7 (patch)
tree7e91db8de3962ddb17cac6884502edc011210bd1
parentaebdba9aeb439074c7ad555a3d16f7047fe44a91 (diff)
parent06d385b749663fd389d862eaec42b6d33dd65e43 (diff)
downloadhealth-map-a673734084a8decd4c9c007587847a6b167301c7.tar
health-map-a673734084a8decd4c9c007587847a6b167301c7.tar.gz
Merge pull request #2 from Fodaro/master
From Harry Cutts
-rw-r--r--resources/map.js10
-rw-r--r--resources/op2geojson.js36
2 files changed, 43 insertions, 3 deletions
diff --git a/resources/map.js b/resources/map.js
index 592eae1..0c43591 100644
--- a/resources/map.js
+++ b/resources/map.js
@@ -51,6 +51,12 @@ $(document).ready(function() {
$('.leaflet-control-layers-selector').first().trigger('click')
}
+ function createQueryURL(bbox) {
+ return "http://overpass-api.de/api/interpreter?" +
+ "data=[out:json];(node[amenity=hospital](" + bbox +
+ ");way[amenity=hospital]("+ bbox +");node(w););out;";
+ }
+
map.on('hospitalsfetched', addHospitalLayer);
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
@@ -66,7 +72,7 @@ $(document).ready(function() {
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
bbox = [sw.lat, sw.lng, ne.lat, ne.lng].join(',');
- var url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](" + bbox + ");out;";
+ var url = createQueryURL(bbox);
converter = new op2geojson();
converter.fetch(url, function(data) {
self.hospitals = data;
@@ -106,7 +112,7 @@ $(document).ready(function() {
}
function geojsonLayer() {
- url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;";
+ url = createQueryURL(52.34,13.3,52.52,13.6);
converter = new op2geojson();
converter.fetch(url, function(data) {
self.hospitals = data;
diff --git a/resources/op2geojson.js b/resources/op2geojson.js
index 74431d3..55be9e3 100644
--- a/resources/op2geojson.js
+++ b/resources/op2geojson.js
@@ -8,10 +8,21 @@ op2geojson = function() {
instance.fetch = function(url, callback) {
$.getJSON(url, { format: "json" },
function(data) {
+ // List all of the returned nodes
+ var nodes = [];
+ $.each(data.elements, function(i, item) {
+ if (item.type === 'node') {
+ nodes[item.id] = item;
+ }
+ });
+
+ // Add nodes and ways to the layer
var features = [];
$.each(data.elements, function(i, item) {
- if( item.type === 'node' ) {
+ if( item.type === 'node' && item.tags != null ) {
features.push( instance.point(item) );
+ } else if (item.type === 'way') {
+ features.push( instance.lineString(item, nodes) );
}
});
geojson = instance.featureCollection(features);
@@ -33,6 +44,29 @@ op2geojson = function() {
return point;
}
+ instance.lineString = function(way, nodeArray) {
+ // Get the node coordinates from nodeArray
+ var coordinates = [];
+ for (id in way.nodes) {
+ var node = nodeArray[way.nodes[id]];
+ coordinates.push([node.lon,node.lat]);
+ }
+
+ // Create the LineString
+ var lineString = {
+ "type" : "Feature",
+ "geometry" : {
+ "type" : "LineString",
+ "coordinates" : coordinates
+ },
+ "properties" : {}
+ };
+
+ // Add the tags
+ _.extend(lineString.properties, way.tags);
+ return lineString;
+ }
+
instance.featureCollection = function(features) {
collection = {
"type" : "FeatureCollection",