diff --git a/src/uhm/components/map/useMapInstance.ts b/src/uhm/components/map/useMapInstance.ts index 5236eb6..8947b00 100644 --- a/src/uhm/components/map/useMapInstance.ts +++ b/src/uhm/components/map/useMapInstance.ts @@ -3,6 +3,7 @@ import maplibregl from "maplibre-gl"; import { MAP_MAX_ZOOM, MAP_MIN_ZOOM } from "@/uhm/lib/map/constants"; import { clampNumber, roundZoom } from "./mapUtils"; import { getBaseMapStyle } from "./useMapLayers"; +import { unregisterMapFromIconUpdates } from "@/uhm/lib/map/styles/geotypeLayers"; const MAP_PROJECTION_STORAGE_KEY = "uhm:mapProjection"; @@ -79,6 +80,7 @@ export function useMapInstance() { if (mapRef.current === map) { mapRef.current = null; } + unregisterMapFromIconUpdates(map); map.remove(); }; } catch (err) { diff --git a/src/uhm/lib/map/styles/geotypeLayers.ts b/src/uhm/lib/map/styles/geotypeLayers.ts index 0dba6a5..ae6fa5a 100644 --- a/src/uhm/lib/map/styles/geotypeLayers.ts +++ b/src/uhm/lib/map/styles/geotypeLayers.ts @@ -1,6 +1,6 @@ import maplibregl from "maplibre-gl"; export const TYPE_MATCH_EXPR: maplibregl.ExpressionSpecification = ["coalesce", ["get", "type"], ["get", "entity_type_id"], ""]; -export { ensurePointGeotypeIcons } from "./shared/pointStyle"; +export { ensurePointGeotypeIcons, unregisterMapFromIconUpdates } from "./shared/pointStyle"; import { getDefenseLineLayers } from "./geotypes/defense_line"; import { getMilitaryRouteLayers } from "./geotypes/military_route"; diff --git a/src/uhm/lib/map/styles/shared/pointStyle.ts b/src/uhm/lib/map/styles/shared/pointStyle.ts index 0c886c8..1033de2 100644 --- a/src/uhm/lib/map/styles/shared/pointStyle.ts +++ b/src/uhm/lib/map/styles/shared/pointStyle.ts @@ -178,6 +178,10 @@ const preloadedImages: Record = {}; const loadedImageKeys = new Set(); const mapsToUpdate = new Set(); +export function unregisterMapFromIconUpdates(map: maplibregl.Map) { + mapsToUpdate.delete(map); +} + function preloadPointIcons() { if (typeof window === "undefined" || typeof document === "undefined") return; for (const [typeId, path] of Object.entries(POINT_GEOTYPE_ICON_PATHS)) {