-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
67 lines (57 loc) · 2.06 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<title>Display routes on map</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<link rel="stylesheet" type="text/css" href="map.css">
</head>
<body>
<div class="box">
<div class="row header">
<label for="gpx">Select one or multiple gpx file(s):</label>
<input type="file"
id="gpx" name="gpx"
accept=".gpx"
multiple = true
onchange = "loadGpx()">
</div>
<div id="map" class="row content"></div></div>
<div class="row footer">
</div>
</div>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script>
const input = document.querySelector('input')
function loadGpx() {
for(const file of input.files) {
let reader = new FileReader()
console.log(file.name)
reader.readAsText(file)
reader.onload = function() {
let parser = new DOMParser()
let xmlDoc = parser.parseFromString(reader.result,"text/xml")
let points = xmlDoc.getElementsByTagName("trkpt")
let latlngs = [];
for(const point of points) {
latlngs.push([Number(point.attributes.lat.value),Number(point.attributes.lon.value)])
}
let polyline = L.polyline(latlngs, {color: 'red'})
console.log(polyline)
polyline.addTo(map)
}
}
}
// Creating map options
const mapOptions = {
center: [51.2469, -0.3574],
zoom: 10
}
// Creating a map object
const map = new L.map('map', mapOptions);
// Creating a Layer object
const layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
// Adding layer to the map
map.addLayer(layer)
</script>
</body>
</html>