@xgis/xgis3d 0.3.25 → 0.3.35
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/README.md +26 -90
- package/dist/Map3D.d.ts +2 -0
- package/dist/cesiumBaseUrl.d.ts +5 -0
- package/dist/index.js +156 -23
- package/dist/index.js.map +1 -1
- package/dist/interactions/centroidTilt.d.ts +12 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
# @xgis/xgis3d
|
|
2
2
|
|
|
3
3
|
CesiumJS 3D map engine for XGIS3D. Renders the globe, implements engine capabilities, and reconciles
|
|
4
|
-
layers and terrain from the shared stores.
|
|
5
|
-
[`@xgis/xgis`](
|
|
6
|
-
|
|
7
|
-
Part of the [XGIS3D monorepo](../../README.md).
|
|
4
|
+
layers and terrain from the shared stores. The host
|
|
5
|
+
[`@xgis/xgis`](https://www.npmjs.com/package/@xgis/xgis) loads it when `mapMode` is `'3d'` or
|
|
6
|
+
`'both'`; it is not used on its own.
|
|
8
7
|
|
|
9
8
|
## Do not import this directly
|
|
10
9
|
|
|
11
|
-
Consumers call `mountXgis()` and set `mapMode`; the host
|
|
12
|
-
|
|
13
|
-
matters here — Cesium ships about 7 MB of runtime assets, plus a ~4.6 MB JavaScript chunk, that a 2D-only user should never fetch.
|
|
10
|
+
Consumers call `mountXgis()` and set `mapMode`; the host loads this package on demand, so a
|
|
11
|
+
2D-only user never fetches Cesium's ~7 MB of runtime assets or its ~4.6 MB JavaScript chunk.
|
|
14
12
|
|
|
15
13
|
```bash
|
|
16
14
|
pnpm add @xgis/xgis3d
|
|
@@ -31,114 +29,52 @@ pnpm add @xgis/xgis3d
|
|
|
31
29
|
## Cesium runtime assets
|
|
32
30
|
|
|
33
31
|
Cesium loads workers, textures and widget CSS **at runtime**, by URL. A bundler bundles the
|
|
34
|
-
JavaScript but never sees those files, so they have to be served separately
|
|
32
|
+
JavaScript but never sees those files, so they have to be served separately, and Cesium has to be
|
|
35
33
|
told where.
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
([ADR-0022](../../docs/decisions/0022-bundler-agnostic-cesium-assets.md)).
|
|
35
|
+
[`@xgis/xgis3d-build`](https://www.npmjs.com/package/@xgis/xgis3d-build) does that, with a Vite
|
|
36
|
+
plugin, an Rspack plugin and a CLI for everything else. It resolves Cesium through this package, so
|
|
37
|
+
the assets it serves are always the copy this runtime was built against.
|
|
41
38
|
|
|
42
39
|
```bash
|
|
43
40
|
pnpm add -D @xgis/xgis3d-build
|
|
44
41
|
```
|
|
45
42
|
|
|
46
|
-
This package
|
|
43
|
+
This package handles the runtime side:
|
|
47
44
|
|
|
48
45
|
### The runtime default
|
|
49
46
|
|
|
50
|
-
Importing `@xgis/xgis3d`
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
Importing `@xgis/xgis3d` reads `<meta name="xgis-cesium-base-url">` and falls back to
|
|
48
|
+
`/cesium-<version>`. This happens as an import side effect, before Cesium can resolve its first
|
|
49
|
+
asset URL. The build plugin emits the tag; set it yourself only if you copy the assets by hand.
|
|
53
50
|
|
|
54
51
|
`ensureCesiumBaseUrl()` is also exported for consumers that need to run it explicitly.
|
|
55
52
|
|
|
56
53
|
> If the globe renders but tiles, terrain or the widget chrome are missing, the two halves disagree:
|
|
57
|
-
> check that the directory the plugin wrote matches the
|
|
54
|
+
> check that the directory the plugin wrote matches the meta tag in your HTML.
|
|
58
55
|
|
|
59
56
|
### Licensing of the copied assets
|
|
60
57
|
|
|
61
|
-
Copying
|
|
62
|
-
`@xgis/xgis3d-build`
|
|
63
|
-
|
|
64
|
-
the 28 third-party components Cesium embeds, so it discharges both Apache-2.0 section 4(a) and the
|
|
65
|
-
BSD-3-Clause reproduction requirement for the files under `ThirdParty/`. Because it is read from
|
|
66
|
-
whichever Cesium is installed, it stays correct across upgrades with nothing to maintain.
|
|
67
|
-
|
|
68
|
-
If you serve the assets from your own location instead of using that package, copy that file too.
|
|
69
|
-
|
|
70
|
-
Three findings from a licensing review, recorded here so nobody has to re-derive them:
|
|
71
|
-
|
|
72
|
-
- **Apache-2.0 section 4(d) does not apply.** It only bites when the licensed work ships a `NOTICE`
|
|
73
|
-
file, and Cesium ships none — checked across every Apache-2.0 package in the runtime graph. The
|
|
74
|
-
files are also copied unmodified, so section 4(b) does not apply either. Section 4(a) is the only
|
|
75
|
-
live requirement, and copying `LICENSE.md` meets it.
|
|
76
|
-
- **DOMPurify's dual licence is already resolved.** Cesium embeds it, and it is offered under
|
|
77
|
-
`MPL-2.0 OR Apache-2.0`. Cesium elects Apache-2.0, recorded in `ThirdParty.json` in the Cesium
|
|
78
|
-
package. Composition analysis tooling reports the dual expression and flags `MPL-2.0`; that
|
|
79
|
-
election is the answer, and no MPL obligation reaches this project.
|
|
80
|
-
- **The navigation help icons need visible credit.** `Widgets/Images/NavigationHelp/*.svg` are by
|
|
81
|
-
Freepik from Flaticon.com under Creative Commons Attribution 3.0. They are part of the library
|
|
82
|
-
build and the plugin copies `Widgets` unconditionally, so the obligation attaches on distribution
|
|
83
|
-
rather than only when the widget is displayed. The copied `LICENSE.md` carries the credit.
|
|
84
|
-
|
|
85
|
-
Nothing third-party is bundled into this package itself — `vite.lib.config.ts` externalises every
|
|
86
|
-
bare specifier, so Cesium reaches you as its own npm package with its own licence file. These
|
|
87
|
-
obligations belong to the application you deploy, not to the tarball.
|
|
88
|
-
|
|
89
|
-
## What lives here
|
|
90
|
-
|
|
91
|
-
| Path | Description |
|
|
92
|
-
| ------------------ | ---------------------------------------------------------------------- |
|
|
93
|
-
| `Map3D.tsx` | The React component; creates the Cesium `Viewer`, registers the engine |
|
|
94
|
-
| `capabilities/` | `cesiumCamera` (`ICameraCapability`) and `cesiumEngineHealth` |
|
|
95
|
-
| `reconcilers/` | Shallow-diff store state onto imagery layers, primitives, data sources |
|
|
96
|
-
| `interactions/` | Pointer and picking behaviour |
|
|
97
|
-
| `projection.ts` | EPSG:3301 ↔ globe projection handling |
|
|
98
|
-
| `cesiumBaseUrl.ts` | The runtime `window.CESIUM_BASE_URL` default |
|
|
58
|
+
Copying Cesium's assets into a deployed site redistributes CesiumJS, which is Apache-2.0.
|
|
59
|
+
`@xgis/xgis3d-build` copies Cesium's `LICENSE.md` alongside them, which discharges the obligation.
|
|
60
|
+
If you serve the assets from your own location instead, copy that file too.
|
|
99
61
|
|
|
100
62
|
## Dependency policy
|
|
101
63
|
|
|
102
|
-
`cesium` and `resium` are **exact-pinned dependencies**, not peers. Cesium does not follow
|
|
103
|
-
|
|
104
|
-
version it is tested against. A consumer does not choose the Cesium version; if it needs to change,
|
|
105
|
-
the change belongs here.
|
|
106
|
-
|
|
107
|
-
### Bumping Cesium
|
|
108
|
-
|
|
109
|
-
`@cesium/engine` and `@cesium/widgets` are pinned here too, and **all three move together**.
|
|
110
|
-
|
|
111
|
-
`cesium` re-exports around 1300 symbols from `@cesium/engine` but declares only a caret range on it.
|
|
112
|
-
Engine minors have removed symbols `cesium` still re-exports — 26.3.0 dropped the ClippingPolygons
|
|
113
|
-
shaders that `cesium@1.143.0` re-exports — and a published package cannot ship a lockfile, so every
|
|
114
|
-
consumer re-resolves that range and gets whichever engine is newest. The mismatch passes
|
|
115
|
-
`vite build`, which drops the missing exports silently, and breaks `vite dev` and Rspack, which
|
|
116
|
-
reject them. Pinning here is the last place the combination can be fixed for everyone downstream.
|
|
117
|
-
|
|
118
|
-
To bump, take the versions from the release you are moving to rather than choosing them:
|
|
64
|
+
`cesium` and `resium` are **exact-pinned dependencies**, not peers. Cesium does not follow semver, so this package pins the
|
|
65
|
+
version it is tested against. A consumer does not choose the Cesium version.
|
|
119
66
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
Copy the `@cesium/engine` and `@cesium/widgets` versions it names, dropping the caret, then run
|
|
125
|
-
`pnpm test` in this package. `cesiumDependencies.test.ts` checks every symbol `cesium` re-exports
|
|
126
|
-
against the installed engine and fails on a mismatched pair, so a wrong combination stops in CI
|
|
127
|
-
instead of in someone's dev server.
|
|
67
|
+
`@cesium/engine` and `@cesium/widgets` are pinned alongside `cesium` and move together. `cesium`
|
|
68
|
+
depends on the engine with a caret range while re-exporting around 1300 of its symbols, and engine
|
|
69
|
+
minors have removed symbols `cesium` still re-exports, so the three are pinned as a set.
|
|
128
70
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
71
|
+
This package has no build-tool peers. `vite`, `@rspack/core` and `sirv` live in
|
|
72
|
+
`@xgis/xgis3d-build`, so installing the 3D engine does not pull a Node static-file server into your
|
|
73
|
+
dependency graph.
|
|
132
74
|
|
|
133
75
|
`./package.json` is exported so `@xgis/xgis3d-build` can resolve this package's Cesium. Do not rely
|
|
134
76
|
on it for anything else.
|
|
135
77
|
|
|
136
|
-
## Docs
|
|
137
|
-
|
|
138
|
-
- [Architecture overview](../../docs/architecture.md) — basemap attachment and teardown is section 8
|
|
139
|
-
- [Developer guide](../../docs/developer-guide.md) — engine and capability system, sections 7–8
|
|
140
|
-
- [ADRs](../../docs/decisions/)
|
|
141
|
-
|
|
142
78
|
## License
|
|
143
79
|
|
|
144
|
-
MIT
|
|
80
|
+
MIT. See the LICENSE file in this package.
|
package/dist/Map3D.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import 'cesium/Build/Cesium/Widgets/widgets.css';
|
|
2
2
|
import type { EngineRegistration, IMapEngine } from '@xgis/xgis-common';
|
|
3
|
+
import type { Viewer as CesiumViewer } from 'cesium';
|
|
4
|
+
export declare function applyRotationPermission(viewer: CesiumViewer, rotationAllowed: boolean): void;
|
|
3
5
|
interface Map3DProps {
|
|
4
6
|
onEngineReady: (engine: IMapEngine) => EngineRegistration;
|
|
5
7
|
}
|
package/dist/cesiumBaseUrl.d.ts
CHANGED
|
@@ -3,4 +3,9 @@ declare global {
|
|
|
3
3
|
CESIUM_BASE_URL?: string;
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Under Module Federation the base URL is baked in by a `define`. An npm consumer gets the meta tag
|
|
8
|
+
* from the cesiumAssets build plugin. This default is the remaining case: assets copied to the
|
|
9
|
+
* conventional path without the plugin.
|
|
10
|
+
*/
|
|
6
11
|
export declare function ensureCesiumBaseUrl(): void;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import 'cesium/Build/Cesium/Widgets/widgets.css';
|
|
3
|
-
import { epsg3301ToWgs84 as epsg3301ToWgs84$1, resolutionForZoom, wrapToRange, TWO_PI, ZOOM_0_RESOLUTION, wgs84ToEpsg3301 as wgs84ToEpsg3301$1, asExtent3301, RADIANS_TO_DEGREES, extentCenter, zoomForExtent, createEngineErrorChannel, WEBGL_CONTEXT_LOST_ERROR_NAME, zoomToFit, clampExtentToBounds, MIN_ZOOM, 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, parseTmsTileMap, tmsCesiumSchemeFor, tmsLevelRange, tmsTileBase, tmsTileSuffix, parseWmsCaps, parseWmtsCapabilities, toAlpha, useBasemapStore, useActiveBasemapPlan,
|
|
4
|
-
import { BoundingSphere, Cartesian3, HeadingPitchRange, Matrix4, Rectangle, Cartesian2, Transforms, Matrix3, Math as Math$1, EllipsoidTerrainProvider, Ellipsoid, Cartographic, sampleTerrainMostDetailed, Cesium3DTileStyle, I3SDataProvider, Cesium3DTileset, Color, ImageMaterialProperty, ColorMaterialProperty, ConstantProperty, Iso8601, ArcType, PointGraphics, Resource, HeightReference, PolygonHierarchy, KmlDataSource, UrlTemplateImageryProvider, WebMercatorTilingScheme, GeographicTilingScheme, WebMercatorProjection, WebMapServiceImageryProvider, WebMapTileServiceImageryProvider, CesiumTerrainProvider, ConstantPositionProperty } from 'cesium';
|
|
3
|
+
import { epsg3301ToWgs84 as epsg3301ToWgs84$1, resolutionForZoom, wrapToRange, TWO_PI, ZOOM_0_RESOLUTION, wgs84ToEpsg3301 as wgs84ToEpsg3301$1, asExtent3301, RADIANS_TO_DEGREES, extentCenter, zoomForExtent, 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, parseTmsTileMap, tmsCesiumSchemeFor, tmsLevelRange, tmsTileBase, tmsTileSuffix, parseWmsCaps, parseWmtsCapabilities, toAlpha, useBasemapStore, useActiveBasemapPlan, useMapViewStore, useTerrainStore, useUserMarkerStore, MAX_ZOOM } from '@xgis/xgis-common';
|
|
4
|
+
import { BoundingSphere, Cartesian3, HeadingPitchRange, Matrix4, 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
|
|
|
8
|
+
const META_NAME = "xgis-cesium-base-url";
|
|
9
|
+
let resolved;
|
|
10
|
+
function fromMeta() {
|
|
11
|
+
return document.querySelector(`meta[name="${META_NAME}"]`)?.content.trim() ?? "";
|
|
12
|
+
}
|
|
8
13
|
function ensureCesiumBaseUrl() {
|
|
9
14
|
if (typeof window === "undefined") {
|
|
10
15
|
return;
|
|
11
16
|
}
|
|
12
|
-
if (
|
|
13
|
-
|
|
17
|
+
if (resolved === void 0) {
|
|
18
|
+
resolved = fromMeta() || `/cesium-${"1.143.0"}`;
|
|
14
19
|
}
|
|
15
|
-
window.CESIUM_BASE_URL =
|
|
20
|
+
window.CESIUM_BASE_URL = resolved;
|
|
16
21
|
}
|
|
17
22
|
ensureCesiumBaseUrl();
|
|
18
23
|
|
|
@@ -480,7 +485,6 @@ function createCesiumViewLimitsCapability(viewer) {
|
|
|
480
485
|
};
|
|
481
486
|
}
|
|
482
487
|
|
|
483
|
-
const MAX_ENTRY_PITCH = Math$1.toRadians(-5);
|
|
484
488
|
const ELLIPSOID_HEIGHT = 0;
|
|
485
489
|
function entryTarget(viewer, view) {
|
|
486
490
|
const [centerX, centerY] = extentCenter(view.bbox);
|
|
@@ -489,7 +493,10 @@ function entryTarget(viewer, view) {
|
|
|
489
493
|
lon,
|
|
490
494
|
lat,
|
|
491
495
|
heading: rotationToCesiumHeading(view.rotation),
|
|
492
|
-
|
|
496
|
+
// `lookAt` offsets the camera by -range*sin(pitch), so a pitch at or above the horizon would
|
|
497
|
+
// place it on or under the ground plane. Free-look (SHIFT-drag) can leave the store's pitch
|
|
498
|
+
// there and it survives a mode switch, so entry clamps to the same tilt the gestures stop at.
|
|
499
|
+
pitch: Math.min(view.pitch, SHALLOWEST_PITCH),
|
|
493
500
|
range: rangeForZoom(viewer, view.zoom)
|
|
494
501
|
};
|
|
495
502
|
}
|
|
@@ -533,6 +540,125 @@ function createCanvasPressRelay(viewer) {
|
|
|
533
540
|
};
|
|
534
541
|
}
|
|
535
542
|
|
|
543
|
+
const ROTATE_RATE = 1.77;
|
|
544
|
+
const RADIANS_PER_PIXEL = 25e-4;
|
|
545
|
+
const LEFT_BUTTON = 0;
|
|
546
|
+
const MIDDLE_BUTTON = 1;
|
|
547
|
+
const LEFT_BUTTON_MASK = 1;
|
|
548
|
+
const MIDDLE_BUTTON_MASK = 4;
|
|
549
|
+
function isReplacedTilt(entry) {
|
|
550
|
+
if (entry === CameraEventType.MIDDLE_DRAG) {
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
return typeof entry === "object" && (entry.eventType === CameraEventType.LEFT_DRAG || entry.eventType === CameraEventType.RIGHT_DRAG) && entry.modifier === KeyboardEventModifier.CTRL;
|
|
554
|
+
}
|
|
555
|
+
function buttonMaskFor(button) {
|
|
556
|
+
return button === MIDDLE_BUTTON ? MIDDLE_BUTTON_MASK : LEFT_BUTTON_MASK;
|
|
557
|
+
}
|
|
558
|
+
function startsGesture(event) {
|
|
559
|
+
if (event.button === MIDDLE_BUTTON) {
|
|
560
|
+
return !event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey;
|
|
561
|
+
}
|
|
562
|
+
return event.button === LEFT_BUTTON && platformModifierOnly(event);
|
|
563
|
+
}
|
|
564
|
+
function createCentroidTilt(viewer) {
|
|
565
|
+
const { scene, camera } = viewer;
|
|
566
|
+
const controller = scene.screenSpaceCameraController;
|
|
567
|
+
const canvas = scene.canvas;
|
|
568
|
+
const originalTiltEventTypes = controller.tiltEventTypes;
|
|
569
|
+
const entries = Array.isArray(originalTiltEventTypes) ? originalTiltEventTypes : originalTiltEventTypes === void 0 ? [] : [originalTiltEventTypes];
|
|
570
|
+
controller.tiltEventTypes = entries.filter((entry) => !isReplacedTilt(entry));
|
|
571
|
+
let anchorTransform;
|
|
572
|
+
let activePointerId;
|
|
573
|
+
let activeButtonMask = LEFT_BUTTON_MASK;
|
|
574
|
+
let suspendedRotate;
|
|
575
|
+
let lastX = 0;
|
|
576
|
+
let lastY = 0;
|
|
577
|
+
function finishGesture() {
|
|
578
|
+
const pointerId = activePointerId;
|
|
579
|
+
activePointerId = void 0;
|
|
580
|
+
anchorTransform = void 0;
|
|
581
|
+
if (suspendedRotate !== void 0) {
|
|
582
|
+
controller.enableRotate = suspendedRotate;
|
|
583
|
+
suspendedRotate = void 0;
|
|
584
|
+
}
|
|
585
|
+
if (pointerId !== void 0 && canvas.hasPointerCapture(pointerId)) {
|
|
586
|
+
canvas.releasePointerCapture(pointerId);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function handlePointerDown(event) {
|
|
590
|
+
if (activePointerId !== void 0 || event.pointerType !== "mouse" || !startsGesture(event) || !controller.enableInputs || !controller.enableTilt) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const picked = pickGroundPoint(
|
|
594
|
+
viewer,
|
|
595
|
+
new Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2)
|
|
596
|
+
);
|
|
597
|
+
if (!picked) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
anchorTransform = Transforms.eastNorthUpToFixedFrame(picked.point);
|
|
601
|
+
activePointerId = event.pointerId;
|
|
602
|
+
activeButtonMask = buttonMaskFor(event.button);
|
|
603
|
+
suspendedRotate = controller.enableRotate;
|
|
604
|
+
controller.enableRotate = false;
|
|
605
|
+
lastX = event.clientX;
|
|
606
|
+
lastY = event.clientY;
|
|
607
|
+
canvas.setPointerCapture(event.pointerId);
|
|
608
|
+
}
|
|
609
|
+
function handlePointerMove(event) {
|
|
610
|
+
if (!anchorTransform || event.pointerId !== activePointerId) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (!(event.buttons & activeButtonMask) || !controller.enableInputs || !controller.enableTilt) {
|
|
614
|
+
finishGesture();
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const dx = event.clientX - lastX;
|
|
618
|
+
const dy = event.clientY - lastY;
|
|
619
|
+
lastX = event.clientX;
|
|
620
|
+
lastY = event.clientY;
|
|
621
|
+
if (dx === 0 && dy === 0) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
const previousTransform = Matrix4.clone(camera.transform);
|
|
625
|
+
try {
|
|
626
|
+
camera.lookAtTransform(anchorTransform);
|
|
627
|
+
camera.rotateLeft(ROTATE_RATE * (dx / canvas.clientWidth) * Math.PI * 2);
|
|
628
|
+
const tilt = Math$1.asinClamped(camera.direction.z);
|
|
629
|
+
const allowedUp = Math.min(-dy * RADIANS_PER_PIXEL, SHALLOWEST_PITCH - tilt);
|
|
630
|
+
if (allowedUp !== 0) {
|
|
631
|
+
camera.rotateUp(allowedUp);
|
|
632
|
+
}
|
|
633
|
+
} finally {
|
|
634
|
+
camera.lookAtTransform(previousTransform);
|
|
635
|
+
}
|
|
636
|
+
scene.requestRender();
|
|
637
|
+
}
|
|
638
|
+
function handlePointerEnd(event) {
|
|
639
|
+
if (event.pointerId !== activePointerId) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
finishGesture();
|
|
643
|
+
}
|
|
644
|
+
canvas.addEventListener("pointerdown", handlePointerDown);
|
|
645
|
+
canvas.addEventListener("pointermove", handlePointerMove);
|
|
646
|
+
canvas.addEventListener("pointerup", handlePointerEnd);
|
|
647
|
+
canvas.addEventListener("pointercancel", handlePointerEnd);
|
|
648
|
+
canvas.addEventListener("lostpointercapture", handlePointerEnd);
|
|
649
|
+
window.addEventListener("blur", finishGesture);
|
|
650
|
+
return () => {
|
|
651
|
+
finishGesture();
|
|
652
|
+
controller.tiltEventTypes = originalTiltEventTypes;
|
|
653
|
+
canvas.removeEventListener("pointerdown", handlePointerDown);
|
|
654
|
+
canvas.removeEventListener("pointermove", handlePointerMove);
|
|
655
|
+
canvas.removeEventListener("pointerup", handlePointerEnd);
|
|
656
|
+
canvas.removeEventListener("pointercancel", handlePointerEnd);
|
|
657
|
+
canvas.removeEventListener("lostpointercapture", handlePointerEnd);
|
|
658
|
+
window.removeEventListener("blur", finishGesture);
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
536
662
|
const KEYBOARD_MOVE_DIVISOR = 10;
|
|
537
663
|
function horizontalDirection(vec, normal) {
|
|
538
664
|
const [vecX, vecY, vecZ] = vec;
|
|
@@ -1172,9 +1298,7 @@ function useCesiumBasemapAttachments(viewer) {
|
|
|
1172
1298
|
|
|
1173
1299
|
function useCesiumBasemapReconciler(viewer) {
|
|
1174
1300
|
const basemapOpacity = useBasemapStore((s) => s.opacity3d);
|
|
1175
|
-
const
|
|
1176
|
-
const { entries, ready } = plan;
|
|
1177
|
-
const reportServiceError = useBasemapServiceError("3d", plan);
|
|
1301
|
+
const { entries, ready } = useActiveBasemapPlan("3d");
|
|
1178
1302
|
const attachments = useCesiumBasemapAttachments(viewer);
|
|
1179
1303
|
useEffect(() => {
|
|
1180
1304
|
attachments.setOpacity(basemapOpacity);
|
|
@@ -1185,11 +1309,6 @@ function useCesiumBasemapReconciler(viewer) {
|
|
|
1185
1309
|
}
|
|
1186
1310
|
attachments.detachAll();
|
|
1187
1311
|
let cancelled = false;
|
|
1188
|
-
const removeListeners = [];
|
|
1189
|
-
const addImagery = (provider) => {
|
|
1190
|
-
attachments.addImagery(provider);
|
|
1191
|
-
removeListeners.push(provider.errorEvent.addEventListener(reportServiceError));
|
|
1192
|
-
};
|
|
1193
1312
|
const attachAsync = (load, attach, failure) => {
|
|
1194
1313
|
void (async () => {
|
|
1195
1314
|
try {
|
|
@@ -1199,7 +1318,6 @@ function useCesiumBasemapReconciler(viewer) {
|
|
|
1199
1318
|
}
|
|
1200
1319
|
} catch (error) {
|
|
1201
1320
|
console.warn(failure, error);
|
|
1202
|
-
reportServiceError();
|
|
1203
1321
|
}
|
|
1204
1322
|
})();
|
|
1205
1323
|
};
|
|
@@ -1209,7 +1327,7 @@ function useCesiumBasemapReconciler(viewer) {
|
|
|
1209
1327
|
continue;
|
|
1210
1328
|
}
|
|
1211
1329
|
if (created.kind === "imagery") {
|
|
1212
|
-
addImagery(created.provider);
|
|
1330
|
+
attachments.addImagery(created.provider);
|
|
1213
1331
|
} else if (created.kind === "tileset") {
|
|
1214
1332
|
attachAsync(created.tileset, attachments.addTileset, "Failed to load 3D tileset basemap");
|
|
1215
1333
|
} else {
|
|
@@ -1218,11 +1336,8 @@ function useCesiumBasemapReconciler(viewer) {
|
|
|
1218
1336
|
}
|
|
1219
1337
|
return () => {
|
|
1220
1338
|
cancelled = true;
|
|
1221
|
-
for (const remove of removeListeners) {
|
|
1222
|
-
remove();
|
|
1223
|
-
}
|
|
1224
1339
|
};
|
|
1225
|
-
}, [viewer, attachments, entries, ready
|
|
1340
|
+
}, [viewer, attachments, entries, ready]);
|
|
1226
1341
|
useEffect(() => attachments.detachAll, [attachments]);
|
|
1227
1342
|
}
|
|
1228
1343
|
|
|
@@ -1415,12 +1530,17 @@ function applyZoomDistanceLimits(viewer) {
|
|
|
1415
1530
|
viewer.scene.screenSpaceCameraController.maximumZoomDistance = rangeForZoom(viewer, MIN_ZOOM);
|
|
1416
1531
|
viewer.scene.screenSpaceCameraController.minimumZoomDistance = rangeForZoom(viewer, MAX_ZOOM);
|
|
1417
1532
|
}
|
|
1533
|
+
function applyRotationPermission(viewer, rotationAllowed) {
|
|
1534
|
+
viewer.scene.screenSpaceCameraController.enableTilt = rotationAllowed;
|
|
1535
|
+
viewer.scene.screenSpaceCameraController.enableLook = rotationAllowed;
|
|
1536
|
+
}
|
|
1418
1537
|
const MSAA = 1;
|
|
1419
1538
|
function applyGlobeSettings(viewer) {
|
|
1420
1539
|
const globe = viewer.scene.globe;
|
|
1421
1540
|
globe.baseColor = Color.BLACK;
|
|
1422
1541
|
globe.showGroundAtmosphere = false;
|
|
1423
|
-
globe.maximumScreenSpaceError = 2.
|
|
1542
|
+
globe.maximumScreenSpaceError = 2.2;
|
|
1543
|
+
globe.depthTestAgainstTerrain = true;
|
|
1424
1544
|
}
|
|
1425
1545
|
function CesiumLayerSync({ viewer, entry }) {
|
|
1426
1546
|
useCesiumBasemapReconciler(viewer);
|
|
@@ -1434,6 +1554,7 @@ function Map3D({ onEngineReady }) {
|
|
|
1434
1554
|
ensureCesiumBaseUrl();
|
|
1435
1555
|
const [cesiumViewer, setCesiumViewer] = useState(null);
|
|
1436
1556
|
const [entry, setEntry] = useState(null);
|
|
1557
|
+
const rotationAllowed = useMapViewStore((s) => s.rotationAllowed);
|
|
1437
1558
|
const onViewerInit = useCallback((ref) => {
|
|
1438
1559
|
if (!ref?.cesiumElement) {
|
|
1439
1560
|
return;
|
|
@@ -1443,7 +1564,7 @@ function Map3D({ onEngineReady }) {
|
|
|
1443
1564
|
placeEntryCamera(viewer, entryTarget(viewer, view), ELLIPSOID_HEIGHT);
|
|
1444
1565
|
applyZoomDistanceLimits(viewer);
|
|
1445
1566
|
applyGlobeSettings(viewer);
|
|
1446
|
-
viewer
|
|
1567
|
+
applyRotationPermission(viewer, view.rotationAllowed);
|
|
1447
1568
|
viewer.scene.screenSpaceCameraController.inertiaSpin = CAMERA_INERTIA;
|
|
1448
1569
|
viewer.scene.screenSpaceCameraController.inertiaZoom = CAMERA_INERTIA;
|
|
1449
1570
|
setEntry(view);
|
|
@@ -1489,6 +1610,12 @@ function Map3D({ onEngineReady }) {
|
|
|
1489
1610
|
}
|
|
1490
1611
|
return createNadirLimit(cesiumViewer);
|
|
1491
1612
|
}, [cesiumViewer]);
|
|
1613
|
+
useEffect(() => {
|
|
1614
|
+
if (!cesiumViewer) {
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
return createCentroidTilt(cesiumViewer);
|
|
1618
|
+
}, [cesiumViewer]);
|
|
1492
1619
|
useEffect(() => {
|
|
1493
1620
|
if (!cesiumViewer) {
|
|
1494
1621
|
return;
|
|
@@ -1499,6 +1626,12 @@ function Map3D({ onEngineReady }) {
|
|
|
1499
1626
|
observer.disconnect();
|
|
1500
1627
|
};
|
|
1501
1628
|
}, [cesiumViewer]);
|
|
1629
|
+
useEffect(() => {
|
|
1630
|
+
if (!cesiumViewer) {
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
applyRotationPermission(cesiumViewer, rotationAllowed);
|
|
1634
|
+
}, [cesiumViewer, rotationAllowed]);
|
|
1502
1635
|
return /* @__PURE__ */ jsx(
|
|
1503
1636
|
Viewer,
|
|
1504
1637
|
{
|