GoBlog/templates/assets/js/geotrack.js

26 lines
817 B
JavaScript
Raw Normal View History

2021-11-10 10:13:30 +00:00
(function () {
let mapEl = document.getElementById('map')
let paths = (mapEl.dataset.paths == "") ? [] : JSON.parse(mapEl.dataset.paths)
let points = (mapEl.dataset.points == "") ? [] : JSON.parse(mapEl.dataset.points)
2021-11-10 10:13:30 +00:00
2021-11-22 15:36:17 +00:00
let map = L.map('map', {
minZoom: mapEl.dataset.minzoom,
maxZoom: mapEl.dataset.maxzoom
})
2021-11-10 10:13:30 +00:00
2021-11-22 15:36:17 +00:00
L.tileLayer("/x/tiles/{s}/{z}/{x}/{y}.png", {
attribution: mapEl.dataset.attribution,
2021-11-10 10:13:30 +00:00
}).addTo(map)
let features = []
2021-11-13 19:19:46 +00:00
2021-11-10 10:13:30 +00:00
paths.forEach(path => {
features.push(L.polyline(path.map(point => [point.Lat, point.Lon]), { color: 'blue' }).addTo(map))
2021-11-10 10:13:30 +00:00
})
2021-11-13 19:19:46 +00:00
points.forEach(point => {
features.push(L.marker([point.Lat, point.Lon]).addTo(map))
})
map.fitBounds(L.featureGroup(features).getBounds(), { padding: [5, 5] })
2021-11-10 10:13:30 +00:00
})()