1
- import { BoothPopup } from "@/app/student/map/_components/BoothPopup"
2
1
import {
3
2
BoothID ,
4
3
geoJsonBoothDataByLocation
5
4
} from "@/app/student/map/lib/booths"
6
- import { Location } from "@/app/student/map/lib/locations"
5
+ import { Location , LocationId } from "@/app/student/map/lib/locations"
7
6
import { useFeatureState } from "@/components/shared/hooks/useFeatureState"
8
7
import { useGeoJsonPlanData } from "@/components/shared/hooks/useGeoJsonPlanData"
9
8
import "maplibre-gl/dist/maplibre-gl.css"
@@ -20,6 +19,7 @@ import {
20
19
addMapIconAssets ,
21
20
backgroundLayerStyle ,
22
21
boothLayerStyle ,
22
+ boothOutlineStyle ,
23
23
buildingLayerStyle ,
24
24
lineLayerStyle ,
25
25
roomLayerStyle ,
@@ -49,15 +49,21 @@ export function MapComponent({
49
49
} ) {
50
50
const mapRef = useRef < MapRef > ( null )
51
51
52
+ const [ mapZoom , setMapZoom ] = useState ( initialView . zoom )
53
+
52
54
const [ markerScale , setMarkerScale ] = useState ( 1 )
53
55
56
+ const [ preLocationId , setPreLocationId ] = useState < LocationId > ( location . id )
54
57
// Fly to location center on change
55
58
useEffect ( ( ) => {
56
59
const { longitude, latitude, zoom } = location . center
57
- mapRef . current ?. flyTo ( {
58
- center : [ longitude , latitude ] ,
59
- zoom : zoom
60
- } )
60
+ const timeout = setTimeout ( ( ) => {
61
+ mapRef . current ?. flyTo ( {
62
+ center : [ longitude , latitude ] ,
63
+ zoom
64
+ } )
65
+ } , 300 )
66
+ return ( ) => clearTimeout ( timeout )
61
67
setMarkerScale ( 0.6 )
62
68
} , [ location ] )
63
69
@@ -79,7 +85,7 @@ export function MapComponent({
79
85
if ( ! booth ) return
80
86
mapRef . current ?. flyTo ( {
81
87
center : booth . center as [ number , number ] ,
82
- zoom : 21 ,
88
+ zoom : 20 ,
83
89
speed : 0.8
84
90
} )
85
91
} , [ activeBoothId , boothsById ] )
@@ -88,10 +94,28 @@ export function MapComponent({
88
94
useFeatureState ( mapRef , hoveredBoothId ? [ hoveredBoothId ] : [ ] , "hover" )
89
95
useFeatureState ( mapRef , filteredBoothIds , "filtered" )
90
96
91
- const activeBooth =
92
- activeBoothId != null ? boothsById . get ( activeBoothId ) : null
93
-
94
- const currentGeoJsonBoothData = geoJsonBoothDataByLocation . get ( location . id ) !
97
+ const currentGeoJsonBoothData = useMemo ( ( ) => {
98
+ const currentData = geoJsonBoothDataByLocation . get (
99
+ location . id === "library" ? preLocationId : location . id
100
+ ) ?? {
101
+ type : "FeatureCollection" ,
102
+ features : [ ]
103
+ }
104
+ const libraryFeatures = geoJsonBoothDataByLocation . get ( "library" ) ! . features
105
+ // Merge library features with the current location's features
106
+ const mergedFeatures = [
107
+ ...libraryFeatures ,
108
+ ...currentData . features . filter (
109
+ feature =>
110
+ ! libraryFeatures . some (
111
+ libraryFeature =>
112
+ libraryFeature . properties . id === feature . properties . id
113
+ )
114
+ )
115
+ ]
116
+ setPreLocationId ( location . id )
117
+ return { ...currentData , features : mergedFeatures }
118
+ } , [ location . id ] )
95
119
96
120
// Don't want to rerender markers on every map render
97
121
const markers = useMemo (
@@ -132,8 +156,9 @@ export function MapComponent({
132
156
function onZoomChange ( ) {
133
157
const zoom = mapRef . current ?. getZoom ( )
134
158
if ( zoom === undefined ) return
135
- const scale = Math . max ( 0.3 , Math . min ( 2 , 1 + ( zoom - 20 ) * 0.5 ) )
159
+ const scale = Math . max ( 0.2 , Math . min ( 1 , 1 + ( zoom - 20 ) * 0.5 ) )
136
160
setMarkerScale ( scale )
161
+ setMapZoom ( zoom )
137
162
}
138
163
139
164
return (
@@ -153,7 +178,7 @@ export function MapComponent({
153
178
[ 18.063 , 59.345 ] ,
154
179
[ 18.079 , 59.35 ]
155
180
] }
156
- mapStyle = "https://api.maptiler.com/maps/977e9770-60b4-4b8a-94e9-a9fa8db4c68d /style.json?key=57xj41WPFBbOEWiVSSwL " >
181
+ mapStyle = "https://api.maptiler.com/maps/376fa556-c405-4a91-8e9e-15be82eb3a58 /style.json?key=mgMcr2yF2fWUHzf27ygv " >
157
182
< Layer { ...backgroundLayerStyle } > </ Layer >
158
183
159
184
{ /** Order sensitive! */ }
@@ -182,31 +207,42 @@ export function MapComponent({
182
207
</ Source >
183
208
184
209
< Source
185
- id = "nymble-plan-style "
210
+ id = "booths-outline "
186
211
type = "geojson"
187
212
promoteId = { "id" }
188
- data = { geoJsonPlanData } >
189
- < Layer { ...lineLayerStyle } > </ Layer >
190
- </ Source >
191
-
192
- < Source
193
- id = "nymble-plan-routes"
194
- type = "geojson"
195
- promoteId = { "id" }
196
- data = { geoJsonPlanRoutesData } >
197
- < Layer { ...routeLayerStyle } > </ Layer >
213
+ data = { currentGeoJsonBoothData } >
214
+ < Layer { ...boothOutlineStyle } > </ Layer >
198
215
</ Source >
199
216
200
217
< Source
201
- id = "nymble-plan-points "
218
+ id = "nymble-plan-style "
202
219
type = "geojson"
203
220
promoteId = { "id" }
204
221
data = { geoJsonPlanData } >
205
- < Layer { ...symbolLayerStyle } > </ Layer >
222
+ < Layer { ...lineLayerStyle } > </ Layer >
206
223
</ Source >
207
224
225
+ { mapZoom > 19 && (
226
+ < Source
227
+ id = "nymble-plan-routes"
228
+ type = "geojson"
229
+ promoteId = { "id" }
230
+ data = { geoJsonPlanRoutesData } >
231
+ < Layer { ...routeLayerStyle } > </ Layer >
232
+ </ Source >
233
+ ) }
234
+
235
+ { mapZoom > 19 && (
236
+ < Source
237
+ id = "nymble-plan-points"
238
+ type = "geojson"
239
+ promoteId = { "id" }
240
+ data = { geoJsonPlanData } >
241
+ < Layer { ...symbolLayerStyle } > </ Layer >
242
+ </ Source >
243
+ ) }
244
+
208
245
{ markers }
209
- { activeBooth && < BoothPopup key = { activeBooth . id } booth = { activeBooth } /> }
210
246
</ MapboxMap >
211
247
</ div >
212
248
)
0 commit comments