Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix map use location zoom #323

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions canopeum_frontend/src/pages/MapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getSiteTypeIconKey, type SiteTypeID } from '@models/SiteType'
import type { SiteMap } from '@services/api'
import { getApiBaseUrl } from '@services/apiSettings'

const PIN_FOCUS_ZOOM_LEVEL = 15
const PIN_FOCUS_ZOOM_LEVEL = 12
const MAP_DISTANCE_ZOOM_MULTIPLIER = 20

/**
Expand Down Expand Up @@ -131,7 +131,11 @@ const MapPage = () => {
initialMapState = defaultMapLocation(fetchedSites)
} else {
// Otherwise focus on the user's position
initialMapState = position.coords
// NOTE: Can't spread or clone a GeolocationPosition !
initialMapState = {
longitude: position.coords.longitude,
latitude: position.coords.latitude,
}
}
setMapViewState(mvs => ({ ...mvs, ...initialMapState }))
}), [fetchData, searchParams])
Expand All @@ -153,8 +157,11 @@ const MapPage = () => {
<NavigationControl position='top-right' showCompass showZoom visualizePitch />
<ScaleControl position='bottom-left' unit='metric' />
{sites.map(site => {
const latitude = Number(site.coordinate.ddLatitude)
const longitude = Number(site.coordinate.ddLongitude)
const latitude = site.coordinate.ddLatitude
const longitude = site.coordinate.ddLongitude

// Unset or invalid coordinate should be ignored from map pins
if (!latitude || !longitude) return

return (
<Marker
Expand All @@ -168,7 +175,7 @@ const MapPage = () => {
<SiteTypePin siteTypeId={site.siteType.id as SiteTypeID} />
</Marker>
)
})}
}).filter(Boolean)}
</ReactMap>
</div>

Expand Down
Loading