MIP*_*IPB 3 reactjs react-native react-native-maps
当我按下应用程序上卡片的 X 按钮时,我当前正在尝试关闭标注。
我的代码是这样的。** 封卡功能 **
unsetCard = id => {
this.setState({
...this.state,
showCard: false,
});
this.markers.hideCallout();
if (this.state.keyboard) {
Keyboard.dismiss();
}
};
Run Code Online (Sandbox Code Playgroud)
这是我的 ** 地图视图代码,我使用 RN 聚类 **
<MapView
//
mapRef={ref => (this.myMapRef = ref)}
//
onPress={this.unsetCard}>
{this.props.data.map(marker => (
<Marker
key={marker.id}
ref={ref => (this.markers = ref)}
//
}>
<Callout
//
}}>
<CustomCallout title={marker.t} />
</Callout>
</Marker>
))}
</MapView>
Run Code Online (Sandbox Code Playgroud)
最后在同一文件中的该组件中调用取消设置卡的函数:
<CustomCardWithImage
close={() => this.unsetCard(this.state.cardInfo.id)}
/>
Run Code Online (Sandbox Code Playgroud)
如果有人告诉我如何使用标记的引用,我将不胜感激,因为尽管我尝试过,但它不起作用。
提前致谢,
在认真考虑不再继续使用这个应用程序后,我休息了一下并解决了问题。如果您有兴趣,可以使用以下方法使用显示或隐藏标注:
初始化标记
constructor(props) {
super();
this.markers = [];
}
Run Code Online (Sandbox Code Playgroud)
创建标记参考
<Marker
key={marker.id}
ref={ref => {
this.markers[marker.id] = ref;
}}>
Run Code Online (Sandbox Code Playgroud)
有需要的地方打电话
this.markers[id].hideCallout();
Run Code Online (Sandbox Code Playgroud)
我希望有一天有人会发现它有帮助