-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
100 lines (83 loc) · 2.79 KB
/
Copy pathscript.js
File metadata and controls
100 lines (83 loc) · 2.79 KB
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
document.addEventListener("DOMContentLoaded", () => {
const layers = [
{ el: document.querySelector(".layer1"), speed: 1, offset: 0 },
{ el: document.querySelector(".layer2"), speed: 1, offset: -85 },
{ el: document.querySelector(".layer3"), speed: 1, offset: -170 },
{ el: document.querySelector(".layer4"), speed: 1, offset: -255 },
{ el: document.querySelector(".layer5"), speed: 1, offset: -340 },
];
// Function to position layers
function updateLayers() {
const scrollY = window.scrollY;
const vh = window.innerHeight; // 1vh = viewport height in px
layers.forEach(layer => {
const offsetPx = layer.offset * vh / 100; // convert vh to px
layer.el.style.transform = `translateY(${scrollY * layer.speed + offsetPx}px)`;
});
}
// Initialize immediately
updateLayers();
// Update on scroll
window.addEventListener("scroll", updateLayers);
});
// MAP STUFF
const mapContainers = document.querySelectorAll(".map-container");
mapContainers.forEach((container, index) => {
const mapDiv = container.querySelector(".map");
const metricsDiv = container.querySelector(".map-metrics");
// Initialize map
const map = L.map(mapDiv).setView([68, -91.935165], 2);
// Tile layer
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
maxZoom: 18,
attribution: 'Tiles © Esri'
}).addTo(map);
// GPX icons
const startIcon = L.icon({
iconUrl: "Assets/start.png",
iconSize: [16, 16],
iconAnchor: [8, 8]
});
const endIcon = L.icon({
iconUrl: "Assets/end.png",
iconSize: [16, 16],
iconAnchor: [8, 8]
});
// Load GPX file from data-gpx attribute
const gpxFile = mapDiv.getAttribute("data-gpx");
const lineWeight = mapDiv.getAttribute("data-weight") || 4;
new L.GPX(gpxFile, {
async: true,
polyline_options: {
color: "#FC4C02",
weight: lineWeight,
opacity: 1,
lineCap: "round"
},
markers: {
startIcon: startIcon,
endIcon: endIcon,
shadowUrl: null
},
display_wpt: false
}).on("loaded", function(e) {
const gpx = e.target;
map.fitBounds(gpx.getBounds());
// Update metrics safely
if (metricsDiv) {
const distanceEl = metricsDiv.querySelector(".distance");
if (distanceEl) {
distanceEl.textContent = (gpx.get_distance() / 1000).toFixed(2) + " km";
}
const timeEl = metricsDiv.querySelector(".time");
if (timeEl) {
const totalTime = gpx.get_total_time();
timeEl.textContent = gpx.get_duration_string_iso(totalTime);
}
const elevationEl = metricsDiv.querySelector(".elevation");
if (elevationEl) {
elevationEl.textContent = gpx.get_elevation_gain().toFixed(0) + " m";
}
}
}).addTo(map);
});