Trigger event with infoWindow or InfoBox on click Google Map API V3

前端 未结 5 697
遥遥无期
遥遥无期 2020-11-30 08:20

I want to know how to trigger an event when I click on an infoWindow using Google Maps API v3. In this example, when I click on a marker, an info window shows up with a uni

5条回答
  •  心在旅途
    2020-11-30 08:32


    Thanks for all your comments. I manage to build (after reading your suggestions) an example that works without modifying the Infowindow code.

    The infoWindow itself should only contain a placeholder div with a unique id:

         {
              this.onInfoWindowOpen(this.props, e);
            }}
          >
            

    And inside the Mapcontainer, you define an onInfoWindowOpen callback, that inserts a single component/container with the onClick event and render it to a placeholder div:

        onInfoWindowOpen = () => {
            const button = ();
            ReactDOM.render(React.Children.only(button),document.getElementById("xyz"));
            }
    
    

    Here is a working example:

    https://codesandbox.io/s/k0xrxok983


    One more complete example MAP, Marker and InfoWindow:

    https://codesandbox.io/s/24m1yrr4mj

提交回复
热议问题