I'm having an issue with google maps InfoBox in a React application. My goal is to open up an empty InfoBox on a google maps instance, and then use ReactDOM.render to put my component inside of it. The component comprises of a set of tabs, with each tab pane making an API call through redux and thunk when it's opened.
This all works fine, it displays nicely. The problem comes from actually clicking on the InfoBox. I can get it to work in one of two ways by changing the enableEventPropagation to be true or false:
enableEventPropagation = true: The component works, all the tabs and buttons, but any markers underneath my InfoBox will be opened if I happen to click on the right part of the InfoBox, which completely breaks the state and flow of my application.
enableEventPropagation = false: The clicks don't go through to the map, but then none of the click events in the react component work. No tabs, no buttons: nothing. Looks great but doesn't work at all.
Here's my code for creating my InfoBox and rendering to it with ReactDOM:
renderInfoBox() {
let {map, google, infoBox} = this.props;
let markerElement = MarkerElementService.getMarkerElement(infoBox.ui.markerId);
this.infoBox = new this.infoBoxClass({
content: this.refs.infoBoxHolder,
enableEventPropagation: false,
pixelOffset: new google.maps.Size(10, -275),
maxWidth: 350,
zIndex: 99999999,
infoBoxClearance: new google.maps.Size(75, 75)
});
ReactDOM.render(
<Provider store={AppStore}>
<ThemeProvider theme={Theme}>
<InfoBoxComponent google={google} onClose={this.closeButtonClicked.bind(this)} />
</ThemeProvider>
</Provider>,
this.refs.infoBoxHolder,
() => {
this.infoBox.open(map, markerElement);
}
);
}
render() {
return (
<div ref="infoBoxHolder" />
);
}
I have tried the following solutions:
Swapping to GoogleMaps OverLay. Exactly the same issue, in fact looking at the InfoBox addon it seems InfoBox is a wrapper to OverLay which helps remove some of these problems, but still assumes it's only going to be non-interactive.
Disabling event propagation at various points inside of my components, but the effect is that it disables event propagation down the DOM tree, not up, meaning child components don't work! Mad!
It seems my only option left is to somehow calculate the Lat/Lng bounds of the InfoBox once it's been rendered and then sequentially disable all markers that are in that area, but that's a hacky load of nonsense I want to avoid!
Or maybe I have completely the wrong approach?