用户单击弹出窗口中的按钮后关闭弹出反应传单

Kib*_*007 6 popup leaflet reactjs react-leaflet

所以基本上想要为react-leaflet Popup组件定制关闭,接缝对于本机API传单来说不是一个大问题,但是对于react-leaflet中的react组件我找不到解决方案。

Luc*_*llo 3

目前,我发现关闭弹出窗口的唯一方法如下:

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>;
}
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!