gpt4 book ai didi

react-native - 如何在运行时在 react-native-mapbox-gl 中显示/隐藏光栅层(可见性属性可见/无)

转载 作者:行者123 更新时间:2023-12-04 17:14:37 24 4
gpt4 key购买 nike

我在 map 初始化中设置了自定义样式 url。喜欢 :

<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 我有两个 basemap ,如下所示:
 {
"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
}
}

卫星是可见的默认。

如何在运行时将卫星属性的可见性设置为无并将卫星 2 的可见性设置为可见?

map 箱gl:
"@mapbox/react-native-mapbox-gl": "^6.1.3"

react 原生:
"react-native": "0.58.9",

最佳答案

最后我得到了解决方案:

constructor() {
this.state = {
lightMap: 'visible',
darkMap: 'none'
};
}

changeMap(){
this.setState({darkMap:'visible'})
}

<MapboxGL.MapView
styleURL="asset://mystyle.json"
logoEnabled={false}
attributionEnabled={false}
ref={(e) => { this.oMap = e }}
zoomLevel={6}
centerCoordinate={[54.0, 24.0]}
style={{ flex: 1 }}>

<MapboxGL.RasterSource
id="idLightMap"
url="LAYERURL1"
tileSize={256}>
<MapboxGL.RasterLayer
id="idLightMap"
sourceID="idLightMap"
style={{visibility: this.state.lightMap}}>
</MapboxGL.RasterLayer>
</MapboxGL.RasterSource>

<MapboxGL.RasterSource
id="idDarkMap"
url="LAYERURL2"
tileSize={256}>
<MapboxGL.RasterLayer
id="idDarkMap"
sourceID="idDarkMap"
style={{visibility: this.state.darkMap}}>
</MapboxGL.RasterLayer>
</MapboxGL.RasterSource>

</MapboxGL.MapView>

我添加了光栅层并以编程方式切换它。

关于react-native - 如何在运行时在 react-native-mapbox-gl 中显示/隐藏光栅层(可见性属性可见/无),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55036420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com