所以基本上想为 react-leaflet Popup 组件定制关闭,接缝这与原生 API 传单无关,但使用 react-leaflet 中的 react 组件我找不到解决方案。
最佳答案
目前,我发现关闭弹出窗口的唯一方法如下:
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>;
}
希望能帮助到你!
关于reactjs - 用户单击弹出窗口中的按钮后关闭弹出窗口 react-leaflet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52085768/