@reearth/core 0.0.6 → 0.0.7-alpha.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/core.js +8312 -8318
- package/dist/core.umd.cjs +75 -75
- package/dist/index.d.ts +183 -184
- package/package.json +1 -1
- package/src/Map/ClusteredLayers/index.tsx +2 -2
- package/src/Map/Layer/index.tsx +3 -3
- package/src/Map/Layers/index.tsx +2 -2
- package/src/Map/hooks.ts +0 -4
- package/src/Map/index.tsx +8 -5
- package/src/Map/types/index.ts +5 -182
- package/src/Map/types/viewerProperty.ts +216 -0
- package/src/Map/useTimelineManager.ts +2 -2
- package/src/Map/utils.ts +1 -43
- package/src/Visualizer/coreContext.tsx +1 -8
- package/src/Visualizer/hooks.ts +6 -75
- package/src/Visualizer/index.stories.tsx +4 -48
- package/src/Visualizer/index.tsx +8 -6
- package/src/Visualizer/useCoreAPI.ts +30 -0
- package/src/engines/Cesium/Feature/Ellipse/index.stories.tsx +1 -1
- package/src/engines/Cesium/Feature/Frustum/index.stories.tsx +1 -1
- package/src/engines/Cesium/Feature/Model/index.stories.tsx +1 -1
- package/src/engines/Cesium/Feature/Model/index.tsx +10 -9
- package/src/engines/Cesium/Feature/Polygon/index.stories.tsx +8 -6
- package/src/engines/Cesium/Feature/Raster/index.stories.tsx +2 -2
- package/src/engines/Cesium/Feature/Resource/index.stories.tsx +1 -1
- package/src/engines/Cesium/Feature/Tileset/hooks.ts +12 -11
- package/src/engines/Cesium/Feature/Tileset/index.stories.tsx +1 -1
- package/src/engines/Cesium/Feature/Tileset/index.tsx +4 -4
- package/src/engines/Cesium/Feature/index.tsx +5 -4
- package/src/engines/Cesium/Feature/utils.tsx +2 -2
- package/src/engines/Cesium/core/Globe.tsx +36 -68
- package/src/engines/Cesium/core/Imagery.test.ts +9 -9
- package/src/engines/Cesium/core/Imagery.tsx +17 -19
- package/src/engines/Cesium/core/Indicator/Indicator.tsx +8 -8
- package/src/engines/Cesium/hooks/useCamera.ts +144 -0
- package/src/engines/Cesium/{cameraLimiter.ts → hooks/useCameraLimiter.ts} +22 -45
- package/src/engines/Cesium/{useEngineRef.test.tsx → hooks/useEngineRef.test.tsx} +14 -10
- package/src/engines/Cesium/{useEngineRef.ts → hooks/useEngineRef.ts} +17 -17
- package/src/engines/Cesium/hooks/useExplicitRender.ts +65 -0
- package/src/engines/Cesium/hooks/useLayerDragDrop.ts +77 -0
- package/src/engines/Cesium/{VertexTerrainElevationMaterial.ts → hooks/useOverrideGlobeShader/VertexTerrainElevationMaterial.ts} +3 -2
- package/src/engines/Cesium/{useOverrideGlobeShader.ts → hooks/useOverrideGlobeShader/useOverrideGlobeShader.ts} +19 -16
- package/src/engines/Cesium/hooks/useViewerProperty.ts +90 -0
- package/src/engines/Cesium/hooks.ts +117 -353
- package/src/engines/Cesium/index.stories.tsx +1 -1
- package/src/engines/Cesium/index.tsx +48 -50
- package/src/engines/index.ts +1 -1
- /package/src/engines/Cesium/{JapanSeaLevelEllipsoid.ts → hooks/useOverrideGlobeShader/JapanSeaLevelEllipsoid.ts} +0 -0
- /package/src/engines/Cesium/{vertexTerrainElevationMaterial.glsl → hooks/useOverrideGlobeShader/vertexTerrainElevationMaterial.glsl} +0 -0
|
@@ -1,42 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Color,
|
|
3
2
|
Entity,
|
|
4
3
|
Cesium3DTileFeature,
|
|
5
|
-
Cartesian3,
|
|
6
4
|
Ion,
|
|
7
5
|
Cesium3DTileset,
|
|
8
6
|
JulianDate,
|
|
9
7
|
Cesium3DTilePointFeature,
|
|
10
8
|
Model,
|
|
11
9
|
Cartographic,
|
|
12
|
-
SunLight,
|
|
13
|
-
DirectionalLight,
|
|
14
10
|
Viewer as CesiumViewer,
|
|
15
11
|
Primitive,
|
|
16
12
|
GroundPrimitive,
|
|
17
13
|
ShadowMap,
|
|
18
14
|
ImageryLayer,
|
|
19
|
-
Scene,
|
|
20
|
-
Math as CesiumMath,
|
|
21
15
|
} from "cesium";
|
|
22
|
-
import
|
|
23
|
-
import { isEqual } from "lodash-es";
|
|
24
|
-
import { RefObject, useCallback, useEffect, useMemo, useRef } from "react";
|
|
16
|
+
import { MutableRefObject, RefObject, useCallback, useEffect, useMemo, useRef } from "react";
|
|
25
17
|
import type { CesiumComponentRef, CesiumMovementEvent, RootEventTarget } from "resium";
|
|
26
|
-
import { useCustomCompareCallback } from "use-custom-compare";
|
|
27
18
|
|
|
28
19
|
import type {
|
|
29
|
-
Camera,
|
|
30
|
-
LatLng,
|
|
31
20
|
LayerSelectionReason,
|
|
32
21
|
EngineRef,
|
|
33
|
-
|
|
22
|
+
ViewerProperty,
|
|
34
23
|
MouseEvents,
|
|
35
24
|
LayerEditEvent,
|
|
36
25
|
LayerVisibilityEvent,
|
|
37
26
|
} from "..";
|
|
38
27
|
import { e2eAccessToken, setE2ECesiumViewer } from "../../e2eConfig";
|
|
39
|
-
import { ComputedFeature, DataType, SelectedFeatureInfo } from "../../mantle";
|
|
28
|
+
import { ComputedFeature, DataType, SelectedFeatureInfo, LatLng, Camera } from "../../mantle";
|
|
40
29
|
import {
|
|
41
30
|
LayerLoadEvent,
|
|
42
31
|
LayerSelectWithRectEnd,
|
|
@@ -45,20 +34,22 @@ import {
|
|
|
45
34
|
LayersRef,
|
|
46
35
|
RequestingRenderMode,
|
|
47
36
|
} from "../../Map";
|
|
48
|
-
import { FORCE_REQUEST_RENDER, NO_REQUEST_RENDER, REQUEST_RENDER_ONCE } from "../../Map/hooks";
|
|
49
37
|
import { TimelineManagerRef } from "../../Map/useTimelineManager";
|
|
50
38
|
import { FEATURE_FLAGS } from "../../Visualizer/featureFlags";
|
|
51
39
|
|
|
52
|
-
import {
|
|
53
|
-
import { getCamera, isDraggable, isSelectable } from "./common";
|
|
40
|
+
import { isSelectable } from "./common";
|
|
54
41
|
import { getTag, type Context as FeatureContext } from "./Feature";
|
|
55
42
|
import { arrayToCartecian3 } from "./helpers/sphericalHaromic";
|
|
43
|
+
import useCamera from "./hooks/useCamera";
|
|
44
|
+
import useEngineRef from "./hooks/useEngineRef";
|
|
45
|
+
import useExplicitRender from "./hooks/useExplicitRender";
|
|
46
|
+
import useLayerDragDrop from "./hooks/useLayerDragDrop";
|
|
56
47
|
import { useLayerSelectWithRect } from "./hooks/useLayerSelectWithRect";
|
|
48
|
+
import { useOverrideGlobeShader } from "./hooks/useOverrideGlobeShader/useOverrideGlobeShader";
|
|
49
|
+
import useViewerProperty from "./hooks/useViewerProperty";
|
|
57
50
|
import { InternalCesium3DTileFeature } from "./types";
|
|
58
|
-
import useEngineRef from "./useEngineRef";
|
|
59
|
-
import { useOverrideGlobeShader } from "./useOverrideGlobeShader";
|
|
60
51
|
import { makeMouseEventProps } from "./utils/mouse";
|
|
61
|
-
import {
|
|
52
|
+
import { findEntity, getEntityContent } from "./utils/utils";
|
|
62
53
|
|
|
63
54
|
interface CustomGlobeSurface {
|
|
64
55
|
tileProvider: {
|
|
@@ -74,46 +65,48 @@ type CesiumMouseWheelEvent = (delta: number) => void;
|
|
|
74
65
|
export default ({
|
|
75
66
|
ref,
|
|
76
67
|
property,
|
|
77
|
-
|
|
68
|
+
time,
|
|
78
69
|
selectedLayerId,
|
|
79
70
|
selectionReason,
|
|
80
|
-
isLayerDraggable,
|
|
81
|
-
isLayerDragging,
|
|
82
71
|
meta,
|
|
83
72
|
layersRef,
|
|
84
73
|
featureFlags,
|
|
85
|
-
requestingRenderMode,
|
|
86
|
-
shouldRender,
|
|
87
74
|
timelineManagerRef,
|
|
88
|
-
|
|
75
|
+
isLayerDraggable,
|
|
76
|
+
isLayerDragging,
|
|
77
|
+
shouldRender,
|
|
78
|
+
requestingRenderMode,
|
|
79
|
+
camera,
|
|
80
|
+
cameraForceHorizontalRoll,
|
|
89
81
|
onLayerSelect,
|
|
90
|
-
onCameraChange,
|
|
91
82
|
onLayerDrag,
|
|
92
83
|
onLayerDrop,
|
|
93
84
|
onLayerEdit,
|
|
94
85
|
onLayerSelectWithRectStart,
|
|
95
86
|
onLayerSelectWithRectMove,
|
|
96
87
|
onLayerSelectWithRectEnd,
|
|
97
|
-
onMount,
|
|
98
88
|
onLayerVisibility,
|
|
99
89
|
onLayerLoad,
|
|
90
|
+
onCameraChange,
|
|
91
|
+
onMount,
|
|
100
92
|
}: {
|
|
101
93
|
ref: React.ForwardedRef<EngineRef>;
|
|
102
|
-
property?:
|
|
103
|
-
|
|
94
|
+
property?: ViewerProperty;
|
|
95
|
+
time?: string | Date;
|
|
104
96
|
selectedLayerId?: {
|
|
105
97
|
layerId?: string;
|
|
106
98
|
featureId?: string;
|
|
107
99
|
};
|
|
108
100
|
layersRef?: RefObject<LayersRef>;
|
|
109
101
|
selectionReason?: LayerSelectionReason;
|
|
110
|
-
isLayerDraggable?: boolean;
|
|
111
|
-
isLayerDragging?: boolean;
|
|
112
102
|
meta?: Record<string, unknown>;
|
|
113
103
|
featureFlags: number;
|
|
114
|
-
requestingRenderMode?: React.MutableRefObject<RequestingRenderMode>;
|
|
115
|
-
shouldRender?: boolean;
|
|
116
104
|
timelineManagerRef?: TimelineManagerRef;
|
|
105
|
+
isLayerDraggable?: boolean;
|
|
106
|
+
isLayerDragging?: boolean;
|
|
107
|
+
shouldRender?: boolean;
|
|
108
|
+
requestingRenderMode?: MutableRefObject<RequestingRenderMode>;
|
|
109
|
+
camera?: Camera;
|
|
117
110
|
cameraForceHorizontalRoll?: boolean;
|
|
118
111
|
onLayerSelect?: (
|
|
119
112
|
layerId?: string,
|
|
@@ -121,7 +114,6 @@ export default ({
|
|
|
121
114
|
options?: LayerSelectionReason,
|
|
122
115
|
info?: SelectedFeatureInfo,
|
|
123
116
|
) => void;
|
|
124
|
-
onCameraChange?: (camera: Camera) => void;
|
|
125
117
|
onLayerDrag?: (layerId: string, featureId: string | undefined, position: LatLng) => void;
|
|
126
118
|
onLayerDrop?: (
|
|
127
119
|
layerId: string,
|
|
@@ -132,16 +124,17 @@ export default ({
|
|
|
132
124
|
onLayerSelectWithRectStart?: (e: LayerSelectWithRectStart) => void;
|
|
133
125
|
onLayerSelectWithRectMove?: (e: LayerSelectWithRectMove) => void;
|
|
134
126
|
onLayerSelectWithRectEnd?: (e: LayerSelectWithRectEnd) => void;
|
|
135
|
-
onMount?: () => void;
|
|
136
127
|
onLayerVisibility?: (e: LayerVisibilityEvent) => void;
|
|
137
128
|
onLayerLoad?: (e: LayerLoadEvent) => void;
|
|
129
|
+
onCameraChange?: (camera: Camera) => void;
|
|
130
|
+
onMount?: () => void;
|
|
138
131
|
}) => {
|
|
139
132
|
const cesium = useRef<CesiumComponentRef<CesiumViewer>>(null);
|
|
140
|
-
|
|
133
|
+
|
|
134
|
+
const cesiumIonAccessToken =
|
|
141
135
|
typeof meta?.cesiumIonAccessToken === "string" && meta.cesiumIonAccessToken
|
|
142
136
|
? meta.cesiumIonAccessToken
|
|
143
137
|
: Ion.defaultAccessToken;
|
|
144
|
-
const cesiumIonAccessToken = property?.default?.ion || cesiumIonDefaultAccessToken;
|
|
145
138
|
|
|
146
139
|
// expose ref
|
|
147
140
|
const engineAPI = useEngineRef(ref, cesium);
|
|
@@ -155,54 +148,6 @@ export default ({
|
|
|
155
148
|
featureFlags,
|
|
156
149
|
});
|
|
157
150
|
|
|
158
|
-
const backgroundColor = useMemo(
|
|
159
|
-
() =>
|
|
160
|
-
property?.default?.bgcolor ? Color.fromCssColorString(property.default.bgcolor) : undefined,
|
|
161
|
-
[property?.default?.bgcolor],
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const light = useMemo(() => {
|
|
165
|
-
let light;
|
|
166
|
-
if (property?.light?.lightType === "sunLight") {
|
|
167
|
-
light = new SunLight({
|
|
168
|
-
color: property.light?.lightColor
|
|
169
|
-
? Color.fromCssColorString(property.light.lightColor)
|
|
170
|
-
: undefined,
|
|
171
|
-
intensity: property.light?.lightIntensity,
|
|
172
|
-
});
|
|
173
|
-
} else if (property?.light?.lightType === "directionalLight") {
|
|
174
|
-
light = new DirectionalLight({
|
|
175
|
-
direction: new Cartesian3(
|
|
176
|
-
property?.light?.lightDirectionX ?? 1,
|
|
177
|
-
property?.light?.lightDirectionY ?? 0,
|
|
178
|
-
property?.light?.lightDirectionZ ?? 0,
|
|
179
|
-
),
|
|
180
|
-
color: property.light?.lightColor
|
|
181
|
-
? Color.fromCssColorString(property.light.lightColor)
|
|
182
|
-
: undefined,
|
|
183
|
-
intensity: property.light?.lightIntensity,
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
light = cesium.current?.cesiumElement?.scene.light;
|
|
187
|
-
if (light) {
|
|
188
|
-
light.color = property?.light?.lightColor
|
|
189
|
-
? Color.fromCssColorString(property.light.lightColor)
|
|
190
|
-
: light.color;
|
|
191
|
-
light.intensity = property?.light?.lightIntensity
|
|
192
|
-
? property.light.lightIntensity
|
|
193
|
-
: light.intensity;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return light;
|
|
197
|
-
}, [
|
|
198
|
-
property?.light?.lightType,
|
|
199
|
-
property?.light?.lightColor,
|
|
200
|
-
property?.light?.lightDirectionX,
|
|
201
|
-
property?.light?.lightDirectionY,
|
|
202
|
-
property?.light?.lightDirectionZ,
|
|
203
|
-
property?.light?.lightIntensity,
|
|
204
|
-
]);
|
|
205
|
-
|
|
206
151
|
// shadow map
|
|
207
152
|
type ShadowMapBias = {
|
|
208
153
|
polygonOffsetFactor?: number;
|
|
@@ -222,11 +167,11 @@ export default ({
|
|
|
222
167
|
})
|
|
223
168
|
| undefined;
|
|
224
169
|
if (!shadowMap) return;
|
|
225
|
-
shadowMap.softShadows = property?.
|
|
226
|
-
shadowMap.darkness = property?.
|
|
227
|
-
shadowMap.size = property?.
|
|
170
|
+
shadowMap.softShadows = property?.scene?.shadow?.shadowMap?.softShadows ?? false;
|
|
171
|
+
shadowMap.darkness = property?.scene?.shadow?.shadowMap?.darkness ?? 0.3;
|
|
172
|
+
shadowMap.size = property?.scene?.shadow?.shadowMap?.size ?? 2048;
|
|
173
|
+
shadowMap.maximumDistance = property?.scene?.shadow?.shadowMap?.maximumDistance ?? 5000;
|
|
228
174
|
shadowMap.fadingEnabled = true;
|
|
229
|
-
shadowMap.maximumDistance = property?.atmosphere?.shadowMaximumDistance ?? 5000;
|
|
230
175
|
shadowMap.normalOffset = true;
|
|
231
176
|
|
|
232
177
|
// bias
|
|
@@ -279,91 +224,12 @@ export default ({
|
|
|
279
224
|
Object.assign(shadowMap._pointBias, defaultPointBias);
|
|
280
225
|
}
|
|
281
226
|
}, [
|
|
282
|
-
property?.
|
|
283
|
-
property?.
|
|
284
|
-
property?.
|
|
285
|
-
property?.
|
|
227
|
+
property?.scene?.shadow?.shadowMap?.softShadows,
|
|
228
|
+
property?.scene?.shadow?.shadowMap?.darkness,
|
|
229
|
+
property?.scene?.shadow?.shadowMap?.size,
|
|
230
|
+
property?.scene?.shadow?.shadowMap?.maximumDistance,
|
|
286
231
|
]);
|
|
287
232
|
|
|
288
|
-
useEffect(() => {
|
|
289
|
-
engineAPI.changeSceneMode(property?.default?.sceneMode, 0);
|
|
290
|
-
}, [property?.default?.sceneMode, engineAPI]);
|
|
291
|
-
|
|
292
|
-
// move to initial position at startup
|
|
293
|
-
const initialCameraFlight = useRef(false);
|
|
294
|
-
|
|
295
|
-
const handleMount = useCustomCompareCallback(
|
|
296
|
-
() => {
|
|
297
|
-
if (initialCameraFlight.current) return;
|
|
298
|
-
initialCameraFlight.current = true;
|
|
299
|
-
if (
|
|
300
|
-
property?.cameraLimiter?.cameraLimitterEnabled &&
|
|
301
|
-
property?.cameraLimiter?.cameraLimitterTargetArea
|
|
302
|
-
) {
|
|
303
|
-
engineAPI.flyTo(property?.cameraLimiter?.cameraLimitterTargetArea, { duration: 0 });
|
|
304
|
-
} else if (property?.default?.camera ?? property?.camera?.camera) {
|
|
305
|
-
const camera = property?.default?.camera ?? property?.camera?.camera;
|
|
306
|
-
engineAPI.flyTo(camera as Camera, { duration: 0 });
|
|
307
|
-
}
|
|
308
|
-
const camera = getCamera(cesium?.current?.cesiumElement);
|
|
309
|
-
if (camera) {
|
|
310
|
-
onCameraChange?.(camera);
|
|
311
|
-
}
|
|
312
|
-
onMount?.();
|
|
313
|
-
},
|
|
314
|
-
[
|
|
315
|
-
engineAPI,
|
|
316
|
-
property?.default?.camera,
|
|
317
|
-
property?.camera?.camera,
|
|
318
|
-
property?.cameraLimiter?.cameraLimitterEnabled,
|
|
319
|
-
onCameraChange,
|
|
320
|
-
onMount,
|
|
321
|
-
],
|
|
322
|
-
(prevDeps, nextDeps) =>
|
|
323
|
-
prevDeps[0] === nextDeps[0] &&
|
|
324
|
-
isEqual(prevDeps[1], nextDeps[1]) &&
|
|
325
|
-
isEqual(prevDeps[2], nextDeps[2]) &&
|
|
326
|
-
prevDeps[3] === nextDeps[3] &&
|
|
327
|
-
prevDeps[4] === nextDeps[4] &&
|
|
328
|
-
prevDeps[5] === nextDeps[5],
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
const handleUnmount = useCallback(() => {
|
|
332
|
-
initialCameraFlight.current = false;
|
|
333
|
-
}, []);
|
|
334
|
-
|
|
335
|
-
// cache the camera data emitted from viewer camera change
|
|
336
|
-
const emittedCamera = useRef<Camera[]>([]);
|
|
337
|
-
const updateCamera = useCallback(() => {
|
|
338
|
-
const viewer = cesium?.current?.cesiumElement;
|
|
339
|
-
if (!viewer || viewer.isDestroyed() || !onCameraChange) return;
|
|
340
|
-
|
|
341
|
-
const c = getCamera(viewer);
|
|
342
|
-
if (c && !isEqual(c, camera)) {
|
|
343
|
-
emittedCamera.current.push(c);
|
|
344
|
-
// The state change is not sync now. This number is how many state updates can actually happen to be merged within one re-render.
|
|
345
|
-
if (emittedCamera.current.length > 10) {
|
|
346
|
-
emittedCamera.current.shift();
|
|
347
|
-
}
|
|
348
|
-
onCameraChange?.(c);
|
|
349
|
-
}
|
|
350
|
-
}, [camera, onCameraChange]);
|
|
351
|
-
|
|
352
|
-
const handleCameraChange = useCallback(() => {
|
|
353
|
-
updateCamera();
|
|
354
|
-
}, [updateCamera]);
|
|
355
|
-
|
|
356
|
-
const handleCameraMoveEnd = useCallback(() => {
|
|
357
|
-
updateCamera();
|
|
358
|
-
}, [updateCamera]);
|
|
359
|
-
|
|
360
|
-
useEffect(() => {
|
|
361
|
-
if (camera && !emittedCamera.current.includes(camera)) {
|
|
362
|
-
engineAPI.flyTo(camera, { duration: 0 });
|
|
363
|
-
emittedCamera.current = [];
|
|
364
|
-
}
|
|
365
|
-
}, [camera, engineAPI]);
|
|
366
|
-
|
|
367
233
|
const prevSelectedEntity = useRef<
|
|
368
234
|
| Entity
|
|
369
235
|
| Cesium3DTileset
|
|
@@ -379,7 +245,11 @@ export default ({
|
|
|
379
245
|
const viewer = cesium.current?.cesiumElement;
|
|
380
246
|
if (!viewer || viewer.isDestroyed()) return;
|
|
381
247
|
|
|
382
|
-
if (
|
|
248
|
+
if (
|
|
249
|
+
prevSelectedImageryFeatureId.current === selectedLayerId?.featureId &&
|
|
250
|
+
selectedLayerId?.featureId !== undefined
|
|
251
|
+
)
|
|
252
|
+
return;
|
|
383
253
|
|
|
384
254
|
const prevTag = getTag(prevSelectedEntity.current);
|
|
385
255
|
if (
|
|
@@ -489,22 +359,25 @@ export default ({
|
|
|
489
359
|
|
|
490
360
|
const sphericalHarmonicCoefficients = useMemo(
|
|
491
361
|
() =>
|
|
492
|
-
property?.
|
|
362
|
+
property?.scene?.imageBasedLighting?.sphericalHarmonicCoefficients
|
|
493
363
|
? arrayToCartecian3(
|
|
494
|
-
property?.
|
|
495
|
-
property?.
|
|
364
|
+
property?.scene?.imageBasedLighting?.sphericalHarmonicCoefficients,
|
|
365
|
+
property?.scene?.imageBasedLighting?.intensity,
|
|
496
366
|
)
|
|
497
367
|
: undefined,
|
|
498
|
-
[
|
|
368
|
+
[
|
|
369
|
+
property?.scene?.imageBasedLighting?.sphericalHarmonicCoefficients,
|
|
370
|
+
property?.scene?.imageBasedLighting?.intensity,
|
|
371
|
+
],
|
|
499
372
|
);
|
|
500
373
|
|
|
501
374
|
useOverrideGlobeShader({
|
|
502
375
|
cesium,
|
|
503
376
|
sphericalHarmonicCoefficients,
|
|
504
|
-
globeShadowDarkness: property?.
|
|
505
|
-
globeImageBasedLighting: property?.
|
|
506
|
-
enableLighting: property?.
|
|
507
|
-
hasVertexNormals: property?.terrain?.
|
|
377
|
+
globeShadowDarkness: property?.scene?.shadow?.darkness,
|
|
378
|
+
globeImageBasedLighting: property?.scene?.imageBasedLighting?.enabled,
|
|
379
|
+
enableLighting: property?.globe?.enableLighting,
|
|
380
|
+
hasVertexNormals: property?.terrain?.enabled && property.terrain.normal,
|
|
508
381
|
terrain: property?.terrain,
|
|
509
382
|
});
|
|
510
383
|
|
|
@@ -775,55 +648,6 @@ export default ({
|
|
|
775
648
|
viewer.scene.requestRender();
|
|
776
649
|
}, []);
|
|
777
650
|
|
|
778
|
-
// enable Drag and Drop Layers
|
|
779
|
-
const handleLayerDrag = useCallback(
|
|
780
|
-
(e: Entity, position: Cartesian3 | undefined, _context: Context): boolean | void => {
|
|
781
|
-
const viewer = cesium.current?.cesiumElement;
|
|
782
|
-
if (!viewer || viewer.isDestroyed() || !isSelectable(e) || !isDraggable(e)) return false;
|
|
783
|
-
|
|
784
|
-
const pos = convertCartesian3ToPosition(cesium.current?.cesiumElement, position);
|
|
785
|
-
if (!pos) return false;
|
|
786
|
-
|
|
787
|
-
const tag = getTag(e);
|
|
788
|
-
if (!tag) return false;
|
|
789
|
-
|
|
790
|
-
onLayerDrag?.(tag.layerId || "", tag.featureId, pos);
|
|
791
|
-
},
|
|
792
|
-
[onLayerDrag],
|
|
793
|
-
);
|
|
794
|
-
|
|
795
|
-
const handleLayerDrop = useCallback(
|
|
796
|
-
(e: Entity, position: Cartesian3 | undefined): boolean | void => {
|
|
797
|
-
const viewer = cesium.current?.cesiumElement;
|
|
798
|
-
if (!viewer || viewer.isDestroyed()) return false;
|
|
799
|
-
|
|
800
|
-
const tag = getTag(e);
|
|
801
|
-
const pos = convertCartesian3ToPosition(cesium.current?.cesiumElement, position);
|
|
802
|
-
onLayerDrop?.(tag?.layerId || "", tag?.featureId || "", pos);
|
|
803
|
-
|
|
804
|
-
return false; // let apollo-client handle optimistic updates
|
|
805
|
-
},
|
|
806
|
-
[onLayerDrop],
|
|
807
|
-
);
|
|
808
|
-
|
|
809
|
-
const cesiumDnD = useRef<CesiumDnD>();
|
|
810
|
-
useEffect(() => {
|
|
811
|
-
const viewer = cesium.current?.cesiumElement;
|
|
812
|
-
if (!viewer || viewer.isDestroyed()) return;
|
|
813
|
-
cesiumDnD.current = new CesiumDnD(viewer, {
|
|
814
|
-
onDrag: handleLayerDrag,
|
|
815
|
-
onDrop: handleLayerDrop,
|
|
816
|
-
dragDelay: 1000,
|
|
817
|
-
initialDisabled: !isLayerDraggable,
|
|
818
|
-
});
|
|
819
|
-
return () => {
|
|
820
|
-
if (!viewer || viewer.isDestroyed()) return;
|
|
821
|
-
cesiumDnD.current?.disable();
|
|
822
|
-
};
|
|
823
|
-
}, [handleLayerDrag, handleLayerDrop, isLayerDraggable]);
|
|
824
|
-
const { cameraViewBoundaries, cameraViewOuterBoundaries, cameraViewBoundariesMaterial } =
|
|
825
|
-
useCameraLimiter(cesium, camera, property?.cameraLimiter);
|
|
826
|
-
|
|
827
651
|
const context = useMemo<FeatureContext>(
|
|
828
652
|
() => ({
|
|
829
653
|
selectionReason,
|
|
@@ -842,148 +666,88 @@ export default ({
|
|
|
842
666
|
[selectionReason, engineAPI, onLayerEdit, onLayerVisibility, onLayerLoad, timelineManagerRef],
|
|
843
667
|
);
|
|
844
668
|
|
|
845
|
-
useEffect(() => {
|
|
846
|
-
if (!cesium.current?.cesiumElement) return;
|
|
847
|
-
const allowCameraMove = !!(featureFlags & FEATURE_FLAGS.CAMERA_MOVE);
|
|
848
|
-
const allowCameraZoom = !!(featureFlags & FEATURE_FLAGS.CAMERA_ZOOM);
|
|
849
|
-
const allowCameraTilt = !!(featureFlags & FEATURE_FLAGS.CAMERA_TILT);
|
|
850
|
-
const allowCameraLook = !!(featureFlags & FEATURE_FLAGS.CAMERA_LOOK);
|
|
851
|
-
cesium.current.cesiumElement.scene.screenSpaceCameraController.enableTranslate =
|
|
852
|
-
allowCameraMove;
|
|
853
|
-
cesium.current.cesiumElement.scene.screenSpaceCameraController.enableRotate = allowCameraMove;
|
|
854
|
-
cesium.current.cesiumElement.scene.screenSpaceCameraController.enableLook = allowCameraLook;
|
|
855
|
-
cesium.current.cesiumElement.scene.screenSpaceCameraController.enableTilt = allowCameraTilt;
|
|
856
|
-
cesium.current.cesiumElement.scene.screenSpaceCameraController.enableZoom = allowCameraZoom;
|
|
857
|
-
}, [featureFlags]);
|
|
858
|
-
|
|
859
|
-
// Anti-aliasing
|
|
860
|
-
useEffect(() => {
|
|
861
|
-
const viewer = cesium.current?.cesiumElement;
|
|
862
|
-
if (!viewer || viewer.isDestroyed()) return;
|
|
863
|
-
// TODO: FXAA doesn't support alpha blending in Cesium, so we will enable FXAA when this is fixed.
|
|
864
|
-
// viewer.scene.postProcessStages.fxaa.enabled = property?.render?.antialias === "high";
|
|
865
|
-
viewer.scene.msaaSamples =
|
|
866
|
-
property?.render?.antialias === "extreme"
|
|
867
|
-
? 8
|
|
868
|
-
: property?.render?.antialias === "high"
|
|
869
|
-
? 6
|
|
870
|
-
: property?.render?.antialias === "medium"
|
|
871
|
-
? 4
|
|
872
|
-
: 1; // default as 1
|
|
873
|
-
}, [property?.render?.antialias]);
|
|
874
|
-
|
|
875
|
-
// explicit rendering
|
|
876
|
-
const explicitRender = useCallback(() => {
|
|
877
|
-
const viewer = cesium.current?.cesiumElement;
|
|
878
|
-
if (!requestingRenderMode?.current || !viewer || viewer.isDestroyed()) return;
|
|
879
|
-
viewer.scene.requestRender();
|
|
880
|
-
if (requestingRenderMode.current === REQUEST_RENDER_ONCE) {
|
|
881
|
-
requestingRenderMode.current = NO_REQUEST_RENDER;
|
|
882
|
-
}
|
|
883
|
-
}, [requestingRenderMode]);
|
|
884
|
-
|
|
885
|
-
const explicitRenderRef = useRef<() => void>();
|
|
886
|
-
|
|
887
|
-
useEffect(() => {
|
|
888
|
-
explicitRenderRef.current = explicitRender;
|
|
889
|
-
}, [explicitRender]);
|
|
890
|
-
|
|
891
|
-
useEffect(() => {
|
|
892
|
-
const viewer = cesium.current?.cesiumElement;
|
|
893
|
-
if (!viewer || viewer.isDestroyed()) return;
|
|
894
|
-
return viewer.scene.postUpdate.addEventListener(() => {
|
|
895
|
-
explicitRenderRef.current?.();
|
|
896
|
-
});
|
|
897
|
-
}, []);
|
|
898
|
-
|
|
899
|
-
// render one frame when scene property changes
|
|
900
|
-
useEffect(() => {
|
|
901
|
-
if (requestingRenderMode) {
|
|
902
|
-
requestingRenderMode.current = REQUEST_RENDER_ONCE;
|
|
903
|
-
}
|
|
904
|
-
}, [property, requestingRenderMode]);
|
|
905
|
-
|
|
906
|
-
// force render when timeline is animating or is shouldRender
|
|
907
|
-
useEffect(() => {
|
|
908
|
-
const viewer = cesium.current?.cesiumElement;
|
|
909
|
-
if (!viewer || viewer.isDestroyed()) return;
|
|
910
|
-
if (requestingRenderMode) {
|
|
911
|
-
requestingRenderMode.current =
|
|
912
|
-
isLayerDragging || shouldRender
|
|
913
|
-
? FORCE_REQUEST_RENDER
|
|
914
|
-
: requestingRenderMode.current === REQUEST_RENDER_ONCE
|
|
915
|
-
? REQUEST_RENDER_ONCE
|
|
916
|
-
: NO_REQUEST_RENDER;
|
|
917
|
-
}
|
|
918
|
-
}, [isLayerDragging, shouldRender, requestingRenderMode]);
|
|
919
|
-
|
|
920
|
-
// cesium timeline & animation widget
|
|
921
|
-
useEffect(() => {
|
|
922
|
-
const viewer = cesium.current?.cesiumElement;
|
|
923
|
-
if (!viewer) return;
|
|
924
|
-
if (viewer.animation?.container) {
|
|
925
|
-
(viewer.animation.container as HTMLDivElement).style.visibility = property?.timeline?.visible
|
|
926
|
-
? "visible"
|
|
927
|
-
: "hidden";
|
|
928
|
-
}
|
|
929
|
-
if (viewer.timeline?.container) {
|
|
930
|
-
(viewer.timeline.container as HTMLDivElement).style.visibility = property?.timeline?.visible
|
|
931
|
-
? "visible"
|
|
932
|
-
: "hidden";
|
|
933
|
-
}
|
|
934
|
-
viewer.forceResize();
|
|
935
|
-
}, [property]);
|
|
936
|
-
|
|
937
669
|
const globe = cesium.current?.cesiumElement?.scene.globe;
|
|
938
670
|
|
|
939
671
|
useEffect(() => {
|
|
940
672
|
if (globe) {
|
|
941
673
|
const surface = (globe as any)._surface as CustomGlobeSurface;
|
|
942
674
|
if (surface) {
|
|
943
|
-
surface.tileProvider._debug.wireframe = property?.
|
|
675
|
+
surface.tileProvider._debug.wireframe = property?.debug?.showGlobeWireframe ?? false;
|
|
944
676
|
}
|
|
945
677
|
}
|
|
946
|
-
}, [globe, property?.
|
|
947
|
-
|
|
948
|
-
const onPreRenderCallback = useCallback(
|
|
949
|
-
(scene: Scene) => {
|
|
950
|
-
if (!scene.camera || !cameraForceHorizontalRoll) return;
|
|
951
|
-
if (Math.abs(CesiumMath.negativePiToPi(scene.camera.roll)) > Math.PI / 86400) {
|
|
952
|
-
scene.camera.setView({
|
|
953
|
-
orientation: {
|
|
954
|
-
heading: scene.camera.heading,
|
|
955
|
-
pitch: scene.camera.pitch,
|
|
956
|
-
roll: 0,
|
|
957
|
-
},
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
},
|
|
961
|
-
[cameraForceHorizontalRoll],
|
|
962
|
-
);
|
|
678
|
+
}, [globe, property?.debug?.showGlobeWireframe]);
|
|
963
679
|
|
|
964
680
|
useEffect(() => {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
681
|
+
if (!time) return;
|
|
682
|
+
timelineManagerRef?.current?.commit({
|
|
683
|
+
cmd: "SET_TIME",
|
|
684
|
+
payload: {
|
|
685
|
+
start: time,
|
|
686
|
+
stop: time,
|
|
687
|
+
current: time,
|
|
688
|
+
},
|
|
689
|
+
committer: {
|
|
690
|
+
source: "initialize",
|
|
691
|
+
id: "reearth_core",
|
|
692
|
+
},
|
|
693
|
+
});
|
|
694
|
+
}, [time, timelineManagerRef]);
|
|
969
695
|
|
|
970
|
-
|
|
971
|
-
|
|
696
|
+
const { sceneLight, sceneBackgroundColor, sceneMsaaSamples, sceneMode } = useViewerProperty({
|
|
697
|
+
property,
|
|
972
698
|
cesium,
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
useLayerDragDrop({ cesium, onLayerDrag, onLayerDrop, isLayerDraggable });
|
|
702
|
+
|
|
703
|
+
useExplicitRender({ cesium, requestingRenderMode, isLayerDragging, shouldRender, property });
|
|
704
|
+
|
|
705
|
+
const {
|
|
973
706
|
cameraViewBoundaries,
|
|
974
707
|
cameraViewOuterBoundaries,
|
|
975
708
|
cameraViewBoundariesMaterial,
|
|
709
|
+
handleCameraChange,
|
|
710
|
+
handleCameraMoveEnd,
|
|
711
|
+
mountCamera,
|
|
712
|
+
unmountCamera,
|
|
713
|
+
} = useCamera({
|
|
714
|
+
cesium,
|
|
715
|
+
property,
|
|
716
|
+
camera,
|
|
717
|
+
cameraForceHorizontalRoll,
|
|
718
|
+
featureFlags,
|
|
719
|
+
engineAPI,
|
|
720
|
+
onCameraChange,
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
const handleMount = useCallback(() => {
|
|
724
|
+
mountCamera?.();
|
|
725
|
+
onMount?.();
|
|
726
|
+
}, [mountCamera, onMount]);
|
|
727
|
+
|
|
728
|
+
const handleUnmount = useCallback(() => {
|
|
729
|
+
unmountCamera?.();
|
|
730
|
+
}, [unmountCamera]);
|
|
731
|
+
|
|
732
|
+
return {
|
|
733
|
+
cesium,
|
|
976
734
|
cesiumIonAccessToken,
|
|
977
735
|
mouseEventHandles,
|
|
736
|
+
layerSelectWithRectEventHandlers,
|
|
978
737
|
context,
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
738
|
+
sceneLight,
|
|
739
|
+
sceneBackgroundColor,
|
|
740
|
+
sceneMsaaSamples,
|
|
741
|
+
sceneMode,
|
|
742
|
+
cameraViewBoundaries,
|
|
743
|
+
cameraViewOuterBoundaries,
|
|
744
|
+
cameraViewBoundariesMaterial,
|
|
984
745
|
handleCameraChange,
|
|
985
746
|
handleCameraMoveEnd,
|
|
986
|
-
|
|
747
|
+
handleUpdate,
|
|
748
|
+
handleClick,
|
|
749
|
+
handleMount,
|
|
750
|
+
handleUnmount,
|
|
987
751
|
};
|
|
988
752
|
};
|
|
989
753
|
|