From a8304e543e027bb0f230ca420261f1a7c4696d39 Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Thu, 13 Mar 2025 15:21:18 +0000 Subject: [PATCH] Merged in fix/SW-1763-clustering-pins-on-filtering-city-map (pull request #1520) fix/SW-1763 clustering pins on filtering city map * fix(SW-1763): uncluster when filter is applied * fix(SW-1763): pass active filters as prop * fix(SW-1763): change prop type to boolean Approved-by: Erik Tiekstra --- .../DestinationPage/Map/MapContent/index.tsx | 14 +++++++++++--- .../ContentType/DestinationPage/Map/index.tsx | 13 ++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/scandic-web/components/ContentType/DestinationPage/Map/MapContent/index.tsx b/apps/scandic-web/components/ContentType/DestinationPage/Map/MapContent/index.tsx index a830c31e6..994e0d36b 100644 --- a/apps/scandic-web/components/ContentType/DestinationPage/Map/MapContent/index.tsx +++ b/apps/scandic-web/components/ContentType/DestinationPage/Map/MapContent/index.tsx @@ -19,6 +19,7 @@ import type { interface MapContentProps { geojson: MarkerGeojson + hasActiveFilters?: boolean } // Important this is outside the component to avoid re-creating the object on each render @@ -29,14 +30,21 @@ const CLUSTER_OPTIONS = { maxZoom: 14, } -export default function MapContent({ geojson }: MapContentProps) { +export default function MapContent({ + geojson, + hasActiveFilters, +}: MapContentProps) { const { setClickedHotel, clickedHotel } = useDestinationPageHotelsMapStore() const map = useMap() + const { clusters, containedHotels } = useSupercluster( geojson, CLUSTER_OPTIONS ) + // Based on the length of active filters, we decide if should show clusters or individual markers + const markerList = hasActiveFilters ? geojson.features : clusters + useEffect(() => { map?.addListener("click", () => { if (clickedHotel) { @@ -53,11 +61,11 @@ export default function MapContent({ geojson }: MapContentProps) { } } - return clusters.map((feature, idx) => { + return markerList.map((feature, idx) => { const [lng, lat] = feature.geometry.coordinates const clusterProperties = feature.properties as ClusterProperties const markerProperties = feature.properties as MarkerProperties - const isCluster = clusterProperties.cluster + const isCluster = clusterProperties?.cluster return isCluster ? ( ({ + activeFilters: state.activeFilters, + })) + + const hasActiveFilters = activeFilters.length > 0 + const markers = getHotelMapMarkers(hotels) const geoJson = mapMarkerDataToGeoJson(markers) const defaultCoordinates = defaultLocation @@ -150,7 +158,10 @@ export default function Map({ defaultCoordinates={defaultCoordinates} defaultZoom={defaultZoom} > - +