@@ -6,6 +6,7 @@ import { Location, LocationId } from "@/app/student/map/lib/locations"
6
6
import { useFeatureState } from "@/components/shared/hooks/useFeatureState"
7
7
import { useGeoJsonPlanData } from "@/components/shared/hooks/useGeoJsonPlanData"
8
8
import "maplibre-gl/dist/maplibre-gl.css"
9
+ import { useSearchParams } from "next/navigation"
9
10
import { useEffect , useMemo , useRef , useState } from "react"
10
11
import {
11
12
Layer ,
@@ -47,6 +48,8 @@ export function MapComponent({
47
48
initialView : { longitude : number ; latitude : number ; zoom : number }
48
49
filteredBoothIds : BoothID [ ]
49
50
} ) {
51
+ const searchParams = useSearchParams ( )
52
+
50
53
const mapRef = useRef < MapRef > ( null )
51
54
52
55
const [ mapZoom , setMapZoom ] = useState ( initialView . zoom )
@@ -56,15 +59,21 @@ export function MapComponent({
56
59
const [ preLocationId , setPreLocationId ] = useState < LocationId > ( location . id )
57
60
// Fly to location center on change
58
61
useEffect ( ( ) => {
62
+ const hasSearchParams = searchParams . has ( "lat" ) || searchParams . has ( "lng" )
59
63
const { longitude, latitude, zoom } = location . center
60
64
const timeout = setTimeout ( ( ) => {
61
- mapRef . current ?. flyTo ( {
62
- center : [ longitude , latitude ] ,
63
- zoom
64
- } )
65
+ if ( ! hasSearchParams ) {
66
+ mapRef . current ?. flyTo ( {
67
+ center : [ longitude , latitude ] ,
68
+ zoom
69
+ } )
70
+ }
71
+ // Remove the search params
72
+ const { pathname } = window . location
73
+ window . history . replaceState ( null , "" , pathname )
65
74
} , 300 )
66
- return ( ) => clearTimeout ( timeout )
67
75
setMarkerScale ( 0.6 )
76
+ return ( ) => clearTimeout ( timeout )
68
77
} , [ location ] )
69
78
70
79
useEffect ( ( ) => {
0 commit comments