silicakes silicakes -4 years ago 130
Javascript Question

mapbox gl-js: how to get the styles of points/polygons from mapbox studio and position it programmatically?

I have a map with an abundance of dynamically generated data.

I'd wish to keep the styling for this data inside mapbox studio itself - but would like to position it manually (programmatically).

The best example I've found is this: however the positioning stems from mapbox studio as well.

Answer Source

I've manage to achieve the above by using getPaintProperty and setPaintProperty where you can get a property from a hidden layer with something like

mapInstance.getPaintProperty("hidden layer name", "fill-color");

and set it with

setPaintProperty("visible layer id", "fill-color", valueFromTheGetMethod);

It's only good for a single property, so you need to 'manually' collect everything you need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download