Skip to content

Commit 1d62820

Browse files
committed
force removing 3d params when updating 2D state urls
1 parent daee4ef commit 1d62820

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { getApplicationVersion } from "@carma-commons/utils";
3535

3636
import {
3737
CustomViewer,
38+
getClearCesiumCameraParams,
3839
selectCurrentSceneStyle,
3940
selectShowPrimaryTileset,
4041
selectViewerIsMode2d,
@@ -84,14 +85,15 @@ import { CESIUM_CONFIG, LEAFLET_CONFIG } from "../../config/app.config";
8485

8586
import "cesium/Build/Cesium/Widgets/widgets.css";
8687
import "../leaflet.css";
87-
import { on } from "events";
8888

8989
interface MapProps {
9090
height: number;
9191
width: number;
9292
allow3d?: boolean;
9393
}
9494

95+
const clear3dParams = getClearCesiumCameraParams();
96+
9597
export const GeoportalMap = ({ height, width, allow3d }: MapProps) => {
9698
const dispatch = useDispatch();
9799

@@ -326,6 +328,7 @@ export const GeoportalMap = ({ height, width, allow3d }: MapProps) => {
326328

327329
const newParams = {
328330
...currentParams,
331+
...clear3dParams,
329332
m: sceneStyle,
330333
lat: latTruncated,
331334
lng: lngTruncated,

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

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useContext, useEffect, useMemo, useRef, useState } from "react";
2+
import { useLocation } from "react-router-dom";
23
import { isMobile } from "react-device-detect";
34
import { useDispatch, useSelector } from "react-redux";
45

@@ -39,7 +40,7 @@ import { ENDPOINT, isAreaType } from "@carma-commons/resources";
3940
import { detectWebGLContext } from "@carma-commons/utils";
4041

4142
import {
42-
cesiumCameraParamsKeyList,
43+
getClearCesiumCameraParams,
4344
MapTypeSwitcher,
4445
PitchingCompass,
4546
selectViewerIsMode2d,
@@ -103,14 +104,15 @@ import {
103104
} from "../../../store/slices/ui.ts";
104105

105106
import { CESIUM_CONFIG } from "../../../config/app.config";
106-
import { useLocation } from "react-router-dom";
107107

108108
// detect GPU support, disables 3d mode if not supported
109109
let hasGPU = false;
110110
const setHasGPU = (flag: boolean) => (hasGPU = flag);
111111
const testGPU = () => detectWebGLContext(setHasGPU);
112112
window.addEventListener("load", testGPU, false);
113113

114+
const clear3dHashParamsObject = getClearCesiumCameraParams();
115+
114116
// TODO: centralize the hash params update behavior
115117

116118
const MapWrapper = () => {
@@ -258,20 +260,8 @@ const MapWrapper = () => {
258260

259261
const clear3dHashParams = () => {
260262
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-
);
273263
replaceHashRoutedHistory(
274-
{ hashParams: clearValues },
264+
{ hashParams: clear3dHashParamsObject },
275265
pathname,
276266
"MapTypeSwitcher Clear"
277267
);

libraries/mapping/engines/cesium/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export {
5252
encodeCesiumCamera,
5353
decodeCesiumCamera,
5454
cesiumCameraParamsKeyList,
55+
getClearCesiumCameraParams,
5556
} from "./lib/utils/cesiumHashParamsCodec";
5657

5758
export {

libraries/mapping/engines/cesium/src/lib/utils/cesiumHashParamsCodec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ export const cesiumCameraParamsKeyList = Object.values(cameraCodec).map(
7373
(codec) => codec.key
7474
);
7575

76+
export const getClearCesiumCameraParams = (emptyValue = "") => {
77+
const only3d = cesiumCameraParamsKeyList.filter(
78+
(k) => !["lng", "lat"].includes(k) // keep lng and lat for consistency
79+
);
80+
81+
const clearValues = only3d.reduce(
82+
(acc, key) => {
83+
acc[key] = emptyValue;
84+
return acc;
85+
},
86+
{ is3d: emptyValue }
87+
);
88+
return clearValues;
89+
};
90+
7691
function isNumber(value: unknown): value is number {
7792
return (
7893
value !== undefined &&

0 commit comments

Comments
 (0)