diff options
author | Willi <willi@jups42.de> | 2012-12-01 18:22:54 +0100 |
---|---|---|
committer | Willi <willi@jups42.de> | 2012-12-01 18:22:54 +0100 |
commit | 07c0da8495319b0d4efb24b2565123b559a19d17 (patch) | |
tree | eccb24bf383d76c38f96be0b19258ab1db71bdde /resources | |
parent | a06e32fc80ddb69a9c2c9be9e27677b98fc604cd (diff) | |
parent | 3fef504fd23b6ac69fde72f242b50a33114c93f5 (diff) | |
download | health-map-07c0da8495319b0d4efb24b2565123b559a19d17.tar health-map-07c0da8495319b0d4efb24b2565123b559a19d17.tar.gz |
manually merged
Diffstat (limited to 'resources')
-rw-r--r-- | resources/map.js | 43 | ||||
-rw-r--r-- | resources/op2geojson.js | 32 |
2 files changed, 45 insertions, 30 deletions
diff --git a/resources/map.js b/resources/map.js index c206327..2896fad 100644 --- a/resources/map.js +++ b/resources/map.js @@ -5,40 +5,51 @@ $(document).ready(function() { fetchLayers(); var map = L.map( 'map', { zoom: 12, - layers: [self.tileLayer, self.hospitalLayer] + layers: [self.tileLayer] }); + function addHospitalLayer(){ + L.control.layers(null, { + "Hospitals" : self.hospitalLayer + }).addTo(map); + } + + $('body').bind('hospitalsfetched', addHospitalLayer); map.on('locationfound', onLocationFound); map.on('locationerror', onLocationError); map.locate({setView: true, maxZoom: 12}); - initLayerControl(); function geojsonLayer() { - var converter = new op2geojson(); - var data = converter.geojson(); - var layer = L.geoJson(data, { - onEachFeature: function(feature, layer) { - layer.bindPopup(feature.properties.name); - } + 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(); + converter.fetch(url, function(data) { + var style = { + "color": "red", + "weight" : 50, + "opacity" : 0.65 + }; + layer = L.geoJson(data, { + style: function(feature) { + return style; + }, + onEachFeature: function(feature, layer) { + layer.bindPopup(feature.properties.name); + } + }); + self.hospitalLayer = layer; + $('body').trigger('hospitalsfetched'); }); - return layer; } function fetchLayers() { - self.hospitalLayer = geojsonLayer(); + geojsonLayer(); self.tileLayer = L.tileLayer('http://{s}.www.toolserver.org/tiles/osm-no-labels/{z}/{x}/{y}.png', { maxZoom: 18, attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' }); } - function initLayerControl() { - L.control.layers(null, { - "Hospitals" : self.hospitalLayer - }).addTo(map); - } - function onLocationFound(e) { self.currentLocation = e.latlng; var radius = e.accuracy / 2; 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; |