nitaliano / react-native-mapbox-gl

A Mapbox GL react native module for creating custom maps
Other
2.16k stars 699 forks source link

is it possible to change visibility by source id. #1613

Closed ansarikhurshid786 closed 5 years ago

ansarikhurshid786 commented 5 years ago

I just want to toggle layer visibility like in mapbox gl js. https://docs.mapbox.com/mapbox-gl-js/example/toggle-layers/

is it possible to change visibility value to none or visible?

sheburdos commented 5 years ago

Source is a "source" of data. The way how it is presented is controlled by Layer. You will need change properties of the layer, not source. If map style is loaded from URL, and not created dynamically, you can do smth like

<MapboxGL.MapView styleURL="http://localhost:3000/style">

  <MapboxGL.RasterSource id={sourceId}>
     <MapboxGL.RasterLayer id={layerId} style={{ visibility: isLayerVisible ? 'visible' : 'none' }} />
   </MapboxGL.RasterSource>

</MapboxGL.MapView>

So you need to know source-id and layer-id