@reearth/core 0.0.7-alpha.15 → 0.0.7-alpha.16
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 +3040 -2988
- package/dist/core.umd.cjs +42 -42
- package/dist/index.d.ts +8 -0
- package/package.json +1 -1
- package/src/Map/types/index.ts +6 -0
- package/src/Visualizer/index.tsx +7 -0
- package/src/engines/Cesium/core/Globe.tsx +11 -2
- package/src/engines/Cesium/core/Imagery.tsx +7 -2
- package/src/engines/Cesium/core/presets.ts +0 -11
- package/src/engines/Cesium/hooks.ts +50 -0
- package/src/engines/Cesium/index.tsx +16 -3
package/dist/index.d.ts
CHANGED
|
@@ -356,6 +356,7 @@ export declare type CoreVisualizerProps = {
|
|
|
356
356
|
ready?: boolean;
|
|
357
357
|
hiddenLayers?: string[];
|
|
358
358
|
zoomedLayerId?: string;
|
|
359
|
+
displayCredits?: boolean;
|
|
359
360
|
onCameraChange?: (camera: Camera) => void;
|
|
360
361
|
onLayerDrop?: (layerId: string, propertyKey: string, position: LatLng | undefined) => void;
|
|
361
362
|
onLayerSelect?: (layerId: string | undefined, layer: (() => Promise<ComputedLayer | undefined>) | undefined, feature: ComputedFeature | undefined, reason: LayerSelectionReason | undefined) => void;
|
|
@@ -367,6 +368,11 @@ export declare type CoreVisualizerProps = {
|
|
|
367
368
|
onSketchFeatureDelete?: (layerId: string, featureId: string) => void;
|
|
368
369
|
onInteractionModeChange?: (mode: InteractionModeType) => void;
|
|
369
370
|
onAPIReady?: () => void;
|
|
371
|
+
onCreditsUpdate?: (credits: Credit[]) => void;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
export declare type Credit = {
|
|
375
|
+
html?: string;
|
|
370
376
|
};
|
|
371
377
|
|
|
372
378
|
export declare type CursorType = "auto" | "grab" | "crosshair";
|
|
@@ -496,6 +502,7 @@ export declare type EngineProps = {
|
|
|
496
502
|
isLayerDragging?: boolean;
|
|
497
503
|
shouldRender?: boolean;
|
|
498
504
|
meta?: Record<string, unknown>;
|
|
505
|
+
displayCredits?: boolean;
|
|
499
506
|
layersRef?: RefObject<LayersRef>;
|
|
500
507
|
requestingRenderMode?: MutableRefObject<RequestingRenderMode>;
|
|
501
508
|
timelineManagerRef?: TimelineManagerRef;
|
|
@@ -510,6 +517,7 @@ export declare type EngineProps = {
|
|
|
510
517
|
onLayerSelectWithRectStart?: (e: LayerSelectWithRectStart) => void;
|
|
511
518
|
onLayerSelectWithRectMove?: (e: LayerSelectWithRectMove) => void;
|
|
512
519
|
onLayerSelectWithRectEnd?: (e: LayerSelectWithRectEnd) => void;
|
|
520
|
+
onCreditsUpdate?: (credits: Credit[]) => void;
|
|
513
521
|
};
|
|
514
522
|
|
|
515
523
|
export declare type EngineRef = {
|
package/package.json
CHANGED
package/src/Map/types/index.ts
CHANGED
|
@@ -235,6 +235,7 @@ export type EngineProps = {
|
|
|
235
235
|
isLayerDragging?: boolean;
|
|
236
236
|
shouldRender?: boolean;
|
|
237
237
|
meta?: Record<string, unknown>;
|
|
238
|
+
displayCredits?: boolean;
|
|
238
239
|
layersRef?: RefObject<LayersRef>;
|
|
239
240
|
requestingRenderMode?: MutableRefObject<RequestingRenderMode>;
|
|
240
241
|
timelineManagerRef?: TimelineManagerRef;
|
|
@@ -258,6 +259,7 @@ export type EngineProps = {
|
|
|
258
259
|
onLayerSelectWithRectStart?: (e: LayerSelectWithRectStart) => void;
|
|
259
260
|
onLayerSelectWithRectMove?: (e: LayerSelectWithRectMove) => void;
|
|
260
261
|
onLayerSelectWithRectEnd?: (e: LayerSelectWithRectEnd) => void;
|
|
262
|
+
onCreditsUpdate?: (credits: Credit[]) => void;
|
|
261
263
|
};
|
|
262
264
|
|
|
263
265
|
export type LayerEditEvent = {
|
|
@@ -381,3 +383,7 @@ export type SketchRef = {
|
|
|
381
383
|
deleteFeature: (layerId: string, featureId: string) => void;
|
|
382
384
|
onEditFeatureChange: (cb: SketchEditFeatureChangeCb) => void;
|
|
383
385
|
};
|
|
386
|
+
|
|
387
|
+
export type Credit = {
|
|
388
|
+
html?: string;
|
|
389
|
+
};
|
package/src/Visualizer/index.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type LatLng,
|
|
13
13
|
type Cluster,
|
|
14
14
|
type ComputedLayer,
|
|
15
|
+
type Credit,
|
|
15
16
|
} from "../Map";
|
|
16
17
|
import { SketchFeature, SketchType } from "../Map/Sketch/types";
|
|
17
18
|
|
|
@@ -46,6 +47,7 @@ export type CoreVisualizerProps = {
|
|
|
46
47
|
ready?: boolean;
|
|
47
48
|
hiddenLayers?: string[];
|
|
48
49
|
zoomedLayerId?: string;
|
|
50
|
+
displayCredits?: boolean;
|
|
49
51
|
onCameraChange?: (camera: Camera) => void;
|
|
50
52
|
onLayerDrop?: (layerId: string, propertyKey: string, position: LatLng | undefined) => void;
|
|
51
53
|
onLayerSelect?: (
|
|
@@ -62,6 +64,7 @@ export type CoreVisualizerProps = {
|
|
|
62
64
|
onSketchFeatureDelete?: (layerId: string, featureId: string) => void;
|
|
63
65
|
onInteractionModeChange?: (mode: InteractionModeType) => void;
|
|
64
66
|
onAPIReady?: () => void;
|
|
67
|
+
onCreditsUpdate?: (credits: Credit[]) => void;
|
|
65
68
|
};
|
|
66
69
|
|
|
67
70
|
export const CoreVisualizer = memo(
|
|
@@ -82,6 +85,7 @@ export const CoreVisualizer = memo(
|
|
|
82
85
|
interactionMode,
|
|
83
86
|
shouldRender,
|
|
84
87
|
meta,
|
|
88
|
+
displayCredits = true,
|
|
85
89
|
style,
|
|
86
90
|
zoomedLayerId,
|
|
87
91
|
children,
|
|
@@ -96,6 +100,7 @@ export const CoreVisualizer = memo(
|
|
|
96
100
|
onSketchFeatureUpdate,
|
|
97
101
|
onSketchFeatureDelete,
|
|
98
102
|
onAPIReady,
|
|
103
|
+
onCreditsUpdate,
|
|
99
104
|
},
|
|
100
105
|
ref: Ref<MapRef | null>,
|
|
101
106
|
) => {
|
|
@@ -160,6 +165,7 @@ export const CoreVisualizer = memo(
|
|
|
160
165
|
isLayerDragging={isLayerDragging}
|
|
161
166
|
isLayerDraggable={isEditable}
|
|
162
167
|
meta={meta}
|
|
168
|
+
displayCredits={displayCredits}
|
|
163
169
|
style={style}
|
|
164
170
|
featureFlags={featureFlags}
|
|
165
171
|
shouldRender={shouldRender}
|
|
@@ -191,6 +197,7 @@ export const CoreVisualizer = memo(
|
|
|
191
197
|
onLayerSelectWithRectMove={handleLayerSelectWithRectMove}
|
|
192
198
|
onLayerSelectWithRectEnd={handleLayerSelectWithRectEnd}
|
|
193
199
|
onAPIReady={onAPIReady}
|
|
200
|
+
onCreditsUpdate={onCreditsUpdate}
|
|
194
201
|
/>
|
|
195
202
|
<coreContext.Provider value={coreContextValue}>{children}</coreContext.Provider>
|
|
196
203
|
</div>
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
IonResource,
|
|
6
6
|
TerrainProvider,
|
|
7
7
|
} from "cesium";
|
|
8
|
-
import { useMemo } from "react";
|
|
8
|
+
import { useEffect, useMemo } from "react";
|
|
9
9
|
import { Globe as CesiumGlobe } from "resium";
|
|
10
10
|
|
|
11
11
|
import type { ViewerProperty, TerrainProperty } from "../..";
|
|
@@ -15,9 +15,14 @@ import { toColor } from "../common";
|
|
|
15
15
|
export type Props = {
|
|
16
16
|
property?: ViewerProperty;
|
|
17
17
|
cesiumIonAccessToken?: string;
|
|
18
|
+
onTerrainProviderChange?: () => void;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
export default function Globe({
|
|
21
|
+
export default function Globe({
|
|
22
|
+
property,
|
|
23
|
+
cesiumIonAccessToken,
|
|
24
|
+
onTerrainProviderChange,
|
|
25
|
+
}: Props): JSX.Element | null {
|
|
21
26
|
const terrainProperty = useMemo(
|
|
22
27
|
(): TerrainProperty => ({
|
|
23
28
|
...property?.terrain,
|
|
@@ -51,6 +56,10 @@ export default function Globe({ property, cesiumIonAccessToken }: Props): JSX.El
|
|
|
51
56
|
[property?.globe?.baseColor],
|
|
52
57
|
);
|
|
53
58
|
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
onTerrainProviderChange?.();
|
|
61
|
+
}, [terrainProvider, onTerrainProviderChange]);
|
|
62
|
+
|
|
54
63
|
return (
|
|
55
64
|
<CesiumGlobe
|
|
56
65
|
baseColor={baseColor}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
TextureMinificationFilter,
|
|
6
6
|
} from "cesium";
|
|
7
7
|
import { isEqual } from "lodash-es";
|
|
8
|
-
import { useCallback, useMemo, useRef, useLayoutEffect, useState } from "react";
|
|
8
|
+
import { useCallback, useMemo, useRef, useLayoutEffect, useState, useEffect } from "react";
|
|
9
9
|
import { ImageryLayer } from "resium";
|
|
10
10
|
|
|
11
11
|
import { tiles as tilePresets } from "./presets";
|
|
@@ -31,9 +31,10 @@ export type Tile = {
|
|
|
31
31
|
export type Props = {
|
|
32
32
|
tiles?: Tile[];
|
|
33
33
|
cesiumIonAccessToken?: string;
|
|
34
|
+
onTilesChange?: () => void;
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
export default function ImageryLayers({ tiles, cesiumIonAccessToken }: Props) {
|
|
37
|
+
export default function ImageryLayers({ tiles, cesiumIonAccessToken, onTilesChange }: Props) {
|
|
37
38
|
const { providers, updated } = useImageryProviders({
|
|
38
39
|
tiles,
|
|
39
40
|
cesiumIonAccessToken,
|
|
@@ -47,6 +48,10 @@ export default function ImageryLayers({ tiles, cesiumIonAccessToken }: Props) {
|
|
|
47
48
|
if (updated) setCounter(c => c + 1);
|
|
48
49
|
}, [providers, updated]);
|
|
49
50
|
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
onTilesChange?.();
|
|
53
|
+
}, [tiles, counter, onTilesChange]);
|
|
54
|
+
|
|
50
55
|
return (
|
|
51
56
|
<>
|
|
52
57
|
{tiles
|
|
@@ -24,17 +24,6 @@ export const tiles = {
|
|
|
24
24
|
IonImageryProvider.fromAssetId(IonWorldImageryStyle.ROAD, {
|
|
25
25
|
accessToken: cesiumIonAccessToken,
|
|
26
26
|
}).catch(console.error),
|
|
27
|
-
stamen_watercolor: () =>
|
|
28
|
-
new OpenStreetMapImageryProvider({
|
|
29
|
-
url: "https://stamen-tiles.a.ssl.fastly.net/watercolor/",
|
|
30
|
-
credit: "Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.",
|
|
31
|
-
fileExtension: "jpg",
|
|
32
|
-
}),
|
|
33
|
-
stamen_toner: () =>
|
|
34
|
-
new OpenStreetMapImageryProvider({
|
|
35
|
-
url: "https://stamen-tiles.a.ssl.fastly.net/toner/",
|
|
36
|
-
credit: "Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.",
|
|
37
|
-
}),
|
|
38
27
|
open_street_map: () =>
|
|
39
28
|
new OpenStreetMapImageryProvider({
|
|
40
29
|
url: "https://a.tile.openstreetmap.org/",
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
GroundPrimitive,
|
|
13
13
|
ShadowMap,
|
|
14
14
|
ImageryLayer,
|
|
15
|
+
CreditDisplay,
|
|
16
|
+
Credit as CesiumCredit,
|
|
15
17
|
} from "cesium";
|
|
16
18
|
import { MutableRefObject, RefObject, useCallback, useEffect, useMemo, useRef } from "react";
|
|
17
19
|
import type { CesiumComponentRef, CesiumMovementEvent, RootEventTarget } from "resium";
|
|
@@ -27,6 +29,7 @@ import type {
|
|
|
27
29
|
import { e2eAccessToken, setE2ECesiumViewer } from "../../e2eConfig";
|
|
28
30
|
import { ComputedFeature, DataType, SelectedFeatureInfo, LatLng, Camera } from "../../mantle";
|
|
29
31
|
import {
|
|
32
|
+
Credit,
|
|
30
33
|
LayerLoadEvent,
|
|
31
34
|
LayerSelectWithRectEnd,
|
|
32
35
|
LayerSelectWithRectMove,
|
|
@@ -89,6 +92,7 @@ export default ({
|
|
|
89
92
|
onLayerLoad,
|
|
90
93
|
onCameraChange,
|
|
91
94
|
onMount,
|
|
95
|
+
onCreditsUpdate,
|
|
92
96
|
}: {
|
|
93
97
|
ref: React.ForwardedRef<EngineRef>;
|
|
94
98
|
property?: ViewerProperty;
|
|
@@ -128,6 +132,7 @@ export default ({
|
|
|
128
132
|
onLayerLoad?: (e: LayerLoadEvent) => void;
|
|
129
133
|
onCameraChange?: (camera: Camera) => void;
|
|
130
134
|
onMount?: () => void;
|
|
135
|
+
onCreditsUpdate?: (credits: Credit[]) => void;
|
|
131
136
|
}) => {
|
|
132
137
|
const cesium = useRef<CesiumComponentRef<CesiumViewer>>(null);
|
|
133
138
|
|
|
@@ -728,6 +733,49 @@ export default ({
|
|
|
728
733
|
unmountCamera?.();
|
|
729
734
|
}, [unmountCamera]);
|
|
730
735
|
|
|
736
|
+
const updateCredits = useCallback(() => {
|
|
737
|
+
if (!onCreditsUpdate) return;
|
|
738
|
+
// currently we don't have a proper way to get the credits update event
|
|
739
|
+
// wait for 3 seconds to get latest credits
|
|
740
|
+
// some internal property is been used here.
|
|
741
|
+
setTimeout(() => {
|
|
742
|
+
const creditDisplay = cesium.current?.cesiumElement?.creditDisplay as
|
|
743
|
+
| (CreditDisplay & {
|
|
744
|
+
_currentFrameCredits: {
|
|
745
|
+
lightboxCredits: { _array: { credit?: CesiumCredit }[] };
|
|
746
|
+
screenCredits: { _array: { credit?: CesiumCredit }[] };
|
|
747
|
+
};
|
|
748
|
+
_currentCesiumCredit: CesiumCredit;
|
|
749
|
+
})
|
|
750
|
+
| undefined;
|
|
751
|
+
|
|
752
|
+
if (!creditDisplay) return;
|
|
753
|
+
|
|
754
|
+
const { lightboxCredits, screenCredits } = creditDisplay?._currentFrameCredits || {};
|
|
755
|
+
const cesiumCredits = creditDisplay._currentCesiumCredit;
|
|
756
|
+
|
|
757
|
+
const credits: Credit[] = [
|
|
758
|
+
...(cesiumCredits?.html ? [{ html: cesiumCredits.html }] : []),
|
|
759
|
+
...Array.from(lightboxCredits?._array ?? []).map(c => ({
|
|
760
|
+
html: c?.credit?.html,
|
|
761
|
+
})),
|
|
762
|
+
...Array.from(screenCredits?._array ?? []).map(c => ({
|
|
763
|
+
html: c?.credit?.html,
|
|
764
|
+
})),
|
|
765
|
+
];
|
|
766
|
+
|
|
767
|
+
onCreditsUpdate(credits);
|
|
768
|
+
}, 3000);
|
|
769
|
+
}, [onCreditsUpdate]);
|
|
770
|
+
|
|
771
|
+
const handleTilesChange = useCallback(() => {
|
|
772
|
+
updateCredits();
|
|
773
|
+
}, [updateCredits]);
|
|
774
|
+
|
|
775
|
+
const handleTerrainProviderChange = useCallback(() => {
|
|
776
|
+
updateCredits();
|
|
777
|
+
}, [updateCredits]);
|
|
778
|
+
|
|
731
779
|
return {
|
|
732
780
|
cesium,
|
|
733
781
|
cesiumIonAccessToken,
|
|
@@ -747,6 +795,8 @@ export default ({
|
|
|
747
795
|
handleClick,
|
|
748
796
|
handleMount,
|
|
749
797
|
handleUnmount,
|
|
798
|
+
handleTilesChange,
|
|
799
|
+
handleTerrainProviderChange,
|
|
750
800
|
};
|
|
751
801
|
};
|
|
752
802
|
|
|
@@ -47,6 +47,7 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
47
47
|
shouldRender,
|
|
48
48
|
layerSelectionReason,
|
|
49
49
|
meta,
|
|
50
|
+
displayCredits,
|
|
50
51
|
layersRef,
|
|
51
52
|
featureFlags,
|
|
52
53
|
requestingRenderMode,
|
|
@@ -63,6 +64,7 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
63
64
|
onMount,
|
|
64
65
|
onLayerVisibility,
|
|
65
66
|
onLayerLoad,
|
|
67
|
+
onCreditsUpdate,
|
|
66
68
|
},
|
|
67
69
|
ref,
|
|
68
70
|
) => {
|
|
@@ -85,6 +87,8 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
85
87
|
handleClick,
|
|
86
88
|
handleMount,
|
|
87
89
|
handleUnmount,
|
|
90
|
+
handleTilesChange,
|
|
91
|
+
handleTerrainProviderChange,
|
|
88
92
|
} = useHooks({
|
|
89
93
|
ref,
|
|
90
94
|
property,
|
|
@@ -112,6 +116,7 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
112
116
|
onLayerLoad,
|
|
113
117
|
onCameraChange,
|
|
114
118
|
onMount,
|
|
119
|
+
onCreditsUpdate,
|
|
115
120
|
});
|
|
116
121
|
|
|
117
122
|
return (
|
|
@@ -133,7 +138,7 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
133
138
|
navigationHelpButton={false}
|
|
134
139
|
projectionPicker={false}
|
|
135
140
|
sceneModePicker={false}
|
|
136
|
-
creditContainer={creditContainer}
|
|
141
|
+
creditContainer={displayCredits ? undefined : creditContainer}
|
|
137
142
|
style={{
|
|
138
143
|
width: small ? "300px" : "auto",
|
|
139
144
|
height: small ? "300px" : "100%",
|
|
@@ -158,7 +163,11 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
158
163
|
onWheel={mouseEventHandles.wheel}>
|
|
159
164
|
<Event onMount={handleMount} onUnmount={handleUnmount} />
|
|
160
165
|
<Clock timelineManagerRef={timelineManagerRef} />
|
|
161
|
-
<ImageryLayers
|
|
166
|
+
<ImageryLayers
|
|
167
|
+
tiles={property?.tiles}
|
|
168
|
+
cesiumIonAccessToken={cesiumIonAccessToken}
|
|
169
|
+
onTilesChange={handleTilesChange}
|
|
170
|
+
/>
|
|
162
171
|
<LabelImageryLayers tileLabels={property?.tileLabels} />
|
|
163
172
|
<Indicator property={property} timelineManagerRef={timelineManagerRef} />
|
|
164
173
|
<ScreenSpaceEventHandler useDefault>
|
|
@@ -252,7 +261,11 @@ const Cesium: React.ForwardRefRenderFunction<EngineRef, EngineProps> = (
|
|
|
252
261
|
saturationShift={property?.sky?.skyAtmosphere?.saturationShift}
|
|
253
262
|
brightnessShift={property?.sky?.skyAtmosphere?.brightnessShift}
|
|
254
263
|
/>
|
|
255
|
-
<Globe
|
|
264
|
+
<Globe
|
|
265
|
+
property={property}
|
|
266
|
+
cesiumIonAccessToken={cesiumIonAccessToken}
|
|
267
|
+
onTerrainProviderChange={handleTerrainProviderChange}
|
|
268
|
+
/>
|
|
256
269
|
<featureContext.Provider value={context}>{ready ? children : null}</featureContext.Provider>
|
|
257
270
|
<AmbientOcclusion
|
|
258
271
|
{...AMBIENT_OCCLUSION_QUALITY[property?.render?.ambientOcclusion?.quality || "low"]}
|