We are building a simple React application that uses google maps to display various events on the map. We are using this repo: https://github.com/tomchentw/react-google-maps
This is the scenario that we are tying to create: Have a bunch of markers shown on the map and have a custom OverlayView shown at all times above the markers.
This is the problem: We are also using google MarkerClusterer. While the markers get clustered when we zoom out the custom Overlays are still shown.
What we need: Have the custom Overlays hide when the markers are clustered.
Here is the code showing the rendering of our google maps. See the <OverlayView>
component. It does not display anything in this example.
Is there a way using react to detect when the markers are no longer visible on the map and then set the visibility of the custom Overlay to hidden?
Thank you.
return ( < div >
< GoogleMapLoader containerElement = { < div {...this.props
}
style = {
{
height: "70vh"
}
}
/>}
googleMapElement={
<GoogleMap
containerProps={{...this.props}}
ref="map"
onBoundsChanged={this.handleBoundsChanged}
defaultZoom={12}
center={
center ? center: userPosition
}
>{contents}
<MarkerClusterer
averageCenter={true}
enableRetinaIcons={true}
gridSize={20}>
{this.data.Missions.map((marker, index) => {
const position = marker.startLocationGeo ? {lat:marker.startLocationGeo.latitude, lng: marker.startLocationGeo.longitude} : null;
const ref = `marker_${index}`;
if(position){
let icon = '';
switch (marker.type) {
case "hit":
icon = "https:/ / www.dropbox.com / s / likbnwqx8y5kywv / shooting.png ? dl = 1 ";
break;
case "
transport ":
icon = "
https: //www.dropbox.com/s/r22dfeh8lutpwv1/fourbyfour.png?dl=1";
break;
default: icon = "https://www.dropbox.com/s/dfjpx65j5v3wlih/pirates.png?dl=1";
break;
}
return ( < Marker key = {
ref
}
ref = {
ref
}
icon = {
icon
}
position = {
position
}
title = {
marker.title
}
onClick = {
this.handleMarkerClick.bind(this, marker)
}
onShapeChanged = {
this.testFunction.bind(this, marker)
} >
{ < OverlayView > THIS COMPONENT SHOULD NOT BE VISIBLE WHEN MARKERS ARE CLUSTERED < /OverlayView>}
{<InfoWindow key={`infoWindow_${index}`} position={position} content={marker.value} ref={`infoWindow_${index}`}/ >
} {
this.state.openedMissions.indexOf(marker.id.objectId) > -1 ? this.renderInfoWindow(ref, marker) : null
} < /Marker>
);
}
})}
</MarkerClusterer >
< SearchBox bounds = {
this.state.bounds
}
controlPosition = {
google.maps.ControlPosition.TOP_LEFT
}
onPlacesChanged = {
this.handlePlacesChanged
}
ref = "searchBox"
placeholder = "Search address"
style = {
inputStyle
}
/>
</GoogleMap >
}
/>
</div >
)