blob: 20b5a84a0e1b70e5ccbb2c7ba248204df19002ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
$(document).ready(function() {
var self = this;
fetchLayers();
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});
function geojsonLayer() {
converter = new op2geojson();
data = converter.geojson();
return L.geoJson(data);
}
function fetchLayers() {
self.hospitalLayer = geojsonLayer();
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() {
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 renderHospitalIcon() {
var hospitalIcon = L.icon({
iconUrl: 'img/hospital.png'
});
if (self.currentLocation) {
debugger;
L.marker([self.location.lat, self.location.lng], {icon: hospitalIcon}).addTo(map);
}
}
});
|