diff options
author | Willi <willi@jups42.de> | 2012-12-01 16:10:26 +0100 |
---|---|---|
committer | Willi <willi@jups42.de> | 2012-12-01 16:10:26 +0100 |
commit | 41b0fe477b6533acf605f4ba35604a81dc2c5ae3 (patch) | |
tree | 8e56d79d5bd639383d3ee8abba061f94d3d97a81 | |
parent | efa746ba7b2e57cf3696e82355059f02d7b051c0 (diff) | |
download | health-map-41b0fe477b6533acf605f4ba35604a81dc2c5ae3.tar health-map-41b0fe477b6533acf605f4ba35604a81dc2c5ae3.tar.gz |
store location, stopped double rendering
-rw-r--r-- | resources/map.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/resources/map.js b/resources/map.js index 2ebf40c..9c466ae 100644 --- a/resources/map.js +++ b/resources/map.js @@ -2,17 +2,17 @@ $(document).ready(function() { var self = this; fetchLayers(); - debugger; var map = L.map( 'map', { layers: [self.tileLayer, self.hospitalLayer] }); + // $('body').bind('hospitalsfetched', renderHospitalIcon); map.on('locationfound', onLocationFound); map.on('locationerror', onLocationError); map.locate({setView: true, maxZoom: 16}); - initLayerControl(); + 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;"); @@ -22,31 +22,31 @@ $(document).ready(function() { }); } - function initLayerControl(map) { + function initLayerControl() { L.control.layers(null, { "Hospitals" : self.hospitalLayer }).addTo(map); } function onLocationFound(e) { + self.currentLocation = e.latlng; var radius = e.accuracy / 2; L.marker(e.latlng).addTo(map) .bindPopup("You are within " + radius + " meters from this point").openPopup(); + $('body').trigger('hospitalsfetched'); } function onLocationError(e) { alert(e.message); } - function initHospitalIcon() { + function renderHospitalIcon() { var hospitalIcon = L.icon({ iconUrl: 'img/hospital.png' }); - L.marker([], {icon: hospitalIcon}).addTo(map); + if (self.currentLocation) { + debugger; + L.marker([self.location.lat, self.location.lng], {icon: hospitalIcon}).addTo(map); + } } - - initialize(); - fetchLayers(); - initLayerControl(); - }); |