aboutsummaryrefslogtreecommitdiff
path: root/resources/map.js
blob: 2ebf40c4314d9a7431fc7e27656d78b2bf9fe529 (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
$(document).ready(function() {
	var self = this;

	fetchLayers();
	debugger;
	var map = L.map( 'map', {
		layers: [self.tileLayer, self.hospitalLayer]
	});

	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 &copy; <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;
		L.marker(e.latlng).addTo(map)
		.bindPopup("You are within " + radius + " meters from this point").openPopup();
	}

	function onLocationError(e) {
		alert(e.message);
	}

	function initHospitalIcon() {
		var hospitalIcon = L.icon({
			iconUrl: 'img/hospital.png'
		});
		L.marker([], {icon: hospitalIcon}).addTo(map);
	}

	initialize();
	fetchLayers();
	initLayerControl();

});