Skip to content

Commit

Permalink
Merge pull request #114 from armada-ths/feat/map
Browse files Browse the repository at this point in the history
Fix lat/lon param zoom in, booth fix and label fix
  • Loading branch information
AmiyaSX authored Nov 17, 2024
2 parents d656323 + b836326 commit 1344b29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/app/student/map/_components/MapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Location, LocationId } from "@/app/student/map/lib/locations"
import { useFeatureState } from "@/components/shared/hooks/useFeatureState"
import { useGeoJsonPlanData } from "@/components/shared/hooks/useGeoJsonPlanData"
import "maplibre-gl/dist/maplibre-gl.css"
import { useSearchParams } from "next/navigation"
import { useEffect, useMemo, useRef, useState } from "react"
import {
Layer,
Expand Down Expand Up @@ -47,6 +48,8 @@ export function MapComponent({
initialView: { longitude: number; latitude: number; zoom: number }
filteredBoothIds: BoothID[]
}) {
const searchParams = useSearchParams()

const mapRef = useRef<MapRef>(null)

const [mapZoom, setMapZoom] = useState(initialView.zoom)
Expand All @@ -56,15 +59,21 @@ export function MapComponent({
const [preLocationId, setPreLocationId] = useState<LocationId>(location.id)
// Fly to location center on change
useEffect(() => {
const hasSearchParams = searchParams.has("lat") || searchParams.has("lng")
const { longitude, latitude, zoom } = location.center
const timeout = setTimeout(() => {
mapRef.current?.flyTo({
center: [longitude, latitude],
zoom
})
if (!hasSearchParams) {
mapRef.current?.flyTo({
center: [longitude, latitude],
zoom
})
}
// Remove the search params
const { pathname } = window.location
window.history.replaceState(null, "", pathname)
}, 300)
return () => clearTimeout(timeout)
setMarkerScale(0.6)
return () => clearTimeout(timeout)
}, [location])

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/student/map/data/booths.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"properties": {
"id": 5,
"location": "nymble/2",
"exhibitorId": 1536
"exhibitorId": 1543
},
"geometry": {
"coordinates": [
Expand Down
4 changes: 2 additions & 2 deletions src/app/student/map/lib/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const libraryCenter = {
export const locations: Location[] = [
{
id: "nymble/2",
label: "Nymble-floor2",
label: "Nymble Floor2",
center: nymbleCenter
},
{
id: "nymble/3",
label: "Nymble-floor3",
label: "Nymble Floor3",
center: nymbleCenter
},
{
Expand Down

0 comments on commit 1344b29

Please sign in to comment.