Skip to content

Commit

Permalink
FE CCCV Zoom out to printable zoom on click
Browse files Browse the repository at this point in the history
  • Loading branch information
wtcarter committed Nov 29, 2024
1 parent 04f37c2 commit f36fcb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cccv/src/lib/useMapFocus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const useMapFocus = (
if (location.description) {
pin.setPopup(new mapboxgl.Popup({ closeButton: false }).setLngLat([location.longitude!, location.latitude!]).setHTML(location.description || '<></>'))
}

setFocusPin(pin)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/cccv/src/lib/zoomIntoFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default function zoomIntoFeatures(
padding: number = 200,
maxZoom: number = 20
) {
if (!focus) return
if (!focus)
return

const featureOrCollection =
(isFeatureCollection(focus) || isFeature(focus)) ? focus :
Expand Down
8 changes: 7 additions & 1 deletion packages/cccv/src/pages/MapPage/MapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,15 @@ export default function MapPage() {
clearErrors()
const clickedFeatures = getFeaturesUnderMouse(mapRef, e, BOUNDARY_LINES_LAYER)
if (clickedFeatures) {
if (mapRef.current?.getMap()?.getZoom() !== DEFAULT_ZOOM)
mapRef.current?.getMap().flyTo({
center: e.lngLat,
zoom: DEFAULT_ZOOM,
})
setSelectedLocation({
longitude: e.lngLat.lng, latitude: e.lngLat.lat,
boundary: clickedFeatures[0]
boundary: clickedFeatures[0],
zoom: DEFAULT_ZOOM,
})
}
}
Expand Down

0 comments on commit f36fcb5

Please sign in to comment.