Last active
February 23, 2023 20:52
-
-
Save yuletide/979e0dd8528b5407c8040c6aea3a320b to your computer and use it in GitHub Desktop.
Get a list of all mapbox layer ids grouped by feature component for easy toggling of mapbox streets layers
This file contains hidden or 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
#!/usr/bin/env node | |
// usage node getStyleComponents.js > groups.json | |
// looks for a style named style.json, rename to match or use process.argv if you want | |
// then save these ids to an array and toggle with: | |
// layers?.forEach(lyr => map.setLayoutProperty(lyr, "visibility", value)); | |
const style = require("./style.json"); | |
const components = style.layers.reduce((map, lyr) => { | |
const component = lyr.metadata?.["mapbox:featureComponent"]; | |
if (map[component]) { | |
map[component].push(lyr.id); | |
} else { | |
map[component] = [lyr.id]; | |
} | |
return map; | |
}, {}); | |
console.log(components); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment