@@ -103,15 +103,19 @@ import {
103
103
} from "../../../store/slices/ui.ts" ;
104
104
105
105
import { CESIUM_CONFIG } from "../../../config/app.config" ;
106
+ import { useLocation } from "react-router-dom" ;
106
107
107
108
// detect GPU support, disables 3d mode if not supported
108
109
let hasGPU = false ;
109
110
const setHasGPU = ( flag : boolean ) => ( hasGPU = flag ) ;
110
111
const testGPU = ( ) => detectWebGLContext ( setHasGPU ) ;
111
112
window . addEventListener ( "load" , testGPU , false ) ;
112
113
114
+ // TODO: centralize the hash params update behavior
115
+
113
116
const MapWrapper = ( ) => {
114
117
const dispatch = useDispatch ( ) ;
118
+ const { pathname } = useLocation ( ) ;
115
119
116
120
const flags = useFeatureFlags ( ) ;
117
121
@@ -252,6 +256,27 @@ const MapWrapper = () => {
252
256
const { gazData } = useGazData ( ) ;
253
257
const { width, height } = useWindowSize ( wrapperRef ) ;
254
258
259
+ const clear3dHashParams = ( ) => {
260
+ console . debug ( "[CESIUM|DEBUG] MapTypeSwitcher: 2D mode, clear hash params" ) ;
261
+
262
+ const only3d = cesiumCameraParamsKeyList . filter (
263
+ ( k ) => ! [ "lng" , "lat" ] . includes ( k ) // keep lng and lat for consistency
264
+ ) ;
265
+
266
+ const clearValues = only3d . reduce (
267
+ ( acc , key ) => {
268
+ acc [ key ] = "" ;
269
+ return acc ;
270
+ } ,
271
+ { is3d : "" }
272
+ ) ;
273
+ replaceHashRoutedHistory (
274
+ { hashParams : clearValues } ,
275
+ pathname ,
276
+ "MapTypeSwitcher Clear"
277
+ ) ;
278
+ } ;
279
+
255
280
const handleToggleMeasurement = ( ) => {
256
281
cancelOngoingRequests ( ) ;
257
282
dispatch ( toggleUIMode ( UIMode . MEASUREMENT ) ) ;
@@ -419,25 +444,7 @@ const MapWrapper = () => {
419
444
duration = { CESIUM_CONFIG . transitions . mapMode . duration }
420
445
className = "!rounded-t-none !border-t-[1px]"
421
446
onComplete = { ( isTo2d : boolean ) => {
422
- isTo2d &&
423
- ( ( ) => {
424
- console . debug (
425
- "[CESIUM|DEBUG] MapTypeSwitcher: 2D mode, clear hash params"
426
- ) ;
427
- const clearValues = cesiumCameraParamsKeyList . reduce (
428
- ( acc , key ) => {
429
- acc [ key ] = "" ;
430
- return acc ;
431
- } ,
432
- { is3d : "" }
433
- ) ;
434
- replaceHashRoutedHistory (
435
- { hashParams : clearValues } ,
436
- location . pathname ,
437
- "MapTypeSwitcher Clear"
438
- ) ;
439
- } ) ( ) ;
440
-
447
+ isTo2d && clear3dHashParams ( ) ;
441
448
//dispatch(setBackgroundLayer({ ...backgroundLayer, visible: isTo2d }));
442
449
} }
443
450
ref = { tourRefLabels . toggle2d3d }
0 commit comments