[Bug] Map instance caching has buggy behavior when used with clustering
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
Empieza reproduciendo el flujo de navegación descrito con el componente Map, reuseMaps={true} y el ejemplo de agrupación de marcadores que usa @googlemaps/markerclusterer. Rastrea la limpieza de los marcadores de clúster durante la navegación entre vistas de ciudades y determina por qué permanecen los marcadores de la ciudad anterior. Se considera terminado cuando cambiar de ciudad ya no deja marcadores de clúster de vistas anteriores en el mapa almacenado en caché.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
I'm implementing an application that has a view /cities which allows you to view all cities on a google map. You can then navigate to view a specific cities at /cities/[id]. Each city then has markers for EV chargers in the city. The EV charger markers are clustered.
If I enable map instance caching via reuseMaps={true} I run into issues where cluster markers remain on the map as you navigate from one city to another. It's not obvious as you have to zoom out in order to see cluster markers from multiple cities.
I'm using @googlemaps/markerclusterer and the implementation follows the marker-clustering example in this repo.
I'm storing the cluster markers in an array stored in useRef in an attempt to be able to remove them when the component unmounts.
return new MarkerClusterer({
map,
renderer: {
render: (cluster, stats, map) => {
const markerElem = renderClusterMarker({
cluster,
map,
mapContentType,
});
// cluster markers are added to the array here
clusterMarkerElems.current.push(markerElem);
return markerElem;
},
},
});
Then on unmount I'm attempting to remove the cluster markers:
useEffect(() => {
return () => {
// This does not throw an error, but it does not seem to work
clusterMarkerElems.current.forEach((clusterMarkerElem) => {
clusterMarkerElem.setMap(null);
});
setMarkers({});
// markerClusterer is always null
if (markerClusterer) {
markerClusterer?.clearMarkers();
}
};
}, []);
The code in the cleanup function does not throw an error, but it also doesn't work. I have a guess that the <Map> component is already removed by the time the cleanup function runs. If I run markerClusterer.clearMarkers() when the view loads it doesn't remove the stranded markers as I don't think it knows they exist.
Steps to Reproduce
See description.
Environment
- Library version: 1.4.2
- Google maps version: weekly
- Browser and Version: Firefox latest
- OS: macOS
Logs
No response
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.9k
- Forks
- 195
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de visgl/react-google-maps
-
bug needs more info
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
visgl/react-google-maps#1039 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
visgl/react-google-maps#918 · 9 comentarios ·
Los mantenedores suelen responder en 3 días
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
visgl/react-google-maps#905 ·
Los mantenedores suelen responder en 3 días
-
google maps issue
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
visgl/react-google-maps#889 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
visgl/react-google-maps#884 · 1 comentario ·
Los mantenedores suelen responder en 3 días
Todos los issues de visgl/react-google-maps
Issues similares
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
StabilityNexus/Fate-EVM-Frontend#153 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
code-yeongyu/oh-my-openagent#9039 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Tencent/teamai-cli#862 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue hacktoberfest redis
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
libredb/libredb-studio#1164 ·
Los mantenedores suelen responder en 1 día
-
flake
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
coder/xum#4920 · 2 comentarios ·
Los mantenedores suelen responder en 1 día