Repository navigation
Added support for setStyleLayerProperty - #4051
Conversation
|
@msaqlain thanks much, can you also add some motivation?! How is this different from our existing solution: <FillLayer id="building" existing style={{ visibility }} /> |
|
Yes sure @mfazekas When we are only loading map using styleURL that contains all the Layers & SourceLayers we dont have references to all the FillLayer, LineLayer or other shapes. To toggle SourceLayers (composite, satellite) we have this method Similarly if you want to toggle a specific layer we dont have any method available. To enable this my in my PR i am using |
I think we do have this: const [visibility, setVisbility] = useState('visible')
...
<FillLayer id="building" existing style={{ visibility }} />This will change a specific layer of( |
|
@mfazekas If we use this approach as you mentioned, then in my scenario, I have to render 300 layers using
So to achieve this without explicitly mentioning |
|
@mfazekas Any update on this? |
|
@msaqlain we'd need CI to pass |
|
Any update ? |
Pass the value through to the SDK as any JSON value (so numbers, colors and expressions work, not only strings), reject the promise when the SDK reports an error, move the iOS method onto RNMBXMapView after the old architecture manager was removed, and rewrite the example as a TSX function component.
|
Thanks @msaqlain! I brought this up to date with main and made a few changes so it matches the SDK call directly: |

Description
Added
MapView#setStyleLayerProperty(layerId, property, value), a thin wrapper over the Mapbox SDK'ssetStyleLayerPropertyon iOS and Android. It's handy for layers that come fromstyleURL(for example showing or hiding groups of them) without declaring them as layer components.valuecan be any JSON value, including expressions, and the returned promise rejects if the SDK reports an error (unknown layer or property, invalid value).Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./example)Screenshot OR Video
Component to reproduce the issue you're fixing
Test screen used on the iOS simulator and Android emulator (valid visibility/color/expression changes plus the invalid layer and invalid property error paths):
Results on the iOS simulator (iPhone 17) and Android emulator: hide/show,
fill-colorand thefill-opacityexpression all apply. The invalid layer rejects withLayer 'nope-layer' is not in styleand the invalid property withfill layer doesn't support this property: nope-propon both platforms.