@masterportal/masterportalapi 2.47.0 → 2.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -11
- package/package.json +1 -1
- package/src/maps/olcs/olcsMap.js +57 -64
- package/test/map.test.js +102 -43
package/CHANGELOG.md
CHANGED
|
@@ -3,19 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
|
|
5
5
|
|
|
6
|
-
##
|
|
7
|
-
|
|
8
|
-
### __Breaking Changes__
|
|
9
|
-
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
### Changed
|
|
13
|
-
|
|
14
|
-
### Deprecated
|
|
15
|
-
|
|
16
|
-
### Removed
|
|
6
|
+
## 2.48.0 - 2025-04-01
|
|
17
7
|
|
|
18
8
|
### Fixed
|
|
9
|
+
- olcsMap: fixed function setCameraParameter.
|
|
19
10
|
|
|
20
11
|
---
|
|
21
12
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masterportal/masterportalapi",
|
|
3
3
|
"author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.48.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Basic functions of the Masterportal as api",
|
|
7
7
|
"repository": {
|
package/src/maps/olcs/olcsMap.js
CHANGED
|
@@ -9,91 +9,84 @@ import defaults from "../../defaults";
|
|
|
9
9
|
let mapIdCounter = 0;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* Recursively sets parameters on the Cesium scene.
|
|
13
|
+
*
|
|
14
|
+
* Certain keys are excluded from being set directly on the scene object:
|
|
15
|
+
* - "0", "1", "2": These is placeholder keys or indices from certain configurations that should not be interpreted as scene properties.
|
|
16
|
+
* - "heading", "tilt", "altitude": These are camera-related properties and should be handled separately via specific camera functions.
|
|
17
|
+
*
|
|
18
|
+
* @param {Cesium.Scene} scene - The Cesium scene instance.
|
|
19
|
+
* @param {Object} params - Configuration parameters.
|
|
16
20
|
* @returns {void}
|
|
17
21
|
*/
|
|
18
22
|
export function setCesiumSceneParams (scene, params) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (!scene || !params || typeof params !== "object") {
|
|
24
|
+
console.warn("setCesiumSceneParams: Invalid scene or params.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
29
|
+
if (["0", "1", "2", "heading", "tilt", "altitude"].includes(key)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof value === "object" && scene[key]) {
|
|
34
|
+
setCesiumSceneParams(scene[key], value);
|
|
28
35
|
}
|
|
29
36
|
else {
|
|
30
|
-
scene[
|
|
37
|
+
scene[key] = value;
|
|
31
38
|
}
|
|
32
39
|
});
|
|
33
40
|
}
|
|
34
41
|
/**
|
|
35
42
|
* Sets the camera parameters either from config or from an trigger.
|
|
36
|
-
* @param {Object} params
|
|
37
|
-
* @param {Object} map3D olcs map.
|
|
38
|
-
* @param {Cesium} cesium
|
|
43
|
+
* @param {Object} params - Parameters for setting the camera.
|
|
44
|
+
* @param {Object} map3D - olcs map instance.
|
|
45
|
+
* @param {Cesium} cesium - Cesium instance.
|
|
39
46
|
* @returns {void}
|
|
40
47
|
*/
|
|
41
48
|
export function setCameraParameter (params, map3D, cesium) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
destination = cesium.Cartesian3.fromDegrees(params.cameraPosition[0], params.cameraPosition[1], params.cameraPosition[2]);
|
|
49
|
+
if (!params || !map3D) {
|
|
50
|
+
console.warn("setCameraParameter: Missing parameters or map3D instance.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let camera = map3D.getCesiumScene()?.camera;
|
|
55
|
+
const heading = parseFloat(params.heading ?? params.camera?.heading ?? 0),
|
|
56
|
+
pitch = parseFloat(params.pitch ?? params.camera?.pitch ?? 0),
|
|
57
|
+
roll = parseFloat(params.roll ?? 0),
|
|
58
|
+
tilt = parseFloat(params.tilt ?? params.camera?.tilt ?? 0),
|
|
59
|
+
altitude = parseFloat(params.altitude ?? params.camera?.altitude ?? 0);
|
|
60
|
+
|
|
61
|
+
if (params.cameraPosition || params.camera?.cameraPosition) {
|
|
62
|
+
const cameraPosition = params.cameraPosition ?? params.camera.cameraPosition,
|
|
63
|
+
destination = cesium.Cartesian3.fromDegrees(cameraPosition[0], cameraPosition[1], cameraPosition[2]),
|
|
58
64
|
orientation = {
|
|
59
65
|
heading: cesium.Math.toRadians(heading),
|
|
60
|
-
pitch: cesium.Math.toRadians(
|
|
61
|
-
roll: cesium.Math.toRadians(
|
|
66
|
+
pitch: cesium.Math.toRadians(pitch),
|
|
67
|
+
roll: cesium.Math.toRadians(roll)
|
|
62
68
|
};
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
orientation
|
|
67
|
-
});
|
|
70
|
+
if (params.cameraPosition) {
|
|
71
|
+
camera.setView({destination, orientation});
|
|
68
72
|
}
|
|
69
73
|
else {
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
camera.flyTo({destination, orientation});
|
|
75
|
+
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
else if (typeof params.camera?.tilt !== "undefined") {
|
|
77
|
-
tilt = parseFloat(params.camera?.tilt);
|
|
78
|
-
}
|
|
79
|
-
if (typeof params.altitude !== "undefined") {
|
|
80
|
-
altitude = parseFloat(params.altitude);
|
|
81
|
-
}
|
|
82
|
-
else if (typeof params.camera?.altitude !== "undefined") {
|
|
83
|
-
altitude = parseFloat(params.camera?.altitude);
|
|
84
|
-
}
|
|
85
|
-
camera = map3D.getCamera();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
camera = map3D.getCamera();
|
|
81
|
+
|
|
82
|
+
if (tilt) {
|
|
83
|
+
camera.setTilt(tilt);
|
|
84
|
+
}
|
|
85
|
+
if (heading) {
|
|
86
|
+
camera.setHeading(heading);
|
|
87
|
+
}
|
|
88
|
+
if (altitude) {
|
|
89
|
+
camera.setAltitude(altitude);
|
|
97
90
|
}
|
|
98
91
|
}
|
|
99
92
|
|
package/test/map.test.js
CHANGED
|
@@ -72,7 +72,7 @@ describe("map.js", function () {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
cesiumLib: "https://
|
|
75
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
@@ -165,7 +165,7 @@ describe("map.js", function () {
|
|
|
165
165
|
heading: -0.30858728378862876,
|
|
166
166
|
tilt: 0.9321791580603296
|
|
167
167
|
},
|
|
168
|
-
cesiumLib: "https://
|
|
168
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
@@ -200,7 +200,7 @@ describe("map.js", function () {
|
|
|
200
200
|
tilt: 0.9321791580603296
|
|
201
201
|
}
|
|
202
202
|
},
|
|
203
|
-
cesiumLib: "https://
|
|
203
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
204
204
|
};
|
|
205
205
|
|
|
206
206
|
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
@@ -213,48 +213,108 @@ describe("map.js", function () {
|
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
215
|
it("set the camera from viewpoint parameter", function () {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
216
|
+
const mockFlyTo = jest.fn(),
|
|
217
|
+
config = {
|
|
218
|
+
map2D: {
|
|
219
|
+
getView: () => {
|
|
220
|
+
return {
|
|
221
|
+
getProjection: () => {
|
|
222
|
+
return {getCode: () => "code"};
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
getViewport: () => {
|
|
227
|
+
return {
|
|
228
|
+
appendChild: jest.fn()
|
|
229
|
+
};
|
|
230
|
+
}
|
|
224
231
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
9.983171185370468,
|
|
239
|
-
53.54328139366739,
|
|
240
|
-
-0.00449886760542777
|
|
241
|
-
],
|
|
242
|
-
"heading": 3.281512334248587,
|
|
243
|
-
"pitch": -45.35612834848329,
|
|
244
|
-
"roll": 0.015054499334397243,
|
|
245
|
-
"animate": false,
|
|
246
|
-
"duration": 6.006336273348537
|
|
247
|
-
}],
|
|
248
|
-
cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
|
|
249
|
-
};
|
|
232
|
+
viewpoint: [{
|
|
233
|
+
"distance": 1660.0290142521517,
|
|
234
|
+
"cameraPosition": [
|
|
235
|
+
9.982163927085617,
|
|
236
|
+
53.532817572762475,
|
|
237
|
+
1180.9805498821436
|
|
238
|
+
],
|
|
239
|
+
"heading": 3.281512334248587,
|
|
240
|
+
"pitch": -45.35612834848329,
|
|
241
|
+
"roll": 0.015054499334397243
|
|
242
|
+
}],
|
|
243
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
244
|
+
};
|
|
250
245
|
|
|
251
246
|
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
252
|
-
const
|
|
247
|
+
const mockMap3D = {
|
|
248
|
+
mapMode: "3D",
|
|
249
|
+
getCesiumScene: () => ({
|
|
250
|
+
camera: {
|
|
251
|
+
flyTo: mockFlyTo
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
};
|
|
253
255
|
|
|
254
|
-
|
|
255
|
-
map.setCameraParameter(config.viewpoint, map3D, config.cesiumLib);
|
|
256
|
+
map.setCameraParameter(config.viewpoint, mockMap3D, config.cesiumLib);
|
|
256
257
|
|
|
257
|
-
|
|
258
|
+
expect(mockFlyTo).toHaveBeenCalledWith(expect.objectContaining({
|
|
259
|
+
destination: expect.any(Object),
|
|
260
|
+
orientation: {
|
|
261
|
+
heading: expect.any(Number),
|
|
262
|
+
pitch: expect.any(Number),
|
|
263
|
+
roll: expect.any(Number)
|
|
264
|
+
},
|
|
265
|
+
duration: config.viewpoint[0].duration
|
|
266
|
+
}));
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("sets the camera parameters when cameraPosition is not provided", function () {
|
|
271
|
+
const mockFlyTo = jest.fn(),
|
|
272
|
+
config = {
|
|
273
|
+
map2D: {
|
|
274
|
+
getView: () => {
|
|
275
|
+
return {
|
|
276
|
+
getProjection: () => {
|
|
277
|
+
return {getCode: () => "code"};
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
getViewport: () => {
|
|
282
|
+
return {
|
|
283
|
+
appendChild: jest.fn()
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
viewpoint: [{
|
|
288
|
+
"distance": 1660.0290142521517,
|
|
289
|
+
"heading": 3.281512334248587,
|
|
290
|
+
"pitch": -45.35612834848329,
|
|
291
|
+
"roll": 0.015054499334397243,
|
|
292
|
+
"tilt": 10,
|
|
293
|
+
"altitude": 1500
|
|
294
|
+
}],
|
|
295
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
299
|
+
const mockMap3D = {
|
|
300
|
+
mapMode: "3D",
|
|
301
|
+
getCesiumScene: () => ({
|
|
302
|
+
camera: {
|
|
303
|
+
flyTo: mockFlyTo,
|
|
304
|
+
setTilt: jest.fn(),
|
|
305
|
+
setHeading: jest.fn(),
|
|
306
|
+
setAltitude: jest.fn()
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
map.setCameraParameter(config.viewpoint[0], mockMap3D, config.cesiumLib);
|
|
312
|
+
|
|
313
|
+
expect(mockFlyTo).not.toHaveBeenCalled();
|
|
314
|
+
|
|
315
|
+
expect(mockMap3D.getCesiumScene().camera.setTilt).toHaveBeenCalledWith(10);
|
|
316
|
+
expect(mockMap3D.getCesiumScene().camera.setHeading).toHaveBeenCalledWith(3.281512334248587);
|
|
317
|
+
expect(mockMap3D.getCesiumScene().camera.setAltitude).toHaveBeenCalledWith(1500);
|
|
258
318
|
});
|
|
259
319
|
});
|
|
260
320
|
});
|
|
@@ -281,7 +341,7 @@ describe("map.js", function () {
|
|
|
281
341
|
heading: -0.30858728378862876,
|
|
282
342
|
tilt: 0.9321791580603296
|
|
283
343
|
},
|
|
284
|
-
cesiumLib: "https://
|
|
344
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
285
345
|
};
|
|
286
346
|
|
|
287
347
|
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
@@ -339,7 +399,7 @@ describe("map.js", function () {
|
|
|
339
399
|
undergroundColor: undefined
|
|
340
400
|
}
|
|
341
401
|
},
|
|
342
|
-
cesiumLib: "https://
|
|
402
|
+
cesiumLib: "https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js"
|
|
343
403
|
};
|
|
344
404
|
|
|
345
405
|
load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
@@ -355,5 +415,4 @@ describe("map.js", function () {
|
|
|
355
415
|
});
|
|
356
416
|
});
|
|
357
417
|
});
|
|
358
|
-
|
|
359
418
|
});
|