【发布时间】:2020-07-04 21:37:11
【问题描述】:
每次 onPress 调用其中一个数据过滤器按钮时,我都会在我的 Mapbox 中更改渲染注释,正如您在这段代码中看到的那样:
import MapboxGL from "@react-native-mapbox-gl/maps";
MapboxGL.setAccessToken("mytoken_workign_fine");
export default class myClass extends Component{
render_annotaions1 = [{.....},{.....},....];
render_annotaions2 = [{.....},{.....},....];
render_annotaions3 = [{.....},{.....},....];
constructor(props) {
super(props);
this.state = {
filter_state: 1,
};
}
press_filter1(){
if(this.state.filter_state != 1){
this.setState({filter_state:1});
}
}
press_filter2(){
if(this.state.filter_state != 2){
this.setState({filter_state:2});
}
}
press_filter3(){
if(this.state.filter_state != 3){
this.setState({filter_state:3});
}
}
getAnnotations(){
switch(this.state.filter_state ){
case 1:return this.render_annotaions1;
case 2:return this.render_annotaions2;
default:return this.render_annotaions3;
}
}
render(){
return (
<MapboxGL.MapView
ref={(c) => (this._map = c)}
style={{ flex: 1 }}
rotateEnabled={false}
logoEnabled={false}
userTrackingMode={1}
pitchEnabled={false}
>
{this.getAnnotations()}
<MapboxGL.Camera
zoomLevel={1.1}
followUserLocation={false}
centerCoordinate={[9, 34]}
/>
</MapboxGL.MapView>);
}
}
现在,默认注释 ( annotations1 ) 显示良好,但是当我按下一个过滤器按钮时,没有地图更改,它保留默认注释,这是我的问题,我想通过 getAnnotations() 每一个
setState()
和
forceUpdate()
打电话(两者都不起作用),请我帮助解决这个问题,谢谢大家。
【问题讨论】:
标签: javascript android react-native mapbox mapbox-gl