Last active
October 17, 2021 00:43
-
-
Save stampyzfanz/eb8e5eecc4a7e993a7bfd473dbd996ea to your computer and use it in GitHub Desktop.
View only offroads tracks on Strava's Global Heatmap by drawing over the roads. Can help find footpaths and single trails.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you want to extend this functionality here are some docs: https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-stack/ | |
// To add layers not in strava (ie cyclepaths specifically maybe) this looks promising: https://docs.mapbox.com/vector-tiles/reference/mapbox-streets-v8/ | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// Go to dark mode | |
for (let elt of document.querySelectorAll('label')) { | |
if (elt.innerHTML.includes('Dark')) { | |
elt.click(); | |
} | |
} | |
await sleep(4000) | |
// Get roads | |
let darkroads = map.getStyle().layers.filter(obj => obj.id.includes('road')) | |
let composite = map.getStyle().sources.composite | |
// Go to light mode | |
for (let elt of document.querySelectorAll('label')) { | |
if (elt.innerHTML.includes('Light')) { | |
elt.click(); | |
} | |
} | |
await sleep(4000) | |
// Get cycle paths | |
let ids = ['road-path', 'road-service', 'road-street_limited']; | |
let lightpaths = map.getStyle().layers.filter(obj => ids.includes(obj.id)); | |
// Go to setallite view | |
for (let elt of document.querySelectorAll('label')) { | |
if (elt.innerHTML.includes('Satellite')) { | |
elt.click(); | |
} | |
} | |
await sleep(4000) | |
// Add style for roads | |
map.addSource('composite', composite) | |
// Add dark roads | |
for (let layer of darkroads) { | |
map.addLayer(layer) | |
} | |
// Add light paths | |
for (let layer of lightpaths) { | |
layer.id += '-light'; | |
map.addLayer(layer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment