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
This commit is contained in:
Fredrik Thorsson
2025-03-13 15:21:18 +00:00
parent 29f0eb4f21
commit a8304e543e
2 changed files with 23 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ import type {
interface MapContentProps { interface MapContentProps {
geojson: MarkerGeojson geojson: MarkerGeojson
hasActiveFilters?: boolean
} }
// Important this is outside the component to avoid re-creating the object on each render // Important this is outside the component to avoid re-creating the object on each render
@@ -29,14 +30,21 @@ const CLUSTER_OPTIONS = {
maxZoom: 14, maxZoom: 14,
} }
export default function MapContent({ geojson }: MapContentProps) { export default function MapContent({
geojson,
hasActiveFilters,
}: MapContentProps) {
const { setClickedHotel, clickedHotel } = useDestinationPageHotelsMapStore() const { setClickedHotel, clickedHotel } = useDestinationPageHotelsMapStore()
const map = useMap() const map = useMap()
const { clusters, containedHotels } = useSupercluster<MarkerProperties>( const { clusters, containedHotels } = useSupercluster<MarkerProperties>(
geojson, geojson,
CLUSTER_OPTIONS 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(() => { useEffect(() => {
map?.addListener("click", () => { map?.addListener("click", () => {
if (clickedHotel) { 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 [lng, lat] = feature.geometry.coordinates
const clusterProperties = feature.properties as ClusterProperties const clusterProperties = feature.properties as ClusterProperties
const markerProperties = feature.properties as MarkerProperties const markerProperties = feature.properties as MarkerProperties
const isCluster = clusterProperties.cluster const isCluster = clusterProperties?.cluster
return isCluster ? ( return isCluster ? (
<ClusterMarker <ClusterMarker

View File

@@ -12,6 +12,8 @@ import {
import { Dialog, Modal } from "react-aria-components" import { Dialog, Modal } from "react-aria-components"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { useDestinationDataStore } from "@/stores/destination-data"
import DestinationFilterAndSort from "@/components/DestinationFilterAndSort" import DestinationFilterAndSort from "@/components/DestinationFilterAndSort"
import { ChevronLeftSmallIcon } from "@/components/Icons" import { ChevronLeftSmallIcon } from "@/components/Icons"
import Button from "@/components/TempDesignSystem/Button" import Button from "@/components/TempDesignSystem/Button"
@@ -55,6 +57,12 @@ export default function Map({
const intl = useIntl() const intl = useIntl()
const { activeFilters } = useDestinationDataStore((state) => ({
activeFilters: state.activeFilters,
}))
const hasActiveFilters = activeFilters.length > 0
const markers = getHotelMapMarkers(hotels) const markers = getHotelMapMarkers(hotels)
const geoJson = mapMarkerDataToGeoJson(markers) const geoJson = mapMarkerDataToGeoJson(markers)
const defaultCoordinates = defaultLocation const defaultCoordinates = defaultLocation
@@ -150,7 +158,10 @@ export default function Map({
defaultCoordinates={defaultCoordinates} defaultCoordinates={defaultCoordinates}
defaultZoom={defaultZoom} defaultZoom={defaultZoom}
> >
<MapContent geojson={geoJson} /> <MapContent
geojson={geoJson}
hasActiveFilters={hasActiveFilters}
/>
</DynamicMap> </DynamicMap>
</Dialog> </Dialog>
</Modal> </Modal>