Click event in Google Map InfoWindow not caught

前端 未结 6 1837
暖寄归人
暖寄归人 2021-02-08 13:43

With Google Map v2, I would like to be able to trigger a function when clicking a text in the InfoWindow of a GMarker.

$(\".foo\").click(myFunction);

...

marke         


        
6条回答
  •  失恋的感觉
    2021-02-08 14:28

    The simplest and fully describe solutions.

    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

    If you have any questions so please comment.

提交回复
热议问题