diff options
Diffstat (limited to 'resources/map.js')
-rw-r--r-- | resources/map.js | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/resources/map.js b/resources/map.js index 47cac86..2ebf40c 100644 --- a/resources/map.js +++ b/resources/map.js @@ -1,11 +1,32 @@ $(document).ready(function() { + var self = this; - var tileLayer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { - maxZoom: 18, - attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' + fetchLayers(); + debugger; + var map = L.map( 'map', { + layers: [self.tileLayer, self.hospitalLayer] }); - var hospitalLayer = L.tileLayer("http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;"); + map.on('locationfound', onLocationFound); + map.on('locationerror', onLocationError); + + map.locate({setView: true, maxZoom: 16}); + initLayerControl(); + + + function fetchLayers() { + self.hospitalLayer = L.tileLayer("http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;"); + self.tileLayer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + maxZoom: 18, + attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' + }); + } + + function initLayerControl(map) { + L.control.layers(null, { + "Hospitals" : self.hospitalLayer + }).addTo(map); + } function onLocationFound(e) { var radius = e.accuracy / 2; @@ -17,15 +38,15 @@ $(document).ready(function() { alert(e.message); } - var map = L.map( 'map', { - layers: [tileLayer, hospitalLayer] - }); + function initHospitalIcon() { + var hospitalIcon = L.icon({ + iconUrl: 'img/hospital.png' + }); + L.marker([], {icon: hospitalIcon}).addTo(map); + } - map.on('locationfound', onLocationFound); - map.on('locationerror', onLocationError); + initialize(); + fetchLayers(); + initLayerControl(); - map.locate({setView: true, maxZoom: 16}); - L.control.layers(null, { - "Hospitals" : hospitalLayer - }).addTo(map); }); |