aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/assets/map.html
blob: 5e93702706ce4f8b4a330009c4fd86abdf8b1ba2 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<link href="font-awesome.min.css" rel="stylesheet">
		<link href="animate.min.css" rel="stylesheet">

		<script src="jquery.min.js"></script>
		<link rel="stylesheet" href="leaflet.css"/>
		<script src="leaflet.js"></script>
	</head>

	<body>
		<style>
			#map{width:100%;height:100%;position:fixed;top:0px;left:0px;right:0px;bottom:0px}
		</style>

		<div id='map'></div>

		<script type="text/javascript">
			var marker;

			//get location from URL
			var getUrlParameter = function getUrlParameter(sParam) {
				var sPageURL = decodeURIComponent(window.location.search.substring(1)),
				sURLVariables = sPageURL.split('&'),
				sParameterName,
				i;

				for (i = 0; i < sURLVariables.length; i++) {
					sParameterName = sURLVariables[i].split('=');
					if (sParameterName[0] === sParam) {
						return sParameterName[1] === undefined ? true : sParameterName[1];
					}
				}
			};

			// create map
			if (getUrlParameter('lat') != null && getUrlParameter('lon') != null) {
				var map = L.map('map', {
					zoomControl: true,
					attributionControl: true
				}).setView([getUrlParameter('lat'), getUrlParameter('lon')], 15);

				// add marker
				if (!marker) {
					marker = L.marker([getUrlParameter('lat'), getUrlParameter('lon')]).addTo(map);
					marker.bindPopup((getUrlParameter('name')), {
						closeOnClick: false,
						closeButton: false,
						autoClose: false
					}).openPopup();
				}
			} else {
				var map = L.map('map', {
					zoomControl: true,
					attributionControl: true
				}).fitWorld();
			}

			map.addLayer(new L.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
				minZoom: 1,
				maxZoom: 19
			}));

			// Change view to coordinates
			function toCoordinates(latIntent, lonIntent, Name){
				map.setView([parseFloat(latIntent), parseFloat(lonIntent)], 15);
				if (!marker) {
					marker = L.marker([parseFloat(latIntent), parseFloat(lonIntent)]).addTo(map);
					marker.bindPopup(("..."), {
						closeOnClick: false,
						closeButton: false,
						autoClose: false
					}).openPopup();
				}
				marker.setLatLng([parseFloat(latIntent), parseFloat(lonIntent)]).update();
				marker.setPopupContent(Name);
			}
		</script>
	</body>
</html>