Reputation: 1591
Working on a mapbox project. I have created a custom layer, and am looking to update a paint property of that layer. Methods I've tried don't work. Here are the details:
The layer I create:
map.addLayer({
id: 'points-circle',
source: 'points',
type: 'circle',
paint: {
'circle-radius': pointSize*.6,
'circle-color': {type: 'identity', property: 'color'},
}
})
Later, I try to update the circle-radius
property, like so:
map.setPaintProperty('points-circle','circle-radius', pointSize*.6)
This fails with the error: Error: The layer 'points-circle' does not exist in the map's style and cannot be styled.
How do I update my circle-radius of my custom added layer?
Upvotes: 3
Views: 3763
Reputation: 1217
You may need to wait for the map idle
event to fire to know that the layer is ready to be styled. See https://docs.mapbox.com/mapbox-gl-js/api/map/#map.event:idle.
Would be nice if map.addLayer
returned a promise that resolved when the layer was able to be styled...
Upvotes: 1