从Marker Component外部打开一个PopUp

时间:2018-02-12 19:39:04

标签: reactjs react-leaflet

嘿所以我试图通过单击外部引用来打开组件上的PopUp。我似乎找不到手动打开PopUp的方法。我在地图之外有标记列表,当点击一个时我想显示弹出窗口。我找到了一种方法来指定哪个标记应该是弹出窗口,我只是无法触发事件。有没有办法做到这一点?

这就是我正在重建的内容

http://transportation.austintexas.io/signals-on-flash/

1 个答案:

答案 0 :(得分:0)

我能够通过创建一个CustomMarker组件并扩展Marker类来实现这一点,并在ComponentWillMount()中调用bindPopup

export default class CustomMarker extends Marker{
componentWillMount(){
    super.componentWillMount();
    console.log(this.props.info);
    this.leafletElement.bindPopup('foo')
}

然后我调用了`我能够通过创建一个CustomMarker组件并扩展Marker类来实现这一点,并在ComponentWillMount()中调用bindPopup

export default class CustomMarker extends Marker{
componentWillMount(){
    super.componentWillMount();
    console.log(this.props.info);
    this.leafletElement.bindPopup('foo')
}

然后在标记元素上调用ref={open ? this.simulateClick : null}

simulateClick()看起来像这样

simulateClick = marker => {
    if(marker){
        marker.leafletElement.openPopup();
    }
};
相关问题