@xgis/xgis3d 0.3.55 → 0.4.1
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/Map3D.d.ts +2 -2
- package/dist/cameraBoundsGuard.d.ts +7 -4
- 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 +216 -81
- package/dist/index.js.map +1 -1
- package/dist/projection.d.ts +7 -41
- package/dist/reconcilers/useCesiumViewBounds.d.ts +4 -1
- package/dist/utils/createKMLLayer.d.ts +2 -2
- package/dist/utils/createWMSLayer.d.ts +2 -2
- package/dist/utils/createWMTSLayer.d.ts +2 -1
- package/dist/utils/kmlEntityStyle.d.ts +2 -2
- package/dist/utils/layerCreation.d.ts +2 -2
- package/dist/utils/topicRectangle.d.ts +3 -0
- package/package.json +4 -6
- package/dist/reconcilers/useCesiumLayerReconciler.d.ts +0 -2
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, fallbackTileTemplate, toAlpha, useBasemapStore, useActiveBasemapPlan, useMapViewStore, useProjectionStore, bus, translate, 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, zoomCeiling) {
|
|
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
|
+
Math.max(currentRange, rangeForZoom(viewer, zoomCeiling, metresPerUnit)),
|
|
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
|
-
if (Math.abs(targetX - x) < MOVE_EPSILON_METERS && Math.abs(targetY - y) < MOVE_EPSILON_METERS && currentRange - range < MOVE_EPSILON_METERS) {
|
|
563
|
+
if (Math.abs(targetX - x) < MOVE_EPSILON_METERS && Math.abs(targetY - y) < MOVE_EPSILON_METERS && Math.abs(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(
|
|
@@ -497,14 +589,17 @@ function createCesiumViewLimitsCapability(viewer) {
|
|
|
497
589
|
return MIN_ZOOM;
|
|
498
590
|
}
|
|
499
591
|
return reportedZoomGrid(boundsFloor(viewer, bounds));
|
|
592
|
+
},
|
|
593
|
+
getZoomCeiling(zoomCeiling) {
|
|
594
|
+
return reportedZoomGrid(zoomCeiling);
|
|
500
595
|
}
|
|
501
596
|
};
|
|
502
597
|
}
|
|
503
598
|
|
|
504
599
|
const ELLIPSOID_HEIGHT = 0;
|
|
505
|
-
function entryTarget(viewer, view) {
|
|
600
|
+
function entryTarget(viewer, view, projection) {
|
|
506
601
|
const [centerX, centerY] = extentCenter(view.bbox);
|
|
507
|
-
const [lon, lat] =
|
|
602
|
+
const [lon, lat] = mapToWgs84(projection, centerX, centerY);
|
|
508
603
|
return {
|
|
509
604
|
lon,
|
|
510
605
|
lat,
|
|
@@ -513,7 +608,7 @@ function entryTarget(viewer, view) {
|
|
|
513
608
|
// place it on or under the ground plane. Free-look (SHIFT-drag) can leave the store's pitch
|
|
514
609
|
// there and it survives a mode switch, so entry clamps to the same tilt the gestures stop at.
|
|
515
610
|
pitch: Math.min(view.pitch, SHALLOWEST_PITCH),
|
|
516
|
-
range: rangeForZoom(viewer, view.zoom)
|
|
611
|
+
range: rangeForZoom(viewer, view.zoom, metresPerMapUnit(projection, lon, lat))
|
|
517
612
|
};
|
|
518
613
|
}
|
|
519
614
|
function placeEntryCamera(viewer, target, height) {
|
|
@@ -1176,7 +1271,7 @@ function createTMS(source, presentation, capabilitiesText) {
|
|
|
1176
1271
|
});
|
|
1177
1272
|
}
|
|
1178
1273
|
|
|
1179
|
-
function createWMS(source, presentation, capabilities) {
|
|
1274
|
+
function createWMS(source, presentation, capabilities, rectangle) {
|
|
1180
1275
|
if (!capabilities) {
|
|
1181
1276
|
return null;
|
|
1182
1277
|
}
|
|
@@ -1196,53 +1291,61 @@ function createWMS(source, presentation, capabilities) {
|
|
|
1196
1291
|
crs: request.crs,
|
|
1197
1292
|
srs: request.crs,
|
|
1198
1293
|
tilingScheme: request.projection === "webMercator" ? new WebMercatorTilingScheme() : new GeographicTilingScheme(),
|
|
1294
|
+
rectangle,
|
|
1199
1295
|
credit: presentation.copyright
|
|
1200
1296
|
});
|
|
1201
1297
|
}
|
|
1202
1298
|
|
|
1203
|
-
|
|
1204
|
-
function coarsestLevel(tilingScheme, minimumLevel) {
|
|
1299
|
+
function coarsestLevel(tilingScheme, rectangle, minimumLevel) {
|
|
1205
1300
|
if (minimumLevel === void 0) {
|
|
1206
1301
|
return void 0;
|
|
1207
1302
|
}
|
|
1208
|
-
return safeMinimumLevel(tilingScheme,
|
|
1303
|
+
return safeMinimumLevel(tilingScheme, rectangle ?? tilingScheme.rectangle, minimumLevel);
|
|
1209
1304
|
}
|
|
1210
|
-
function
|
|
1211
|
-
|
|
1305
|
+
function layerRectangle(bbox, topic) {
|
|
1306
|
+
if (!bbox) {
|
|
1307
|
+
return topic;
|
|
1308
|
+
}
|
|
1309
|
+
return Rectangle.fromDegrees(...bbox);
|
|
1310
|
+
}
|
|
1311
|
+
function createWMTS(source, presentation, capabilitiesText, rectangle) {
|
|
1312
|
+
const parsed = parseWmtsCapabilities(capabilitiesText, source.layer, source.format);
|
|
1212
1313
|
if (!parsed) {
|
|
1213
1314
|
return null;
|
|
1214
1315
|
}
|
|
1215
1316
|
const style = source.styles ?? "default";
|
|
1216
|
-
const url =
|
|
1317
|
+
const url = parsed.tileTemplate ?? fallbackTileTemplate(source.href, source.layer, style);
|
|
1217
1318
|
const tilingScheme = parsed.tilingScheme === "geographic" ? new GeographicTilingScheme() : new WebMercatorTilingScheme();
|
|
1319
|
+
const extent = layerRectangle(parsed.wgs84BoundingBox, rectangle);
|
|
1218
1320
|
return new WebMapTileServiceImageryProvider({
|
|
1219
1321
|
url: withQuery(url, stringifyParams(source.params)),
|
|
1220
1322
|
layer: source.layer,
|
|
1221
1323
|
style,
|
|
1222
1324
|
tileMatrixSetID: parsed.tileMatrixSetID,
|
|
1325
|
+
dimensions: parsed.dimensions,
|
|
1223
1326
|
tileMatrixLabels: parsed.tileMatrixLabels.length > 0 ? parsed.tileMatrixLabels : void 0,
|
|
1224
1327
|
format: source.format,
|
|
1225
1328
|
tilingScheme,
|
|
1226
1329
|
maximumLevel: parsed.maximumLevel,
|
|
1227
|
-
minimumLevel: coarsestLevel(tilingScheme, parsed.minimumLevel),
|
|
1330
|
+
minimumLevel: coarsestLevel(tilingScheme, extent, parsed.minimumLevel),
|
|
1228
1331
|
credit: presentation.copyright,
|
|
1229
|
-
rectangle:
|
|
1332
|
+
rectangle: extent
|
|
1230
1333
|
});
|
|
1231
1334
|
}
|
|
1232
1335
|
|
|
1233
|
-
function createCesiumBaseLayer(entry, viewer) {
|
|
1336
|
+
function createCesiumBaseLayer(entry, viewer, rectangle) {
|
|
1234
1337
|
const { layer, capabilities, tileset } = entry;
|
|
1235
1338
|
const { source } = layer;
|
|
1236
1339
|
switch (source.kind) {
|
|
1237
1340
|
case "wms": {
|
|
1238
|
-
const provider = createWMS(source, layer, capabilities);
|
|
1341
|
+
const provider = createWMS(source, layer, capabilities, rectangle);
|
|
1239
1342
|
return provider ? { kind: "imagery", provider } : null;
|
|
1240
1343
|
}
|
|
1241
1344
|
case "wmts": {
|
|
1242
1345
|
if (!capabilities) {
|
|
1243
1346
|
return null;
|
|
1244
1347
|
}
|
|
1245
|
-
const provider = createWMTS(source, layer, capabilities);
|
|
1348
|
+
const provider = createWMTS(source, layer, capabilities, rectangle);
|
|
1246
1349
|
return provider ? { kind: "imagery", provider } : null;
|
|
1247
1350
|
}
|
|
1248
1351
|
case "ogcMaps": {
|
|
@@ -1269,6 +1372,16 @@ function createCesiumBaseLayer(entry, viewer) {
|
|
|
1269
1372
|
}
|
|
1270
1373
|
}
|
|
1271
1374
|
|
|
1375
|
+
function topicRectangle(bbox, projection) {
|
|
1376
|
+
if (!bbox) {
|
|
1377
|
+
return void 0;
|
|
1378
|
+
}
|
|
1379
|
+
const [minX, minY, maxX, maxY] = bbox;
|
|
1380
|
+
const [west, south] = mapToWgs84(projection, minX, minY);
|
|
1381
|
+
const [east, north] = mapToWgs84(projection, maxX, maxY);
|
|
1382
|
+
return Rectangle.fromDegrees(west, south, east, north);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1272
1385
|
function errorStatus(error) {
|
|
1273
1386
|
const cause = error.error;
|
|
1274
1387
|
if (typeof cause !== "object" || cause === null || !("statusCode" in cause)) {
|
|
@@ -1343,6 +1456,12 @@ function useCesiumBasemapAttachments(viewer) {
|
|
|
1343
1456
|
function useCesiumBasemapReconciler(viewer) {
|
|
1344
1457
|
const basemapOpacity = useBasemapStore((s) => s.opacity3d);
|
|
1345
1458
|
const { entries, ready } = useActiveBasemapPlan("3d");
|
|
1459
|
+
const constraintBbox = useMapViewStore((s) => s.constraintBbox);
|
|
1460
|
+
const projection = useProjectionStore((s) => s.projection);
|
|
1461
|
+
const rectangle = useMemo(
|
|
1462
|
+
() => topicRectangle(constraintBbox, projection),
|
|
1463
|
+
[constraintBbox, projection]
|
|
1464
|
+
);
|
|
1346
1465
|
const attachments = useCesiumBasemapAttachments(viewer);
|
|
1347
1466
|
useEffect(() => {
|
|
1348
1467
|
attachments.setOpacity(basemapOpacity);
|
|
@@ -1370,7 +1489,7 @@ function useCesiumBasemapReconciler(viewer) {
|
|
|
1370
1489
|
})();
|
|
1371
1490
|
};
|
|
1372
1491
|
for (const entry of entries) {
|
|
1373
|
-
const created = createCesiumBaseLayer(entry, viewer);
|
|
1492
|
+
const created = createCesiumBaseLayer(entry, viewer, rectangle);
|
|
1374
1493
|
if (!created) {
|
|
1375
1494
|
continue;
|
|
1376
1495
|
}
|
|
@@ -1390,7 +1509,7 @@ function useCesiumBasemapReconciler(viewer) {
|
|
|
1390
1509
|
return () => {
|
|
1391
1510
|
cancelled = true;
|
|
1392
1511
|
};
|
|
1393
|
-
}, [viewer, attachments, entries, ready]);
|
|
1512
|
+
}, [viewer, attachments, entries, ready, rectangle]);
|
|
1394
1513
|
useEffect(() => attachments.detachAll, [attachments]);
|
|
1395
1514
|
}
|
|
1396
1515
|
|
|
@@ -1403,6 +1522,7 @@ function viewRecentred(entryBbox, currentBbox) {
|
|
|
1403
1522
|
}
|
|
1404
1523
|
function useCesiumEntryCamera(viewer, view) {
|
|
1405
1524
|
useEffect(() => {
|
|
1525
|
+
const projection = useProjectionStore.getState().projection;
|
|
1406
1526
|
const canvas = viewer.scene.canvas;
|
|
1407
1527
|
let done = false;
|
|
1408
1528
|
let userTookOver = false;
|
|
@@ -1421,7 +1541,10 @@ function useCesiumEntryCamera(viewer, view) {
|
|
|
1421
1541
|
return;
|
|
1422
1542
|
}
|
|
1423
1543
|
try {
|
|
1424
|
-
const height = await sampleTerrainHeight(
|
|
1544
|
+
const height = await sampleTerrainHeight(
|
|
1545
|
+
viewer.terrainProvider,
|
|
1546
|
+
entryTarget(viewer, view, projection)
|
|
1547
|
+
);
|
|
1425
1548
|
if (done || height === void 0) {
|
|
1426
1549
|
return;
|
|
1427
1550
|
}
|
|
@@ -1429,7 +1552,7 @@ function useCesiumEntryCamera(viewer, view) {
|
|
|
1429
1552
|
finish();
|
|
1430
1553
|
return;
|
|
1431
1554
|
}
|
|
1432
|
-
raiseEntryCameraToTerrain(viewer, entryTarget(viewer, view), height);
|
|
1555
|
+
raiseEntryCameraToTerrain(viewer, entryTarget(viewer, view, projection), height);
|
|
1433
1556
|
finish();
|
|
1434
1557
|
} catch (error) {
|
|
1435
1558
|
console.error("Failed to sample terrain for the entry camera", error);
|
|
@@ -1570,18 +1693,28 @@ function useCesiumUserMarker(viewer) {
|
|
|
1570
1693
|
|
|
1571
1694
|
function useCesiumViewBounds(viewer) {
|
|
1572
1695
|
const constraintBbox = useMapViewStore((s) => s.constraintBbox);
|
|
1696
|
+
const zoomCeiling = useMapViewStore((s) => s.zoomCeiling);
|
|
1697
|
+
const projection = useProjectionStore((s) => s.projection);
|
|
1573
1698
|
useEffect(() => {
|
|
1574
1699
|
if (!constraintBbox) {
|
|
1575
1700
|
return;
|
|
1576
1701
|
}
|
|
1577
|
-
return createCameraBoundsGuard(viewer, constraintBbox);
|
|
1578
|
-
}, [viewer, constraintBbox]);
|
|
1702
|
+
return createCameraBoundsGuard(viewer, constraintBbox, projection, zoomCeiling);
|
|
1703
|
+
}, [viewer, constraintBbox, projection, zoomCeiling]);
|
|
1579
1704
|
}
|
|
1580
1705
|
|
|
1706
|
+
const currentProjection = () => useProjectionStore.getState().projection;
|
|
1581
1707
|
const CAMERA_INERTIA = 0;
|
|
1582
|
-
function applyZoomDistanceLimits(viewer) {
|
|
1583
|
-
|
|
1584
|
-
|
|
1708
|
+
function applyZoomDistanceLimits(viewer, projection) {
|
|
1709
|
+
const { longitude, latitude } = viewer.camera.positionCartographic;
|
|
1710
|
+
const metresPerUnit = metresPerMapUnit(
|
|
1711
|
+
projection,
|
|
1712
|
+
longitude * RADIANS_TO_DEGREES,
|
|
1713
|
+
latitude * RADIANS_TO_DEGREES
|
|
1714
|
+
);
|
|
1715
|
+
const controller = viewer.scene.screenSpaceCameraController;
|
|
1716
|
+
controller.maximumZoomDistance = rangeForZoom(viewer, MIN_ZOOM, metresPerUnit);
|
|
1717
|
+
controller.minimumZoomDistance = rangeForZoom(viewer, MAX_ZOOM, metresPerUnit);
|
|
1585
1718
|
}
|
|
1586
1719
|
function applyRotationPermission(viewer, rotationAllowed) {
|
|
1587
1720
|
viewer.scene.screenSpaceCameraController.enableTilt = rotationAllowed;
|
|
@@ -1612,6 +1745,7 @@ function Map3D({ onEngineReady }) {
|
|
|
1612
1745
|
const [cesiumViewer, setCesiumViewer] = useState(null);
|
|
1613
1746
|
const [entry, setEntry] = useState(null);
|
|
1614
1747
|
const rotationAllowed = useMapViewStore((s) => s.rotationAllowed);
|
|
1748
|
+
const projection = useProjectionStore((s) => s.projection);
|
|
1615
1749
|
const t = useTranslate();
|
|
1616
1750
|
const canvasLabel = t("map.3d.aria");
|
|
1617
1751
|
const onViewerInit = useCallback((ref) => {
|
|
@@ -1620,12 +1754,12 @@ function Map3D({ onEngineReady }) {
|
|
|
1620
1754
|
}
|
|
1621
1755
|
const viewer = ref.cesiumElement;
|
|
1622
1756
|
const view = useMapViewStore.getState();
|
|
1623
|
-
placeEntryCamera(viewer, entryTarget(viewer, view), ELLIPSOID_HEIGHT);
|
|
1624
|
-
applyZoomDistanceLimits(viewer);
|
|
1757
|
+
placeEntryCamera(viewer, entryTarget(viewer, view, currentProjection()), ELLIPSOID_HEIGHT);
|
|
1625
1758
|
applyGlobeSettings(viewer);
|
|
1626
1759
|
applyRotationPermission(viewer, view.rotationAllowed);
|
|
1627
1760
|
viewer.scene.screenSpaceCameraController.inertiaSpin = CAMERA_INERTIA;
|
|
1628
1761
|
viewer.scene.screenSpaceCameraController.inertiaZoom = CAMERA_INERTIA;
|
|
1762
|
+
viewer.scene.screenSpaceCameraController.minimumCollisionTerrainHeight = Number.POSITIVE_INFINITY;
|
|
1629
1763
|
setEntry(view);
|
|
1630
1764
|
setCesiumViewer(viewer);
|
|
1631
1765
|
}, []);
|
|
@@ -1637,7 +1771,7 @@ function Map3D({ onEngineReady }) {
|
|
|
1637
1771
|
const engine = {
|
|
1638
1772
|
type: "3d",
|
|
1639
1773
|
capabilities: {
|
|
1640
|
-
camera: createCesiumCameraCapability(cesiumViewer),
|
|
1774
|
+
camera: createCesiumCameraCapability(cesiumViewer, currentProjection),
|
|
1641
1775
|
viewLimits: createCesiumViewLimitsCapability(cesiumViewer)
|
|
1642
1776
|
},
|
|
1643
1777
|
destroy() {
|
|
@@ -1688,12 +1822,13 @@ function Map3D({ onEngineReady }) {
|
|
|
1688
1822
|
if (!cesiumViewer) {
|
|
1689
1823
|
return;
|
|
1690
1824
|
}
|
|
1691
|
-
|
|
1825
|
+
applyZoomDistanceLimits(cesiumViewer, projection);
|
|
1826
|
+
const observer = new ResizeObserver(() => applyZoomDistanceLimits(cesiumViewer, projection));
|
|
1692
1827
|
observer.observe(cesiumViewer.scene.canvas);
|
|
1693
1828
|
return () => {
|
|
1694
1829
|
observer.disconnect();
|
|
1695
1830
|
};
|
|
1696
|
-
}, [cesiumViewer]);
|
|
1831
|
+
}, [cesiumViewer, projection]);
|
|
1697
1832
|
useEffect(() => {
|
|
1698
1833
|
if (!cesiumViewer) {
|
|
1699
1834
|
return;
|