Skip to content

Commit daee4ef

Browse files
committed
WIP use proper path for routing on hash replacements
1 parent 3cdc987 commit daee4ef

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

apps/geoportal/src/app/components/GeoportalMap/GeoportalMap.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ interface MapProps {
9595
export const GeoportalMap = ({ height, width, allow3d }: MapProps) => {
9696
const dispatch = useDispatch();
9797

98-
const location = useLocation();
98+
const { pathname } = useLocation();
9999
const rerenderCountRef = useRef(0);
100100
const lastRenderTimeStampRef = useRef(Date.now());
101101
const lastRenderIntervalRef = useRef(0);
@@ -334,7 +334,7 @@ export const GeoportalMap = ({ height, width, allow3d }: MapProps) => {
334334

335335
replaceHashRoutedHistory(
336336
{ hashParams: newParams },
337-
location.pathname,
337+
pathname,
338338
"GPM:TopicMap:locationChangedHandler"
339339
);
340340

@@ -354,7 +354,7 @@ export const GeoportalMap = ({ height, width, allow3d }: MapProps) => {
354354
);
355355
return;
356356
}
357-
replaceHashRoutedHistory(e, location.pathname, "GPM:3D");
357+
replaceHashRoutedHistory(e, pathname, "GPM:3D");
358358
};
359359

360360
// TODO Move out Controls to own component

apps/geoportal/src/app/components/GeoportalMap/controls/MapWrapper.tsx

+26-19
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,19 @@ import {
103103
} from "../../../store/slices/ui.ts";
104104

105105
import { CESIUM_CONFIG } from "../../../config/app.config";
106+
import { useLocation } from "react-router-dom";
106107

107108
// detect GPU support, disables 3d mode if not supported
108109
let hasGPU = false;
109110
const setHasGPU = (flag: boolean) => (hasGPU = flag);
110111
const testGPU = () => detectWebGLContext(setHasGPU);
111112
window.addEventListener("load", testGPU, false);
112113

114+
// TODO: centralize the hash params update behavior
115+
113116
const MapWrapper = () => {
114117
const dispatch = useDispatch();
118+
const { pathname } = useLocation();
115119

116120
const flags = useFeatureFlags();
117121

@@ -252,6 +256,27 @@ const MapWrapper = () => {
252256
const { gazData } = useGazData();
253257
const { width, height } = useWindowSize(wrapperRef);
254258

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+
255280
const handleToggleMeasurement = () => {
256281
cancelOngoingRequests();
257282
dispatch(toggleUIMode(UIMode.MEASUREMENT));
@@ -419,25 +444,7 @@ const MapWrapper = () => {
419444
duration={CESIUM_CONFIG.transitions.mapMode.duration}
420445
className="!rounded-t-none !border-t-[1px]"
421446
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();
441448
//dispatch(setBackgroundLayer({ ...backgroundLayer, visible: isTo2d }));
442449
}}
443450
ref={tourRefLabels.toggle2d3d}

0 commit comments

Comments
 (0)