Skip to content

Commit

Permalink
set max zoom on init if bounds are too small
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Aug 14, 2023
1 parent 8bebced commit 620558b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const forGoogleMaps = async ({ input }: TRPCHandlerParams<TForGoogleMapsS
result.length === 1 && result.at(0)?.latitude && result.at(0)?.longitude
? ({ lat: result.at(0)!.latitude, lng: result.at(0)!.longitude } as { lat: number; lng: number })
: getCenter(coordsForBounds)
const zoom = result.length === 1 ? 11 : null
const zoom = result.length === 1 ? 17 : null

return {
locations: result,
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/components/core/GoogleMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const MapRenderer = memo(({ height, width }: MapRendererProps) => {
isFractionalZoomEnabled: true,
})
const newInfoWindow = new google.maps.InfoWindow()

setMap(newMap)
setInfoWindow(newInfoWindow)
mapEvents.ready.emit(true)
Expand Down Expand Up @@ -49,6 +50,9 @@ export const GoogleMap = ({ height, width, locationIds }: GoogleMapProps) => {
if (bounds) {
map.fitBounds(bounds)
map.panToBounds(bounds)
if (map.getZoom() ?? 0 > 16) {
map.setZoom(16)
}
}
camera.center = center
camera.zoom = zoom ?? map.getZoom()
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/sections/LocationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const LocationCard = ({ remoteOnly, locationId }: LocationCardProps) => {
const locationCoords = new google.maps.LatLng({ lat: data.latitude, lng: data.longitude })
const locationView: google.maps.CameraOptions = {
center: locationCoords.toJSON(),
zoom: 15,
zoom: 17,
}
const zoomIn = new Tween(camera)
.to(locationView, 2000)
Expand Down

0 comments on commit 620558b

Please sign in to comment.