用户单击弹出窗口中的按钮后关闭弹出窗口 react-leaflet [英] close popup react-leaflet after user click on button in popup
本文介绍了用户单击弹出窗口中的按钮后关闭弹出窗口 react-leaflet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以基本上想为 react-leaflet Popup 组件自定义关闭,接缝这与原生 API 传单无关,但使用 react-leaflet 中的 react 组件我找不到解决方案.
So basically want to make custom close for react-leaflet Popup component, seams that is not a big problem to do with native API leaflet but with react component from react-leaflet I can't find the solution.
推荐答案
目前,我发现关闭弹出窗口的唯一方法如下:
at the moment, the only way I found to close the popup is the following:
constructor(props){
super(props);
this.popup = React.createRef();
}
// the magic
closePopusOnClick(){
this.popup.current.leafletElement.options.leaflet.map.closePopup();
}
render(){
return <Marker position={[this.props.lat, this.props.lng]}>
<Popup ref={this.popup}>
<Button onClick={this.closePopusOnClick}>Close popup</Button>
</Popup>
</Marker>;
}
希望有帮助!
这篇关于用户单击弹出窗口中的按钮后关闭弹出窗口 react-leaflet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文