"mapLayer.layout.get()" is no longer a function
mapbox-gl-js version: 3.5.2
browser: Safari, Chrome, Firefox
Steps to Trigger Behavior
- attempt to use
map.getLayer(LAYER_ID).layout.get('icon-size').value.value
Link to Demonstration
Expected Behavior
The value of the layer property is returned.
Actual Behavior
An error stating that get is not a function (it is undefined) is thrown.
Other tech details
I found that the computed value is now available under map.style._layers[LAYER_ID].layout._values['icon-size'].value.value, but this is both using what looks like an internal value, and the types are not set up well to use like .get() was with the @types/ library previously.
Also, map.style._layers[LAYER_ID] has a type of StyleLayer, which is a base type, (rather than being TypedStyleLayer which is the combined type), so there’s no way to use type guards to narrow it to the type, (SymbolStyleLayer), required.
Hi @brookjordan,
The StyleLayer is not intended to be part of the public API, and starting with v3.5.2, Map#getLayer returns serialized layers instead of the internal StyleLayer instance.
So both map.getLayer(LAYER_ID).layout and map.style._layers[LAYER_ID].layout are considered internal APIs. Could you please share more context on your use case?
Starting with v3.5.2, you can narrow Map#getLayer return type, e.g.:
https://github.com/mapbox/mapbox-gl-js/blob/fcfe0894e662be52e74689b2e004fbe2cf97841c/test/build/typings/index.ts#L273-L304