aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilli <willi@jups42.de>2012-12-02 14:16:06 +0100
committerWilli <willi@jups42.de>2012-12-02 14:16:06 +0100
commit0e600790a155d31ee809e8b60c693d44acbae19a (patch)
treecc7cfb93ef452877406edfc56153ca5686f8183e
parent4f424e6c73b6b44639a333dcd14851397ddd5712 (diff)
parenta673734084a8decd4c9c007587847a6b167301c7 (diff)
downloadhealth-map-0e600790a155d31ee809e8b60c693d44acbae19a.tar
health-map-0e600790a155d31ee809e8b60c693d44acbae19a.tar.gz
Merge branch 'master' of github.com:filbertkm/hospital-map
-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 cebadc7..e488a03 100644
--- a/resources/map.js
+++ b/resources/map.js
@@ -53,6 +53,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);
@@ -68,7 +74,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;
@@ -108,7 +114,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",