-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.js
63 lines (52 loc) · 1.66 KB
/
plot.js
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
/**
* The id of the embedded map element
*/
const mapId = "map";
/**
* The template URL for the map tile server
*/
const tileUrlTemplate = 'https://tile.thunderforest.com/atlas/{z}/{x}/{y}.png?apikey={YOUR_API_KEY}}';
/**
* The Attribution text that will be shown on the map
*/
const tileAttribution = 'Maps © <a href="http://www.thunderforest.com">Thunderforest</a>, Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>';
/**
* The lines that are currently plotted on the map
*/
let lines = [];
/**
* The Leaflet.js Map element
*/
var map = L.map(mapId);
// use the OpenStreetMap tile servers
L.tileLayer(tileUrlTemplate, {
attribution: tileAttribution,
maxZoom: 18,
tileSize: 512,
zoomOffset: -1,
}).addTo(map);
/**
* Fit the map to the bounds that cover all of the polylines in `lines`
*/
var fitBounds = function () {
let bounds = L.latLngBounds(paths.flatMap(pts => pts.map(pt => L.latLng(pt[0], pt[1]))))
map.fitBounds(bounds);
}
/**
* Plot all of the paths in data.js on the map
*/
var plot = function () {
// Update the status
document.getElementById("status").textContent = `Loading...`
// Remove anything that is plotted
lines.forEach(l => l.remove());
// Plot the lines
let color = document.getElementById("color-input").value || "#FF0000";
let opacity = document.getElementById("opacity-input").value / 100 || 0.3;
lines = paths.map(p => L.polyline(p, { color, opacity }).addTo(map));
// Update the status
document.getElementById("status").textContent = `Plotted ${lines.length} runs!`
}
// Plot the points when the page loads and zoom to fit.
plot();
fitBounds();