-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unmounting Markers performance using MarkerClusterer #2849
Comments
Something else that improves performance is to add https://react-google-maps-api-docs.netlify.app/#!/Marker But although it solves my performance problems it adds me another problem, the marker does not reload itself, then I have to "move" or interact with it so that new markers are added. 🤔 UPDATE 1:In another thread someone seems to have solved this: |
Hello everyone! I am dealing with this issue and I can't find a way to actually make it work correctly, meaning markers and clusters do get updated correctly. |
Setting function Map({ markers }) {
const clustererRef = useRef()
useEffect(() => {
clustererRef.current?.repaint()
}, [markers.length])
return (
<GoogleMap center={center}>
<MarkerClusterer
options={clustererOptions}
onLoad={clusterer => (clustererRef.current = clusterer)}
>
{clusterer =>
markers.map(marker => (
<MarkerF
key={marker.id}
position={marker.position}
clusterer={clusterer}
noClustererRedraw={true}
/>
))
}
</MarkerClusterer>
</GoogleMap>
)
} |
I confirm calling |
@madox2 Thanks for your suggestion, it helped a lot in my specific case and I haven't observed anything else than improved performance. |
Solution by @madox2 works fantastically. I can confirm |
please test MarkerClustererF with 2.15.0 version |
Hi @JustFly1984 I just upgraded from 2.8 to 2.17 and the performance seems the same without manually calling |
If anyone wants a solution for React18, I resolved this by using a combination of state management and clearing of markers, you also need to use MarkerClustererF and MarkerF as they are compatible with React18. When updating your set of markers, set the state to an empty array and then repopulate it with the desired markers and then use the onUnMount handle to clear the set of markers. What happens is that when the markers length is set to 0, the onUnMount handler is called which clears the markers and then when you repopulate the markers the markerclusterer is rendered from scratch which means no repaint needed. Hope this helps!
|
what is your parameter "Markers" ? I get syntax issue when I use my locations list to map it into markers, please advice |
Hello everyone!
I'm currently rendering and clustering more than a 1500 markers. On the first load everything works ok but if I change the state filtering those markers it takes too long (1min) to remove all the markers and just leave the ones I want. It only happens if I use the MarkerClusterer component.
This is what I see while it is removing the markers
I found that the same issue happened on the react-google-maps library
I'm using:
os: mac/linux
node --version: 16.3.0
react version: 17.0.2
@react-google-maps/api: 2.2.0
Any workaround to resolve this issue?
The text was updated successfully, but these errors were encountered: