Added support for setStyleLayerProperty
Added setStyleLayerProperty support that allows setting the value of a property for a specific layer referencing the specified layerId
Checklist
- [X] I've read
CONTRIBUTING.md - [X] I updated the doc/other generated code with running
yarn generatein the root folder - [X] I have tested the new feature on
/exampleapp.- [X] In V11 mode/ios
- [X] In New Architecture mode/ios
- [X] In V11 mode/android
- [X] In New Architecture mode/android
- [X] I added/updated a sample - if a new feature was implemented (
/example)
@mfazekas Created a new PR with the latest version. closing an old one https://github.com/rnmapbox/maps/pull/3870.
Added an example too. Thanks
@msaqlain thanks much, can you also add some motivation?!
How is this different from our existing solution:
<FillLayer id="building" existing style={{ visibility }} />
https://rnmapbox.github.io/docs/examples/Map/ShowAndHideLayer
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 setSourceVisibility
mapRef.current?.setSourceVisibility(
shouldBeVisible,
'composite',
mode
);
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 setStyleLayerProperty
mapRef?.current?.setStyleLayerProperty(
layerId,
'visibility',
'visible'
);
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 setStyleLayerProperty
mapRef?.current?.setStyleLayerProperty(
layerId,
'visibility',
'visible'
);
I think we do have this:
const [visibility, setVisbility] = useState('visible')
...
<FillLayer id="building" existing style={{ visibility }} />
This will change a specific layer of(building) visibility. Note the existing flag, that will not create new layer but will lookup up the layer by id.
@mfazekas If we use this approach as you mentioned, then in my scenario, I have to render 300 layers using FillLayer, which I need to enable and disable based on my internal grouping.
So to achieve this without explicitly mentioning FillLayer i can load map using styleURL only and then using map ref i can enable disable layers.
@mfazekas Any update on this?
@msaqlain we'd need CI to pass