In my app I'm using react-google-maps (v.6.x.x) to handle api for Google Maps. I'm using markers and infobox to show proper information. Infobox with enableEventPropagation
set to true, propagates events to map layer through the infobox - what does that mean? When I have infobox - aka infowindow whe I click on it, and underneath is placed marker, this marker is 'clicked' in first place, and than any html element in infobox. If enableEventPropagation
is false - nothing is propagated. So my question is - is there any possibility to add google event listener for react component, for example code:
let infobox = (<InfoBox
onDomReady={() => props.infoBoxReady(infobox)}
defaultPosition={new google.maps.LatLng(props.activeMarker.location[1], props.activeMarker.location[0])}
options={{
closeBoxURL: ``, enableEventPropagation: true, pane: 'mapPane',
position: new google.maps.LatLng(props.activeMarker.location[1], props.activeMarker.location[0]),
alignBottom: true,
pixelOffset: new google.maps.Size(-120, 0)
}}>
How I can use this code to use Google Event Listener
google.maps.event.addListener(infobox, 'domready', function ()
Any clue, how can I set listener for it, or maybe there are other options to set listeners for google map - unfortunately I've to use this library and handle clicks on infobox
Not sure if this helps because this is a different react google maps plugin, but the issue seems quite similar: https://github.com/fullstackreact/google-maps-react/issues/70
The only way I was able to prevent clicks through to the map (stop propagation) and still be able to click items in the in InfoBox is by setting "enableEventPropagation: false" and then adding listeners for the items in the InfoBox on the "onDomReady" prop. This makes sure that the listeners are attached after the InfoBox is rendered. Not sure if thats the best solution, but it did work. Hope that helps someone.
You can access the listeners via props on the InfoBox component.
Check them out here: Github docs
You're already using one -
onDomReady
- there's also:I wrote this wrapper component that places a
<Rectangle/>
over the entire map to stop clicks being passed through to the map below. Whilst still allowing you to click things inside the<infoBox/>
.This allows
enableEventPropagation
to be set totrue
without creating problems. I then usemouseOver
andmouseOut
to control how the rectangle works. In my case I use clicking on the rectangle to close my<InfoBox/>
. You could just as easily hide and show it.