fix(SW-2449): Small cluster changes and added optional boundsPadding prop
This commit is contained in:
committed by
Michael Zetterberg
parent
b6c066ea8d
commit
21e7932058
@@ -26,6 +26,7 @@ export default async function OverviewMapContainer() {
|
|||||||
mapId={googleMapId}
|
mapId={googleMapId}
|
||||||
markers={markers}
|
markers={markers}
|
||||||
fitBounds
|
fitBounds
|
||||||
|
boundsPadding={0}
|
||||||
gestureHandling="cooperative"
|
gestureHandling="cooperative"
|
||||||
>
|
>
|
||||||
<MapContent geojson={geoJson} />
|
<MapContent geojson={geoJson} />
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ interface DynamicMapProps {
|
|||||||
defaultCenter?: google.maps.LatLngLiteral
|
defaultCenter?: google.maps.LatLngLiteral
|
||||||
defaultZoom?: number
|
defaultZoom?: number
|
||||||
fitBounds?: boolean
|
fitBounds?: boolean
|
||||||
|
boundsPadding?: number
|
||||||
gestureHandling?: "greedy" | "cooperative" | "auto" | "none"
|
gestureHandling?: "greedy" | "cooperative" | "auto" | "none"
|
||||||
onClose?: () => void
|
onClose?: () => void
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,7 @@ export default function DynamicMap({
|
|||||||
defaultCenter = BACKUP_COORDINATES,
|
defaultCenter = BACKUP_COORDINATES,
|
||||||
defaultZoom = 3,
|
defaultZoom = 3,
|
||||||
fitBounds = true,
|
fitBounds = true,
|
||||||
|
boundsPadding = 100,
|
||||||
onClose,
|
onClose,
|
||||||
gestureHandling = "auto",
|
gestureHandling = "auto",
|
||||||
children,
|
children,
|
||||||
@@ -68,10 +70,10 @@ export default function DynamicMap({
|
|||||||
markers.forEach((marker) => {
|
markers.forEach((marker) => {
|
||||||
bounds.extend(marker.coordinates)
|
bounds.extend(marker.coordinates)
|
||||||
})
|
})
|
||||||
map.fitBounds(bounds, 100)
|
map.fitBounds(bounds, boundsPadding)
|
||||||
setHasFittedBounds(true)
|
setHasFittedBounds(true)
|
||||||
}
|
}
|
||||||
}, [map, fitBounds, markers, hasFittedBounds])
|
}, [map, fitBounds, markers, hasFittedBounds, boundsPadding])
|
||||||
|
|
||||||
useHandleKeyUp((event: KeyboardEvent) => {
|
useHandleKeyUp((event: KeyboardEvent) => {
|
||||||
if (event.key === "Escape" && onClose) {
|
if (event.key === "Escape" && onClose) {
|
||||||
|
|||||||
@@ -19,20 +19,20 @@ import type {
|
|||||||
|
|
||||||
interface MapContentProps {
|
interface MapContentProps {
|
||||||
geojson: MarkerGeojson
|
geojson: MarkerGeojson
|
||||||
hasActiveFilters?: boolean
|
disableClustering?: 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
|
||||||
// which is making the useSupercluster hook fail
|
// which is making the useSupercluster hook fail
|
||||||
|
// Options are defined according to the supercluster documentation: https://github.com/mapbox/supercluster/blob/main/README.md#options
|
||||||
const CLUSTER_OPTIONS = {
|
const CLUSTER_OPTIONS = {
|
||||||
extent: 256,
|
|
||||||
radius: 80,
|
|
||||||
maxZoom: 14,
|
maxZoom: 14,
|
||||||
|
extent: 256,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MapContent({
|
export default function MapContent({
|
||||||
geojson,
|
geojson,
|
||||||
hasActiveFilters,
|
disableClustering,
|
||||||
}: MapContentProps) {
|
}: MapContentProps) {
|
||||||
const { setActiveMarker, activeMarker } = useDestinationPageHotelsMapStore()
|
const { setActiveMarker, activeMarker } = useDestinationPageHotelsMapStore()
|
||||||
const map = useMap()
|
const map = useMap()
|
||||||
@@ -41,7 +41,7 @@ export default function MapContent({
|
|||||||
useSupercluster<MarkerProperties>(geojson, CLUSTER_OPTIONS)
|
useSupercluster<MarkerProperties>(geojson, CLUSTER_OPTIONS)
|
||||||
|
|
||||||
// Based on the length of active filters, we decide if should show clusters or individual markers
|
// Based on the length of active filters, we decide if should show clusters or individual markers
|
||||||
const markerList = hasActiveFilters ? geojson.features : clusters
|
const markerList = disableClustering ? geojson.features : clusters
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
map?.addListener("click", () => {
|
map?.addListener("click", () => {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export default function Map({
|
|||||||
fitBounds={!activeHotel}
|
fitBounds={!activeHotel}
|
||||||
gestureHandling="greedy"
|
gestureHandling="greedy"
|
||||||
>
|
>
|
||||||
<MapContent geojson={geoJson} hasActiveFilters={hasActiveFilters} />
|
<MapContent geojson={geoJson} disableClustering={hasActiveFilters} />
|
||||||
</DynamicMap>
|
</DynamicMap>
|
||||||
</div>
|
</div>
|
||||||
</MapProvider>
|
</MapProvider>
|
||||||
|
|||||||
Reference in New Issue
Block a user