@xgis/xgis3d 0.3.55 → 0.3.58
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/dist/cameraBoundsGuard.d.ts +3 -3
- package/dist/cameraScale.d.ts +2 -2
- package/dist/capabilities/cesiumCamera.d.ts +3 -2
- package/dist/capabilities/cesiumMoving.d.ts +2 -0
- package/dist/entryCamera.d.ts +3 -3
- package/dist/index.js +173 -66
- package/dist/index.js.map +1 -1
- package/dist/projection.d.ts +7 -41
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EpsgCode, MapExtent, ZoomLevel } from '@xgis/xgis-common';
|
|
2
2
|
import type { Viewer as CesiumViewer } from 'cesium';
|
|
3
3
|
/** Zoom at which `bounds` just fills the canvas — the furthest this camera may pull back. */
|
|
4
|
-
export declare function boundsFloor(viewer: CesiumViewer, bounds:
|
|
4
|
+
export declare function boundsFloor(viewer: CesiumViewer, bounds: MapExtent): ZoomLevel;
|
|
5
5
|
/** Cesium has no extent constraint, so the camera is pulled back each frame after it moves. */
|
|
6
|
-
export declare function createCameraBoundsGuard(viewer: CesiumViewer, bounds:
|
|
6
|
+
export declare function createCameraBoundsGuard(viewer: CesiumViewer, bounds: MapExtent, projection: EpsgCode): () => void;
|
package/dist/cameraScale.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ZoomLevel } from '@xgis/xgis-common';
|
|
2
2
|
import type { Viewer as CesiumViewer } from 'cesium';
|
|
3
3
|
/** Camera→focus range that renders `zoom` at the same ground scale as the 2D map. */
|
|
4
|
-
export declare function rangeForZoom(viewer: CesiumViewer, zoom: number): number;
|
|
4
|
+
export declare function rangeForZoom(viewer: CesiumViewer, zoom: number, metresPerUnit: number): number;
|
|
5
5
|
/** The 2D zoom whose resolution matches the ground scale at `range` — inverse of `rangeForZoom`. */
|
|
6
|
-
export declare function zoomForRange(viewer: CesiumViewer, range: number): number;
|
|
6
|
+
export declare function zoomForRange(viewer: CesiumViewer, range: number, metresPerUnit: number): number;
|
|
7
7
|
export declare function reportedZoomGrid(zoom: number): ZoomLevel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ICameraCapability } from '@xgis/xgis-common';
|
|
1
|
+
import type { EpsgCode, ICameraCapability } from '@xgis/xgis-common';
|
|
2
2
|
import type { Camera, TerrainProvider, Viewer as CesiumViewer } from 'cesium';
|
|
3
3
|
interface CameraFocus {
|
|
4
4
|
readonly lon: number;
|
|
@@ -17,5 +17,6 @@ export declare function sampleTerrainHeight(provider: TerrainProvider, position:
|
|
|
17
17
|
lon: number;
|
|
18
18
|
lat: number;
|
|
19
19
|
}): Promise<number | undefined>;
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function viewCenter(viewer: CesiumViewer, focus: CameraFocus | undefined): [number, number];
|
|
21
|
+
export declare function createCesiumCameraCapability(viewer: CesiumViewer, getProjection: () => EpsgCode): ICameraCapability;
|
|
21
22
|
export {};
|
package/dist/entryCamera.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EpsgCode, type MapExtent, type Radians, type ZoomLevel } from '@xgis/xgis-common';
|
|
2
2
|
import { type Viewer as CesiumViewer } from 'cesium';
|
|
3
3
|
export declare const ELLIPSOID_HEIGHT = 0;
|
|
4
4
|
export interface EntryView {
|
|
5
|
-
readonly bbox:
|
|
5
|
+
readonly bbox: MapExtent;
|
|
6
6
|
readonly zoom: ZoomLevel;
|
|
7
7
|
readonly rotation: Radians;
|
|
8
8
|
readonly pitch: Radians;
|
|
@@ -14,6 +14,6 @@ export interface EntryTarget {
|
|
|
14
14
|
readonly pitch: number;
|
|
15
15
|
readonly range: number;
|
|
16
16
|
}
|
|
17
|
-
export declare function entryTarget(viewer: CesiumViewer, view: EntryView): EntryTarget;
|
|
17
|
+
export declare function entryTarget(viewer: CesiumViewer, view: EntryView, projection: EpsgCode): EntryTarget;
|
|
18
18
|
export declare function placeEntryCamera(viewer: CesiumViewer, target: EntryTarget, height: number): void;
|
|
19
19
|
export declare function raiseEntryCameraToTerrain(viewer: CesiumViewer, target: EntryTarget, height: number): void;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import 'cesium/Build/Cesium/Widgets/widgets.css';
|
|
3
|
-
import {
|
|
4
|
-
import { Matrix4, BoundingSphere,
|
|
3
|
+
import { toWgs84, resolutionForZoom, fromWgs84, wrapToRange, TWO_PI, ZOOM_0_RESOLUTION, RADIANS_TO_DEGREES, extentCenter, zoomForExtent, asMapExtent, createEngineErrorChannel, WEBGL_CONTEXT_LOST_ERROR_NAME, zoomToFit, clampExtentToBounds, MIN_ZOOM, SHALLOWEST_PITCH, platformModifierOnly, KML_DEFAULT_COLOR, KML_LABEL_OUTLINE_COLOR, kmlExtractStyles, KML_LABEL_FONT, KML_MARKER_SIZE_PX, KML_LABEL_OUTLINE_PX, KML_LABEL_FONT_SIZE_PX, ogcMapsCesiumCrs, withQuery, ogcMapsMapUrl, ogcMapsQuery, stringifyParams, parseTmsTileMap, tmsCesiumSchemeFor, tmsLevelRange, tmsTileBase, tmsTileSuffix, parseWmsCaps, parseWmtsCapabilities, toAlpha, useBasemapStore, useActiveBasemapPlan, bus, translate, useProjectionStore, useMapViewStore, useTerrainStore, useUserMarkerStore, useTranslate, MAX_ZOOM } from '@xgis/xgis-common';
|
|
4
|
+
import { Cartesian3, Matrix4, BoundingSphere, HeadingPitchRange, Rectangle, Cartesian2, Transforms, Matrix3, Math as Math$1, EllipsoidTerrainProvider, Ellipsoid, Cartographic, sampleTerrainMostDetailed, CameraEventType, KeyboardEventModifier, Cesium3DTileStyle, I3SDataProvider, Cesium3DTileset, Color, ImageMaterialProperty, ColorMaterialProperty, ConstantProperty, Iso8601, ArcType, PointGraphics, Resource, HeightReference, PolygonHierarchy, KmlDataSource, UrlTemplateImageryProvider, WebMercatorTilingScheme, GeographicTilingScheme, WebMercatorProjection, WebMapServiceImageryProvider, WebMapTileServiceImageryProvider, CesiumTerrainProvider, ConstantPositionProperty } from 'cesium';
|
|
5
5
|
import { useRef, useMemo, useEffect, useState, useCallback } from 'react';
|
|
6
6
|
import { Viewer } from 'resium';
|
|
7
7
|
|
|
@@ -21,21 +21,37 @@ function ensureCesiumBaseUrl() {
|
|
|
21
21
|
}
|
|
22
22
|
ensureCesiumBaseUrl();
|
|
23
23
|
|
|
24
|
-
function
|
|
25
|
-
const { lon, lat } =
|
|
24
|
+
function mapToWgs84(projection, x, y) {
|
|
25
|
+
const { lon, lat } = toWgs84(projection, [x, y]);
|
|
26
26
|
return [lon, lat];
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return
|
|
28
|
+
function wgs84ToMap(projection, lon, lat) {
|
|
29
|
+
return fromWgs84(projection, { lon, lat });
|
|
30
|
+
}
|
|
31
|
+
function ellipsoidPoint(projection, x, y) {
|
|
32
|
+
const [lon, lat] = mapToWgs84(projection, x, y);
|
|
33
|
+
return Cartesian3.fromDegrees(lon, lat);
|
|
34
|
+
}
|
|
35
|
+
function metresPerMapUnit(projection, lon, lat) {
|
|
36
|
+
const [x, y] = wgs84ToMap(projection, lon, lat);
|
|
37
|
+
const east = Cartesian3.distance(
|
|
38
|
+
ellipsoidPoint(projection, x - 0.5, y),
|
|
39
|
+
ellipsoidPoint(projection, x + 0.5, y)
|
|
40
|
+
);
|
|
41
|
+
const north = Cartesian3.distance(
|
|
42
|
+
ellipsoidPoint(projection, x, y - 0.5),
|
|
43
|
+
ellipsoidPoint(projection, x, y + 0.5)
|
|
44
|
+
);
|
|
45
|
+
return (east + north) / 2;
|
|
30
46
|
}
|
|
31
47
|
function fovSpanPx(viewportWidthPx, viewportHeightPx) {
|
|
32
48
|
return Math.max(viewportWidthPx, viewportHeightPx);
|
|
33
49
|
}
|
|
34
|
-
function zoomToRange(zoom, spanPx, fov) {
|
|
35
|
-
return resolutionForZoom(zoom) * spanPx / (2 * Math.tan(fov / 2));
|
|
50
|
+
function zoomToRange(zoom, spanPx, fov, metresPerUnit) {
|
|
51
|
+
return resolutionForZoom(zoom) * metresPerUnit * spanPx / (2 * Math.tan(fov / 2));
|
|
36
52
|
}
|
|
37
|
-
function rangeToZoom(range, spanPx, fov) {
|
|
38
|
-
const resolution = 2 * range * Math.tan(fov / 2) / spanPx;
|
|
53
|
+
function rangeToZoom(range, spanPx, fov, metresPerUnit) {
|
|
54
|
+
const resolution = 2 * range * Math.tan(fov / 2) / spanPx / metresPerUnit;
|
|
39
55
|
return Math.max(0, Math.log2(ZOOM_0_RESOLUTION / resolution));
|
|
40
56
|
}
|
|
41
57
|
function focusRangeForZoom(height, focusRange, maxRangeFactor) {
|
|
@@ -50,8 +66,8 @@ function flipAngleDirection(radians) {
|
|
|
50
66
|
}
|
|
51
67
|
const cesiumHeadingToRotation = flipAngleDirection;
|
|
52
68
|
const rotationToCesiumHeading = flipAngleDirection;
|
|
53
|
-
function
|
|
54
|
-
const [cx, cy] =
|
|
69
|
+
function cameraFootprint(projection, centerLon, centerLat, zoom, viewportWidthPx, viewportHeightPx) {
|
|
70
|
+
const [cx, cy] = wgs84ToMap(projection, centerLon, centerLat);
|
|
55
71
|
const resolution = resolutionForZoom(zoom);
|
|
56
72
|
const halfWidth = resolution * viewportWidthPx / 2;
|
|
57
73
|
const halfHeight = resolution * viewportHeightPx / 2;
|
|
@@ -67,13 +83,13 @@ function opticsOf(viewer) {
|
|
|
67
83
|
const spanPx = fovSpanPx(canvas.clientWidth, canvas.clientHeight);
|
|
68
84
|
return { spanPx: spanPx > 0 ? spanPx : FALLBACK_SPAN_PX, fov };
|
|
69
85
|
}
|
|
70
|
-
function rangeForZoom(viewer, zoom) {
|
|
86
|
+
function rangeForZoom(viewer, zoom, metresPerUnit) {
|
|
71
87
|
const { spanPx, fov } = opticsOf(viewer);
|
|
72
|
-
return zoomToRange(zoom, spanPx, fov);
|
|
88
|
+
return zoomToRange(zoom, spanPx, fov, metresPerUnit);
|
|
73
89
|
}
|
|
74
|
-
function zoomForRange(viewer, range) {
|
|
90
|
+
function zoomForRange(viewer, range, metresPerUnit) {
|
|
75
91
|
const { spanPx, fov } = opticsOf(viewer);
|
|
76
|
-
return rangeToZoom(range, spanPx, fov);
|
|
92
|
+
return rangeToZoom(range, spanPx, fov, metresPerUnit);
|
|
77
93
|
}
|
|
78
94
|
function reportedZoomGrid(zoom) {
|
|
79
95
|
return Math.round(zoom * 10) / 10;
|
|
@@ -100,6 +116,55 @@ function pickGroundPoint(viewer, pixel) {
|
|
|
100
116
|
return point ? { point, onTerrain: terrainPoint !== void 0 } : void 0;
|
|
101
117
|
}
|
|
102
118
|
|
|
119
|
+
function watchCesiumMoving(viewer, callback) {
|
|
120
|
+
const canvas = viewer.scene.canvas;
|
|
121
|
+
let cameraMoving = false;
|
|
122
|
+
let pressed = [];
|
|
123
|
+
let reported = false;
|
|
124
|
+
function report() {
|
|
125
|
+
const moving = cameraMoving || pressed.length > 0;
|
|
126
|
+
if (moving === reported) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
reported = moving;
|
|
130
|
+
callback(moving);
|
|
131
|
+
}
|
|
132
|
+
const press = (event) => {
|
|
133
|
+
pressed = [...pressed, event.pointerId];
|
|
134
|
+
report();
|
|
135
|
+
};
|
|
136
|
+
const release = (event) => {
|
|
137
|
+
pressed = pressed.filter((id) => id !== event.pointerId);
|
|
138
|
+
report();
|
|
139
|
+
};
|
|
140
|
+
const releaseAll = () => {
|
|
141
|
+
pressed = [];
|
|
142
|
+
report();
|
|
143
|
+
};
|
|
144
|
+
const removeMoveStart = viewer.camera.moveStart.addEventListener(() => {
|
|
145
|
+
cameraMoving = true;
|
|
146
|
+
report();
|
|
147
|
+
});
|
|
148
|
+
const removeMoveEnd = viewer.camera.moveEnd.addEventListener(() => {
|
|
149
|
+
cameraMoving = false;
|
|
150
|
+
report();
|
|
151
|
+
});
|
|
152
|
+
canvas.addEventListener("pointerdown", press);
|
|
153
|
+
canvas.addEventListener("lostpointercapture", release);
|
|
154
|
+
window.addEventListener("pointerup", release);
|
|
155
|
+
window.addEventListener("pointercancel", release);
|
|
156
|
+
window.addEventListener("blur", releaseAll);
|
|
157
|
+
return () => {
|
|
158
|
+
removeMoveStart();
|
|
159
|
+
removeMoveEnd();
|
|
160
|
+
canvas.removeEventListener("pointerdown", press);
|
|
161
|
+
canvas.removeEventListener("lostpointercapture", release);
|
|
162
|
+
window.removeEventListener("pointerup", release);
|
|
163
|
+
window.removeEventListener("pointercancel", release);
|
|
164
|
+
window.removeEventListener("blur", releaseAll);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
103
168
|
const MAX_FOCUS_RANGE_FACTOR = 10;
|
|
104
169
|
function jumpTargetHeight(focus) {
|
|
105
170
|
return focus?.height ?? 0;
|
|
@@ -193,8 +258,12 @@ async function destinationTerrainHeight(viewer, lon, lat) {
|
|
|
193
258
|
return 0;
|
|
194
259
|
}
|
|
195
260
|
}
|
|
261
|
+
function viewCenter(viewer, focus) {
|
|
262
|
+
const carto = viewer.camera.positionCartographic;
|
|
263
|
+
return focus ? [focus.lon, focus.lat] : [carto.longitude * RADIANS_TO_DEGREES, carto.latitude * RADIANS_TO_DEGREES];
|
|
264
|
+
}
|
|
196
265
|
const ROTATION_EPSILON = 1e-4;
|
|
197
|
-
function createCesiumCameraCapability(viewer) {
|
|
266
|
+
function createCesiumCameraCapability(viewer, getProjection) {
|
|
198
267
|
const listeners = /* @__PURE__ */ new Set();
|
|
199
268
|
const rotationListeners = /* @__PURE__ */ new Set();
|
|
200
269
|
viewer.camera.percentageChanged = 0.01;
|
|
@@ -222,27 +291,39 @@ function createCesiumCameraCapability(viewer) {
|
|
|
222
291
|
lastRotation = rotation;
|
|
223
292
|
rotationListeners.forEach((cb) => cb(rotation));
|
|
224
293
|
}
|
|
225
|
-
function
|
|
226
|
-
|
|
227
|
-
|
|
294
|
+
function metresPerUnitAt([lon, lat]) {
|
|
295
|
+
return metresPerMapUnit(getProjection(), lon, lat);
|
|
296
|
+
}
|
|
297
|
+
function reportedZoom(focus) {
|
|
298
|
+
const height = viewer.camera.positionCartographic.height;
|
|
228
299
|
const range = focusRangeForZoom(height, focus?.range, MAX_FOCUS_RANGE_FACTOR);
|
|
229
|
-
|
|
300
|
+
return reportedZoomGrid(zoomForRange(viewer, range, metresPerUnitAt(viewCenter(viewer, focus))));
|
|
301
|
+
}
|
|
302
|
+
function footprint(focus, zoom) {
|
|
303
|
+
const canvas = viewer.scene.canvas;
|
|
304
|
+
const [centerLon, centerLat] = viewCenter(viewer, focus);
|
|
305
|
+
return asMapExtent(
|
|
306
|
+
cameraFootprint(
|
|
307
|
+
getProjection(),
|
|
308
|
+
centerLon,
|
|
309
|
+
centerLat,
|
|
310
|
+
zoom,
|
|
311
|
+
canvas.clientWidth,
|
|
312
|
+
canvas.clientHeight
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
function emitChange(focus, heading, pitch) {
|
|
317
|
+
const zoom = reportedZoom(focus);
|
|
230
318
|
if (!Number.isFinite(zoom)) {
|
|
231
319
|
return;
|
|
232
320
|
}
|
|
233
321
|
const change = {
|
|
234
322
|
zoom,
|
|
235
323
|
rotation: cesiumHeadingToRotation(heading),
|
|
236
|
-
pitch
|
|
324
|
+
pitch,
|
|
325
|
+
bbox: footprint(focus, zoom)
|
|
237
326
|
};
|
|
238
|
-
const canvas = viewer.scene.canvas;
|
|
239
|
-
const [centerLon, centerLat] = focus ? [focus.lon, focus.lat] : [
|
|
240
|
-
camera.positionCartographic.longitude * RADIANS_TO_DEGREES,
|
|
241
|
-
camera.positionCartographic.latitude * RADIANS_TO_DEGREES
|
|
242
|
-
];
|
|
243
|
-
change.bbox = asExtent3301(
|
|
244
|
-
cameraFallbackExtent3301(centerLon, centerLat, zoom, canvas.clientWidth, canvas.clientHeight)
|
|
245
|
-
);
|
|
246
327
|
settleDropped = false;
|
|
247
328
|
listeners.forEach((cb) => cb(change));
|
|
248
329
|
}
|
|
@@ -273,8 +354,9 @@ function createCesiumCameraCapability(viewer) {
|
|
|
273
354
|
});
|
|
274
355
|
return {
|
|
275
356
|
flyTo(extent) {
|
|
276
|
-
const
|
|
277
|
-
const [
|
|
357
|
+
const projection = getProjection();
|
|
358
|
+
const [west, south] = mapToWgs84(projection, extent[0], extent[1]);
|
|
359
|
+
const [east, north] = mapToWgs84(projection, extent[2], extent[3]);
|
|
278
360
|
viewer.camera.flyTo({
|
|
279
361
|
destination: Rectangle.fromDegrees(west, south, east, north),
|
|
280
362
|
duration: 0
|
|
@@ -284,20 +366,22 @@ function createCesiumCameraCapability(viewer) {
|
|
|
284
366
|
const camera = viewer.camera;
|
|
285
367
|
const canvas = viewer.scene.canvas;
|
|
286
368
|
const [cx, cy] = extentCenter(extent);
|
|
287
|
-
const
|
|
369
|
+
const projection = getProjection();
|
|
370
|
+
const [lon, lat] = mapToWgs84(projection, cx, cy);
|
|
288
371
|
const focus = focusForPlacement();
|
|
289
372
|
const { heading, pitch } = orientationAtFocus(camera, focus);
|
|
290
373
|
const zoom = zoomForExtent(extent, canvas.clientWidth, canvas.clientHeight);
|
|
374
|
+
const range = rangeForZoom(viewer, zoom, metresPerUnitAt([lon, lat]));
|
|
291
375
|
lookAtTarget(
|
|
292
376
|
camera,
|
|
293
377
|
Cartesian3.fromDegrees(lon, lat, jumpTargetHeight(focus)),
|
|
294
|
-
new HeadingPitchRange(heading, pitch,
|
|
378
|
+
new HeadingPitchRange(heading, pitch, range)
|
|
295
379
|
);
|
|
296
380
|
},
|
|
297
381
|
setExtent(extent) {
|
|
298
382
|
const camera = viewer.camera;
|
|
299
383
|
const [cx, cy] = extentCenter(extent);
|
|
300
|
-
const [lon, lat] =
|
|
384
|
+
const [lon, lat] = mapToWgs84(getProjection(), cx, cy);
|
|
301
385
|
const focus = focusForPlacement();
|
|
302
386
|
const { heading, pitch } = orientationAtFocus(camera, focus);
|
|
303
387
|
lookAtTarget(
|
|
@@ -308,8 +392,8 @@ function createCesiumCameraCapability(viewer) {
|
|
|
308
392
|
},
|
|
309
393
|
setZoom(zoom) {
|
|
310
394
|
const camera = viewer.camera;
|
|
311
|
-
const range = rangeForZoom(viewer, zoom);
|
|
312
395
|
const focus = focusForPlacement();
|
|
396
|
+
const range = rangeForZoom(viewer, zoom, metresPerUnitAt(viewCenter(viewer, focus)));
|
|
313
397
|
if (!focus) {
|
|
314
398
|
camera.setView({
|
|
315
399
|
destination: Cartesian3.fromRadians(
|
|
@@ -360,13 +444,14 @@ function createCesiumCameraCapability(viewer) {
|
|
|
360
444
|
},
|
|
361
445
|
zoomTo(coord, zoom) {
|
|
362
446
|
const camera = viewer.camera;
|
|
363
|
-
const [lon, lat] =
|
|
447
|
+
const [lon, lat] = mapToWgs84(getProjection(), coord[0], coord[1]);
|
|
364
448
|
const focus = focusForPlacement();
|
|
365
449
|
const { heading, pitch } = orientationAtFocus(camera, focus);
|
|
450
|
+
const range = rangeForZoom(viewer, zoom, metresPerUnitAt([lon, lat]));
|
|
366
451
|
lookAtTarget(
|
|
367
452
|
camera,
|
|
368
453
|
Cartesian3.fromDegrees(lon, lat, jumpTargetHeight(focus)),
|
|
369
|
-
new HeadingPitchRange(heading, pitch,
|
|
454
|
+
new HeadingPitchRange(heading, pitch, range)
|
|
370
455
|
);
|
|
371
456
|
},
|
|
372
457
|
async flyToPosition(position, zoom) {
|
|
@@ -374,10 +459,11 @@ function createCesiumCameraCapability(viewer) {
|
|
|
374
459
|
const focus = focusForPlacement();
|
|
375
460
|
const { heading, pitch } = orientationAtFocus(camera, focus);
|
|
376
461
|
const terrainHeight = await destinationTerrainHeight(viewer, position.lon, position.lat);
|
|
462
|
+
const range = rangeForZoom(viewer, zoom, metresPerUnitAt([position.lon, position.lat]));
|
|
377
463
|
camera.flyToBoundingSphere(
|
|
378
464
|
new BoundingSphere(Cartesian3.fromDegrees(position.lon, position.lat, terrainHeight), 0),
|
|
379
465
|
{
|
|
380
|
-
offset: new HeadingPitchRange(heading, pitch,
|
|
466
|
+
offset: new HeadingPitchRange(heading, pitch, range),
|
|
381
467
|
duration: 1
|
|
382
468
|
}
|
|
383
469
|
);
|
|
@@ -387,7 +473,8 @@ function createCesiumCameraCapability(viewer) {
|
|
|
387
473
|
return [carto.longitude * RADIANS_TO_DEGREES, carto.latitude * RADIANS_TO_DEGREES];
|
|
388
474
|
},
|
|
389
475
|
getBbox() {
|
|
390
|
-
|
|
476
|
+
const { focus } = currentView();
|
|
477
|
+
return footprint(focus, reportedZoom(focus));
|
|
391
478
|
},
|
|
392
479
|
getRotation() {
|
|
393
480
|
return cesiumHeadingToRotation(currentView().heading);
|
|
@@ -403,6 +490,9 @@ function createCesiumCameraCapability(viewer) {
|
|
|
403
490
|
return () => {
|
|
404
491
|
rotationListeners.delete(callback);
|
|
405
492
|
};
|
|
493
|
+
},
|
|
494
|
+
onMovingChange(callback) {
|
|
495
|
+
return watchCesiumMoving(viewer, callback);
|
|
406
496
|
}
|
|
407
497
|
};
|
|
408
498
|
}
|
|
@@ -436,7 +526,7 @@ function boundsFloor(viewer, bounds) {
|
|
|
436
526
|
const canvas = viewer.scene.canvas;
|
|
437
527
|
return zoomToFit(bounds, { width: canvas.clientWidth, height: canvas.clientHeight });
|
|
438
528
|
}
|
|
439
|
-
function createCameraBoundsGuard(viewer, bounds) {
|
|
529
|
+
function createCameraBoundsGuard(viewer, bounds, projection) {
|
|
440
530
|
let lastPosition;
|
|
441
531
|
let lastCanvasKey = "";
|
|
442
532
|
function clampToBounds() {
|
|
@@ -450,28 +540,30 @@ function createCameraBoundsGuard(viewer, bounds) {
|
|
|
450
540
|
lastPosition = Cartesian3.clone(camera.position, lastPosition);
|
|
451
541
|
lastCanvasKey = canvasKey;
|
|
452
542
|
const focus = screenCenterGroundFocus(viewer);
|
|
453
|
-
const [lon, lat] =
|
|
454
|
-
|
|
455
|
-
camera.positionCartographic.latitude * RADIANS_TO_DEGREES
|
|
456
|
-
];
|
|
543
|
+
const [lon, lat] = viewCenter(viewer, focus);
|
|
544
|
+
const metresPerUnit = metresPerMapUnit(projection, lon, lat);
|
|
457
545
|
const viewport = { width: canvas.clientWidth, height: canvas.clientHeight };
|
|
458
546
|
const currentRange = focus ? focus.range : camera.positionCartographic.height * MAX_FOCUS_RANGE_FACTOR;
|
|
459
|
-
const range = Math.min(
|
|
460
|
-
|
|
461
|
-
|
|
547
|
+
const range = Math.min(
|
|
548
|
+
currentRange,
|
|
549
|
+
rangeForZoom(viewer, boundsFloor(viewer, bounds), metresPerUnit)
|
|
550
|
+
);
|
|
551
|
+
const footprint = asMapExtent(
|
|
552
|
+
cameraFootprint(
|
|
553
|
+
projection,
|
|
462
554
|
lon,
|
|
463
555
|
lat,
|
|
464
|
-
zoomForRange(viewer, range),
|
|
556
|
+
zoomForRange(viewer, range, metresPerUnit),
|
|
465
557
|
viewport.width,
|
|
466
558
|
viewport.height
|
|
467
559
|
)
|
|
468
560
|
);
|
|
469
|
-
const [x, y] =
|
|
561
|
+
const [x, y] = wgs84ToMap(projection, lon, lat);
|
|
470
562
|
const [targetX, targetY] = extentCenter(clampExtentToBounds(footprint, bounds));
|
|
471
563
|
if (Math.abs(targetX - x) < MOVE_EPSILON_METERS && Math.abs(targetY - y) < MOVE_EPSILON_METERS && currentRange - range < MOVE_EPSILON_METERS) {
|
|
472
564
|
return;
|
|
473
565
|
}
|
|
474
|
-
const [targetLon, targetLat] =
|
|
566
|
+
const [targetLon, targetLat] = mapToWgs84(projection, targetX, targetY);
|
|
475
567
|
if (focus) {
|
|
476
568
|
const { heading, pitch } = headingPitchAtFocus(camera, focus.lon, focus.lat);
|
|
477
569
|
lookAtTarget(
|
|
@@ -502,9 +594,9 @@ function createCesiumViewLimitsCapability(viewer) {
|
|
|
502
594
|
}
|
|
503
595
|
|
|
504
596
|
const ELLIPSOID_HEIGHT = 0;
|
|
505
|
-
function entryTarget(viewer, view) {
|
|
597
|
+
function entryTarget(viewer, view, projection) {
|
|
506
598
|
const [centerX, centerY] = extentCenter(view.bbox);
|
|
507
|
-
const [lon, lat] =
|
|
599
|
+
const [lon, lat] = mapToWgs84(projection, centerX, centerY);
|
|
508
600
|
return {
|
|
509
601
|
lon,
|
|
510
602
|
lat,
|
|
@@ -513,7 +605,7 @@ function entryTarget(viewer, view) {
|
|
|
513
605
|
// place it on or under the ground plane. Free-look (SHIFT-drag) can leave the store's pitch
|
|
514
606
|
// there and it survives a mode switch, so entry clamps to the same tilt the gestures stop at.
|
|
515
607
|
pitch: Math.min(view.pitch, SHALLOWEST_PITCH),
|
|
516
|
-
range: rangeForZoom(viewer, view.zoom)
|
|
608
|
+
range: rangeForZoom(viewer, view.zoom, metresPerMapUnit(projection, lon, lat))
|
|
517
609
|
};
|
|
518
610
|
}
|
|
519
611
|
function placeEntryCamera(viewer, target, height) {
|
|
@@ -1403,6 +1495,7 @@ function viewRecentred(entryBbox, currentBbox) {
|
|
|
1403
1495
|
}
|
|
1404
1496
|
function useCesiumEntryCamera(viewer, view) {
|
|
1405
1497
|
useEffect(() => {
|
|
1498
|
+
const projection = useProjectionStore.getState().projection;
|
|
1406
1499
|
const canvas = viewer.scene.canvas;
|
|
1407
1500
|
let done = false;
|
|
1408
1501
|
let userTookOver = false;
|
|
@@ -1421,7 +1514,10 @@ function useCesiumEntryCamera(viewer, view) {
|
|
|
1421
1514
|
return;
|
|
1422
1515
|
}
|
|
1423
1516
|
try {
|
|
1424
|
-
const height = await sampleTerrainHeight(
|
|
1517
|
+
const height = await sampleTerrainHeight(
|
|
1518
|
+
viewer.terrainProvider,
|
|
1519
|
+
entryTarget(viewer, view, projection)
|
|
1520
|
+
);
|
|
1425
1521
|
if (done || height === void 0) {
|
|
1426
1522
|
return;
|
|
1427
1523
|
}
|
|
@@ -1429,7 +1525,7 @@ function useCesiumEntryCamera(viewer, view) {
|
|
|
1429
1525
|
finish();
|
|
1430
1526
|
return;
|
|
1431
1527
|
}
|
|
1432
|
-
raiseEntryCameraToTerrain(viewer, entryTarget(viewer, view), height);
|
|
1528
|
+
raiseEntryCameraToTerrain(viewer, entryTarget(viewer, view, projection), height);
|
|
1433
1529
|
finish();
|
|
1434
1530
|
} catch (error) {
|
|
1435
1531
|
console.error("Failed to sample terrain for the entry camera", error);
|
|
@@ -1570,18 +1666,27 @@ function useCesiumUserMarker(viewer) {
|
|
|
1570
1666
|
|
|
1571
1667
|
function useCesiumViewBounds(viewer) {
|
|
1572
1668
|
const constraintBbox = useMapViewStore((s) => s.constraintBbox);
|
|
1669
|
+
const projection = useProjectionStore((s) => s.projection);
|
|
1573
1670
|
useEffect(() => {
|
|
1574
1671
|
if (!constraintBbox) {
|
|
1575
1672
|
return;
|
|
1576
1673
|
}
|
|
1577
|
-
return createCameraBoundsGuard(viewer, constraintBbox);
|
|
1578
|
-
}, [viewer, constraintBbox]);
|
|
1674
|
+
return createCameraBoundsGuard(viewer, constraintBbox, projection);
|
|
1675
|
+
}, [viewer, constraintBbox, projection]);
|
|
1579
1676
|
}
|
|
1580
1677
|
|
|
1678
|
+
const currentProjection = () => useProjectionStore.getState().projection;
|
|
1581
1679
|
const CAMERA_INERTIA = 0;
|
|
1582
|
-
function applyZoomDistanceLimits(viewer) {
|
|
1583
|
-
|
|
1584
|
-
|
|
1680
|
+
function applyZoomDistanceLimits(viewer, projection) {
|
|
1681
|
+
const { longitude, latitude } = viewer.camera.positionCartographic;
|
|
1682
|
+
const metresPerUnit = metresPerMapUnit(
|
|
1683
|
+
projection,
|
|
1684
|
+
longitude * RADIANS_TO_DEGREES,
|
|
1685
|
+
latitude * RADIANS_TO_DEGREES
|
|
1686
|
+
);
|
|
1687
|
+
const controller = viewer.scene.screenSpaceCameraController;
|
|
1688
|
+
controller.maximumZoomDistance = rangeForZoom(viewer, MIN_ZOOM, metresPerUnit);
|
|
1689
|
+
controller.minimumZoomDistance = rangeForZoom(viewer, MAX_ZOOM, metresPerUnit);
|
|
1585
1690
|
}
|
|
1586
1691
|
function applyRotationPermission(viewer, rotationAllowed) {
|
|
1587
1692
|
viewer.scene.screenSpaceCameraController.enableTilt = rotationAllowed;
|
|
@@ -1612,6 +1717,7 @@ function Map3D({ onEngineReady }) {
|
|
|
1612
1717
|
const [cesiumViewer, setCesiumViewer] = useState(null);
|
|
1613
1718
|
const [entry, setEntry] = useState(null);
|
|
1614
1719
|
const rotationAllowed = useMapViewStore((s) => s.rotationAllowed);
|
|
1720
|
+
const projection = useProjectionStore((s) => s.projection);
|
|
1615
1721
|
const t = useTranslate();
|
|
1616
1722
|
const canvasLabel = t("map.3d.aria");
|
|
1617
1723
|
const onViewerInit = useCallback((ref) => {
|
|
@@ -1620,12 +1726,12 @@ function Map3D({ onEngineReady }) {
|
|
|
1620
1726
|
}
|
|
1621
1727
|
const viewer = ref.cesiumElement;
|
|
1622
1728
|
const view = useMapViewStore.getState();
|
|
1623
|
-
placeEntryCamera(viewer, entryTarget(viewer, view), ELLIPSOID_HEIGHT);
|
|
1624
|
-
applyZoomDistanceLimits(viewer);
|
|
1729
|
+
placeEntryCamera(viewer, entryTarget(viewer, view, currentProjection()), ELLIPSOID_HEIGHT);
|
|
1625
1730
|
applyGlobeSettings(viewer);
|
|
1626
1731
|
applyRotationPermission(viewer, view.rotationAllowed);
|
|
1627
1732
|
viewer.scene.screenSpaceCameraController.inertiaSpin = CAMERA_INERTIA;
|
|
1628
1733
|
viewer.scene.screenSpaceCameraController.inertiaZoom = CAMERA_INERTIA;
|
|
1734
|
+
viewer.scene.screenSpaceCameraController.minimumCollisionTerrainHeight = Number.POSITIVE_INFINITY;
|
|
1629
1735
|
setEntry(view);
|
|
1630
1736
|
setCesiumViewer(viewer);
|
|
1631
1737
|
}, []);
|
|
@@ -1637,7 +1743,7 @@ function Map3D({ onEngineReady }) {
|
|
|
1637
1743
|
const engine = {
|
|
1638
1744
|
type: "3d",
|
|
1639
1745
|
capabilities: {
|
|
1640
|
-
camera: createCesiumCameraCapability(cesiumViewer),
|
|
1746
|
+
camera: createCesiumCameraCapability(cesiumViewer, currentProjection),
|
|
1641
1747
|
viewLimits: createCesiumViewLimitsCapability(cesiumViewer)
|
|
1642
1748
|
},
|
|
1643
1749
|
destroy() {
|
|
@@ -1688,12 +1794,13 @@ function Map3D({ onEngineReady }) {
|
|
|
1688
1794
|
if (!cesiumViewer) {
|
|
1689
1795
|
return;
|
|
1690
1796
|
}
|
|
1691
|
-
|
|
1797
|
+
applyZoomDistanceLimits(cesiumViewer, projection);
|
|
1798
|
+
const observer = new ResizeObserver(() => applyZoomDistanceLimits(cesiumViewer, projection));
|
|
1692
1799
|
observer.observe(cesiumViewer.scene.canvas);
|
|
1693
1800
|
return () => {
|
|
1694
1801
|
observer.disconnect();
|
|
1695
1802
|
};
|
|
1696
|
-
}, [cesiumViewer]);
|
|
1803
|
+
}, [cesiumViewer, projection]);
|
|
1697
1804
|
useEffect(() => {
|
|
1698
1805
|
if (!cesiumViewer) {
|
|
1699
1806
|
return;
|