-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
100 lines (79 loc) · 3.02 KB
/
index.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<style>
html,
body {
height: 100%;
margin: 0;
}
#mapid {
min-height: 100%;
}
</style>
</head>
<body>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid');
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1,
accessToken: 'pk.eyJ1IjoibTByY2gzbCIsImEiOiJjazR5a21kODkwMWZzM2ZxdW9neTlyNWF2In0.meiHG49gkd3-86AkMrP0qg'
}).addTo(mymap);
const markerHtmlStyles = `
width: 1rem;
height: 1rem;
display: block;
left: -0.5rem;
top: 0rem;
position: relative;
border-radius: 1rem 1rem 0;
transform: rotate(45deg);
border: 1px solid #FFFFFF`
async function parseWaypoints() {
if (window.DOMParser) {
parser = new DOMParser();
response = await fetch('./waypoints.gpx');
if (response.ok) {
xmlDoc = parser.parseFromString(await response.text(), "text/xml");
const waypoints = xmlDoc.getElementsByTagName('wpt');
const wps = Array.from(waypoints);
const colorStep = 255 / wps.length;
let mapCenter = [];
wps.forEach((wpt, idx) => {
//const myCustomColour = Math.floor((idx + 1) * colorStep).toString(16);
const color = 255 - Math.round((idx + 1) * colorStep);
const icon = L.divIcon({
className: "my-custom-pin",
iconAnchor: [0, 24],
labelAnchor: [-6, 0],
popupAnchor: [0, -36],
html: `<span style="background-color: rgb(${color},${color},${color}); ${markerHtmlStyles}" />`
})
let m = L.marker([wpt.attributes.lat.value, wpt.attributes.lon.value], { icon: icon }).addTo(mymap);
let pop = m.bindPopup(`<h3>${Array.from(wpt.childNodes).filter(item => item.nodeName == 'name')[0].innerHTML}</h3>`);
//TODO opening the latest popup isn't working yet
if (idx == waypoints.lenght - 1) {
pop.openPopup();
}
//remember the last waypoint coordinates
mapCenter = [wpt.attributes.lat.value, wpt.attributes.lon.value];
});
//set the map center to to latest waypoint
mymap.setView(mapCenter, 8);
}
}
}
parseWaypoints();
</script>
</body>
</html>