我已经在地图初始化中设置了自定义样式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中,我有两个基本映射,如下所示:
{
"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可见性设置为visible?
Mapbox gl:
"@mapbox/react-native-mapbox-gl": "^6.1.3"原生React:
"react-native": "0.58.9",发布于 2019-03-10 18:40:33
最后我得到了解决方案:
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>我已经添加了栅格层和编程切换它。
发布于 2019-03-07 14:55:54
假设我们有一个状态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>发布于 2019-03-07 13:17:06
我可以看到您使用的是较旧的mapbox-gl折旧版本。此程序包已弃用,请改用this。
安装
依赖关系
node
npm
React Native recommended version 0.50 or greaterGit
git clone git@github.com:mapbox/react-native-mapbox-gl.git
cd react-native-mapbox-gl纱线
yarn add @mapbox/react-native-mapbox-glNpm
npm install @mapbox/react-native-mapbox-gl --save你可以走了!
https://stackoverflow.com/questions/55036420
复制相似问题