我在地图初始化中设置了自定义样式网址.喜欢 : Mapbox.MapView styleURL="asset://mystyle.json" logoEnabled={false} attributionEnabled={false} ref={(e) = { this.oMap = e }} animate={true} zoomLevel={6} centerCoordinate={[54
<Mapbox.MapView styleURL="asset://mystyle.json" logoEnabled={false} attributionEnabled={false} ref={(e) => { this.oMap = e }} animate={true} zoomLevel={6} centerCoordinate={[54.0, 24.0]} style={{ flex: 1 }} showUserLocation={true}> </Mapbox.MapView>
在mystyle.json中我有两个基本地图如下:
{ "id": "Satellite", "type": "raster", "source": "Satellite", "layout": { "visibility": "visible" }, "paint": { "raster-opacity": 1 } }, { "id": "Satellite2", "type": "raster", "source": "Satellite", "layout": { "visibility": "none" }, "paint": { "raster-opacity": 1 } }
卫星是默认可见的.
如何将卫星属性的可见性设置为none,将satellite2的可见性设置为在运行时可见?
Mapbox gl:
"@mapbox/react-native-mapbox-gl": "^6.1.3"
反应原生:
"react-native": "0.58.6",假设我们有一个状态isStateliteVisible:false,
现在,当您想要查看时,将此状态更改为true
并像这样使用mapbox,
<Mapbox.MapView styleURL={this.state.isStateliteVisible?...visiblityStyle:....noneStyle} // use this as per your case logoEnabled={false} attributionEnabled={false} ref={(e) => { this.oMap = e }} animate={true} zoomLevel={6} centerCoordinate={[54.0, 24.0]} style={{ flex: 1 }} showUserLocation={true}> </Mapbox.MapView>