@reearth/core 0.0.7-alpha.0 → 0.0.7-alpha.2

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.
Files changed (55) hide show
  1. package/dist/core.js +8865 -8890
  2. package/dist/core.umd.cjs +74 -74
  3. package/dist/index.d.ts +216 -212
  4. package/package.json +1 -1
  5. package/src/Map/ClusteredLayers/index.tsx +2 -2
  6. package/src/Map/Layer/index.tsx +3 -3
  7. package/src/Map/Layers/index.tsx +2 -2
  8. package/src/Map/Sketch/hooks.ts +46 -66
  9. package/src/Map/Sketch/index.tsx +2 -24
  10. package/src/Map/Sketch/preset.ts +2 -0
  11. package/src/Map/Sketch/types.ts +31 -0
  12. package/src/Map/hooks.ts +0 -4
  13. package/src/Map/index.tsx +8 -5
  14. package/src/Map/ref.ts +3 -7
  15. package/src/Map/types/index.ts +34 -216
  16. package/src/Map/types/viewerProperty.ts +215 -0
  17. package/src/Map/useTimelineManager.ts +5 -3
  18. package/src/Map/utils.ts +1 -43
  19. package/src/Visualizer/coreContext.tsx +1 -8
  20. package/src/Visualizer/hooks.ts +6 -75
  21. package/src/Visualizer/index.stories.tsx +4 -48
  22. package/src/Visualizer/index.tsx +8 -6
  23. package/src/Visualizer/useCoreAPI.ts +30 -0
  24. package/src/engines/Cesium/Feature/Ellipse/index.stories.tsx +1 -1
  25. package/src/engines/Cesium/Feature/Frustum/index.stories.tsx +1 -1
  26. package/src/engines/Cesium/Feature/Model/index.stories.tsx +1 -1
  27. package/src/engines/Cesium/Feature/Model/index.tsx +10 -9
  28. package/src/engines/Cesium/Feature/Polygon/index.stories.tsx +8 -6
  29. package/src/engines/Cesium/Feature/Raster/index.stories.tsx +2 -2
  30. package/src/engines/Cesium/Feature/Resource/index.stories.tsx +1 -1
  31. package/src/engines/Cesium/Feature/Tileset/hooks.ts +12 -11
  32. package/src/engines/Cesium/Feature/Tileset/index.stories.tsx +1 -1
  33. package/src/engines/Cesium/Feature/Tileset/index.tsx +4 -4
  34. package/src/engines/Cesium/Feature/index.tsx +5 -4
  35. package/src/engines/Cesium/Feature/utils.tsx +2 -2
  36. package/src/engines/Cesium/core/Globe.tsx +36 -68
  37. package/src/engines/Cesium/core/Imagery.test.ts +9 -9
  38. package/src/engines/Cesium/core/Imagery.tsx +17 -19
  39. package/src/engines/Cesium/core/Indicator/Indicator.tsx +8 -8
  40. package/src/engines/Cesium/hooks/useCamera.ts +135 -0
  41. package/src/engines/Cesium/{cameraLimiter.ts → hooks/useCameraLimiter.ts} +22 -45
  42. package/src/engines/Cesium/{useEngineRef.test.tsx → hooks/useEngineRef.test.tsx} +38 -34
  43. package/src/engines/Cesium/{useEngineRef.ts → hooks/useEngineRef.ts} +43 -41
  44. package/src/engines/Cesium/hooks/useExplicitRender.ts +65 -0
  45. package/src/engines/Cesium/hooks/useLayerDragDrop.ts +77 -0
  46. package/src/engines/Cesium/{VertexTerrainElevationMaterial.ts → hooks/useOverrideGlobeShader/VertexTerrainElevationMaterial.ts} +3 -2
  47. package/src/engines/Cesium/{useOverrideGlobeShader.ts → hooks/useOverrideGlobeShader/useOverrideGlobeShader.ts} +19 -16
  48. package/src/engines/Cesium/hooks/useViewerProperty.ts +90 -0
  49. package/src/engines/Cesium/hooks.ts +129 -365
  50. package/src/engines/Cesium/index.stories.tsx +1 -1
  51. package/src/engines/Cesium/index.tsx +60 -62
  52. package/src/engines/index.ts +1 -1
  53. package/src/mantle/compat/types.ts +7 -7
  54. /package/src/engines/Cesium/{JapanSeaLevelEllipsoid.ts → hooks/useOverrideGlobeShader/JapanSeaLevelEllipsoid.ts} +0 -0
  55. /package/src/engines/Cesium/{vertexTerrainElevationMaterial.glsl → hooks/useOverrideGlobeShader/vertexTerrainElevationMaterial.glsl} +0 -0
@@ -9,7 +9,7 @@ import type {
9
9
  ComputedFeature,
10
10
  LayerSimple,
11
11
  } from "../../mantle";
12
- import { SceneProperty } from "../types";
12
+ import { ViewerProperty } from "../types";
13
13
 
14
14
  import useHooks, { type Atom, type EvalFeature } from "./hooks";
15
15
 
@@ -29,7 +29,7 @@ export type CommonProps = {
29
29
 
30
30
  export type FeatureComponentProps = {
31
31
  layer: ComputedLayer;
32
- sceneProperty?: SceneProperty;
32
+ viewerProperty?: ViewerProperty;
33
33
  onFeatureRequest?: (range: DataRange) => void;
34
34
  onLayerFetch?: (value: Partial<Pick<LayerSimple, "properties">>) => void;
35
35
  onFeatureFetch?: (features: Feature[]) => void;
@@ -44,7 +44,7 @@ export type Props = {
44
44
  atom?: Atom;
45
45
  overrides?: Record<string, any>;
46
46
  delegatedDataTypes?: DataType[];
47
- sceneProperty?: any;
47
+ viewerProperty?: ViewerProperty;
48
48
  selectedFeatureId?: string;
49
49
  /** Feature component should be injected by a map engine. */
50
50
  Feature?: ComponentType<FeatureComponentProps>;
@@ -2,7 +2,7 @@ import { forwardRef, RefObject, type ForwardRefRenderFunction, type MutableRefOb
2
2
 
3
3
  import { SelectedFeatureInfo } from "../../mantle";
4
4
  import ClusteredLayers, { type Props as ClusteredLayerProps } from "../ClusteredLayers";
5
- import type { ComputedLayer, EngineRef, RequestingRenderMode } from "../types";
5
+ import type { ComputedLayer, EngineRef, RequestingRenderMode, ViewerProperty } from "../types";
6
6
 
7
7
  import useHooks, { LayerSelectionReason, type Ref } from "./hooks";
8
8
 
@@ -36,7 +36,7 @@ export type Props = Omit<ClusteredLayerProps, "atomMap" | "isHidden" | "selected
36
36
  reason?: LayerSelectionReason;
37
37
  };
38
38
  hiddenLayers?: string[];
39
- sceneProperty?: any;
39
+ viewerProperty?: ViewerProperty;
40
40
  requestingRenderMode?: MutableRefObject<RequestingRenderMode>;
41
41
  engineRef?: RefObject<EngineRef>;
42
42
  onLayerSelect?: (
@@ -24,15 +24,16 @@ import {
24
24
  MouseEventProps,
25
25
  SketchRef,
26
26
  } from "../types";
27
+ import { useGet } from "../utils";
27
28
 
28
- import { PRESET_APPEARANCE } from "./preset";
29
+ import { PRESET_APPEARANCE, PRESET_COLOR } from "./preset";
29
30
  import { Position3d, createSketchMachine } from "./sketchMachine";
30
31
  import {
31
32
  GeometryOptionsXYZ,
32
33
  SketchType,
33
34
  SketchFeature,
34
- SketchAppearance,
35
35
  SketchEventProps,
36
+ SketchOptions,
36
37
  } from "./types";
37
38
  import { useWindowEvent } from "./utils";
38
39
 
@@ -73,16 +74,25 @@ export default function useHooks({
73
74
  const [state, send] = useMachine(sketchMachine);
74
75
  const [type, updateType] = useState<SketchType | undefined>();
75
76
  const [from, updateFrom] = useState<"editor" | "plugin">("editor");
76
- const [color, updateColor] = useState<string>();
77
- const [disableShadow, updateDisableShadow] = useState(false);
78
- const [enableRelativeHeight, updateEnableRelativeHeight] = useState(false);
79
77
  const [disableInteraction, setDisableInteraction] = useState(false);
80
- const [defaultAppearance, updateDefaultAppearance] = useState<SketchAppearance | undefined>(
81
- PRESET_APPEARANCE,
82
- );
83
- const createDataOnlyForPluginEnabledRef = useRef(false);
84
- const allowRightClickToAbortEnabledRef = useRef(true);
85
- const allowAutoResetInteractionModeRef = useRef(true);
78
+
79
+ const [sketchOptions, setSketchOptions] = useState<SketchOptions>({
80
+ color: PRESET_COLOR,
81
+ appearance: PRESET_APPEARANCE,
82
+ dataOnly: false,
83
+ disableShadow: false,
84
+ enableRelativeHeight: false,
85
+ rightClickToAbort: true,
86
+ autoResetInteractionMode: true,
87
+ });
88
+
89
+ const overrideOptions = useCallback((options: SketchOptions) => {
90
+ setSketchOptions(prev => ({
91
+ ...prev,
92
+ ...options,
93
+ appearance: merge(cloneDeep(prev.appearance), options.appearance),
94
+ }));
95
+ }, []);
86
96
 
87
97
  const [geometryOptions, setGeometryOptions] = useState<GeometryOptionsXYZ | null>(null);
88
98
  const [extrudedHeight, setExtrudedHeight] = useState(0);
@@ -94,34 +104,6 @@ export default function useHooks({
94
104
  updateFrom(from ?? "editor");
95
105
  }, []);
96
106
 
97
- const setColor = useCallback((color: string) => {
98
- updateColor(color);
99
- }, []);
100
-
101
- const setDisableShadow = useCallback((disable: boolean) => {
102
- updateDisableShadow(!!disable);
103
- }, []);
104
-
105
- const setEnableRelativeHeight = useCallback((enable: boolean) => {
106
- updateEnableRelativeHeight(!!enable);
107
- }, []);
108
-
109
- const setDefaultAppearance = useCallback((appearance: SketchAppearance) => {
110
- updateDefaultAppearance(merge(cloneDeep(PRESET_APPEARANCE), appearance));
111
- }, []);
112
-
113
- const createDataOnly = useCallback((dataOnly: boolean) => {
114
- createDataOnlyForPluginEnabledRef.current = !!dataOnly;
115
- }, []);
116
-
117
- const allowRightClickToAbort = useCallback((allow: boolean) => {
118
- allowRightClickToAbortEnabledRef.current = !!allow;
119
- }, []);
120
-
121
- const allowAutoResetInteractionMode = useCallback((allow: boolean) => {
122
- allowAutoResetInteractionModeRef.current = !!allow;
123
- }, []);
124
-
125
107
  const createFeature = useCallback(() => {
126
108
  const geoOptions = type === "marker" ? markerGeometryRef.current : geometryOptions;
127
109
  if (geoOptions == null) {
@@ -169,11 +151,11 @@ export default function useHooks({
169
151
  features: [{ ...feature, id: feature.properties.id }],
170
152
  },
171
153
  },
172
- ...defaultAppearance,
154
+ ...sketchOptions.appearance,
173
155
  });
174
156
  return { layerId: newLayer?.id, featureId: feature.properties.id };
175
157
  },
176
- [layersRef, defaultAppearance],
158
+ [layersRef, sketchOptions.appearance],
177
159
  );
178
160
 
179
161
  const pluginSketchLayerFeatureAdd = useCallback(
@@ -226,7 +208,7 @@ export default function useHooks({
226
208
  return;
227
209
  }
228
210
 
229
- if (!createDataOnlyForPluginEnabledRef.current) {
211
+ if (!sketchOptions.dataOnly) {
230
212
  const selectedLayer = layersRef.current?.selectedLayer();
231
213
  const { layerId, featureId } =
232
214
  selectedLayer?.id?.length !== PLUGIN_LAYER_ID_LENGTH ||
@@ -262,6 +244,7 @@ export default function useHooks({
262
244
  [
263
245
  layersRef,
264
246
  from,
247
+ sketchOptions.dataOnly,
265
248
  pluginSketchLayerCreate,
266
249
  pluginSketchLayerFeatureAdd,
267
250
  onSketchFeatureCreate,
@@ -481,7 +464,7 @@ export default function useHooks({
481
464
  );
482
465
 
483
466
  const handleRightClick = useCallback(() => {
484
- if (!allowRightClickToAbortEnabledRef.current) {
467
+ if (!sketchOptions.rightClickToAbort) {
485
468
  return;
486
469
  }
487
470
  if (type !== undefined) {
@@ -490,7 +473,7 @@ export default function useHooks({
490
473
  if (state.matches("idle")) return;
491
474
  send({ type: "ABORT" });
492
475
  updateGeometryOptions(undefined);
493
- }, [type, state, send, updateGeometryOptions]);
476
+ }, [type, state, sketchOptions.rightClickToAbort, send, updateGeometryOptions]);
494
477
 
495
478
  const mouseDownEventRef = useRef<MouseEventCallback>(handleLeftDown);
496
479
  mouseDownEventRef.current = handleLeftDown;
@@ -586,44 +569,41 @@ export default function useHooks({
586
569
  useEffect(() => {
587
570
  if (type) {
588
571
  overrideInteractionMode?.("sketch");
589
- } else if (allowAutoResetInteractionModeRef.current) {
572
+ } else if (sketchOptions.autoResetInteractionMode) {
590
573
  overrideInteractionMode?.("default");
591
574
  }
592
575
 
593
576
  onSketchTypeChange?.(type, from);
594
- }, [type, from, overrideInteractionMode, onSketchTypeChange]);
577
+ }, [
578
+ type,
579
+ from,
580
+ sketchOptions.autoResetInteractionMode,
581
+ overrideInteractionMode,
582
+ onSketchTypeChange,
583
+ ]);
584
+
585
+ // API
586
+ const getType = useGet(type);
587
+ const getOptions = useGet(sketchOptions);
595
588
 
596
589
  useImperativeHandle(
597
590
  ref,
598
591
  () => ({
592
+ getType,
599
593
  setType,
600
- setColor,
601
- setDefaultAppearance,
602
- createDataOnly,
603
- disableShadow: setDisableShadow,
604
- enableRelativeHeight: setEnableRelativeHeight,
605
- allowRightClickToAbort,
606
- allowAutoResetInteractionMode,
594
+ getOptions,
595
+ overrideOptions,
607
596
  }),
608
- [
609
- setType,
610
- setColor,
611
- setDisableShadow,
612
- setEnableRelativeHeight,
613
- setDefaultAppearance,
614
- createDataOnly,
615
- allowRightClickToAbort,
616
- allowAutoResetInteractionMode,
617
- ],
597
+ [getType, setType, getOptions, overrideOptions],
618
598
  );
619
599
 
620
600
  return {
621
601
  state,
622
602
  extrudedHeight,
623
603
  geometryOptions,
624
- color,
625
- disableShadow,
626
- enableRelativeHeight,
604
+ color: sketchOptions.color,
605
+ disableShadow: sketchOptions.disableShadow,
606
+ enableRelativeHeight: sketchOptions.enableRelativeHeight,
627
607
  } as any;
628
608
  }
629
609
 
@@ -1,38 +1,16 @@
1
1
  // Reference: Sketch feature is basically referenced from https://github.com/takram-design-engineering/plateau-view/blob/main/libs/sketch/src/SketchTool.tsx
2
2
 
3
- import { type LineString, type MultiPolygon, type Polygon } from "geojson";
4
- import { ComponentType, ForwardRefRenderFunction, RefObject, forwardRef } from "react";
5
- import { RequireExactlyOne } from "type-fest";
3
+ import { ForwardRefRenderFunction, RefObject, forwardRef } from "react";
6
4
 
7
5
  import { ComputedLayer, SelectedFeatureInfo } from "../../mantle";
8
- import { Position3d } from "../../types";
9
6
  import { InteractionModeType } from "../../Visualizer/interactionMode";
10
7
  import { EngineRef, Feature, LayerSelectionReason, LayersRef, SketchRef } from "../types";
11
8
 
12
9
  import useHooks from "./hooks";
13
- import { SketchEventProps, SketchFeature, SketchType } from "./types";
10
+ import { SketchComponentType, SketchEventProps, SketchFeature, SketchType } from "./types";
14
11
 
15
12
  export * from "./types";
16
13
 
17
- export type SketchComponentType = ComponentType<SketchComponentProps>;
18
-
19
- type GeometryOptions = {
20
- type: SketchType;
21
- controlPoints: readonly Position3d[];
22
- };
23
-
24
- type SketchComponentProps = RequireExactlyOne<
25
- {
26
- geometry?: LineString | Polygon | MultiPolygon | null;
27
- geometryOptions?: GeometryOptions | null;
28
- extrudedHeight?: number;
29
- disableShadow?: boolean;
30
- enableRelativeHeight?: boolean;
31
- color?: string;
32
- },
33
- "geometry" | "geometryOptions"
34
- >;
35
-
36
14
  export type OnLayerSelectType = (
37
15
  layerId: string | undefined,
38
16
  featureId: string | undefined,
@@ -27,3 +27,5 @@ export const PRESET_APPEARANCE: SketchAppearance = {
27
27
  strokeWidth: 2,
28
28
  },
29
29
  };
30
+
31
+ export const PRESET_COLOR: string = "#FFFFFF";
@@ -1,8 +1,29 @@
1
1
  import { Feature as GeojsonFeature, MultiPolygon, Polygon, Point, LineString } from "geojson";
2
+ import { ComponentType } from "react";
3
+ import { RequireExactlyOne } from "type-fest";
2
4
 
3
5
  import { LayerAppearanceTypes } from "../../mantle";
4
6
  import { Position3d } from "../../types";
5
7
 
8
+ type GeometryOptions = {
9
+ type: SketchType;
10
+ controlPoints: readonly Position3d[];
11
+ };
12
+
13
+ type SketchComponentProps = RequireExactlyOne<
14
+ {
15
+ geometry?: LineString | Polygon | MultiPolygon | null;
16
+ geometryOptions?: GeometryOptions | null;
17
+ extrudedHeight?: number;
18
+ disableShadow?: boolean;
19
+ enableRelativeHeight?: boolean;
20
+ color?: string;
21
+ },
22
+ "geometry" | "geometryOptions"
23
+ >;
24
+
25
+ export type SketchComponentType = ComponentType<SketchComponentProps>;
26
+
6
27
  export type SketchType =
7
28
  | "marker"
8
29
  | "polyline"
@@ -13,6 +34,16 @@ export type SketchType =
13
34
  | "extrudedRectangle"
14
35
  | "extrudedPolygon";
15
36
 
37
+ export type SketchOptions = {
38
+ color?: string;
39
+ appearance?: SketchAppearance;
40
+ dataOnly?: boolean;
41
+ disableShadow?: boolean;
42
+ enableRelativeHeight?: boolean;
43
+ rightClickToAbort?: boolean;
44
+ autoResetInteractionMode?: boolean;
45
+ };
46
+
16
47
  export type GeometryOptionsXYZ = {
17
48
  type: SketchType;
18
49
  controlPoints: Position3d[];
package/src/Map/hooks.ts CHANGED
@@ -9,7 +9,6 @@ import type {
9
9
  LayerSelectionReason,
10
10
  ComputedLayer,
11
11
  RequestingRenderMode,
12
- SceneProperty,
13
12
  SketchRef,
14
13
  } from "./types";
15
14
  import useTimelineManager, { TimelineManagerRef } from "./useTimelineManager";
@@ -24,13 +23,11 @@ export const REQUEST_RENDER_ONCE = 1;
24
23
 
25
24
  export default function ({
26
25
  ref,
27
- sceneProperty,
28
26
  timelineManagerRef,
29
27
  cursor,
30
28
  onLayerSelect,
31
29
  }: {
32
30
  ref: Ref<MapRef>;
33
- sceneProperty?: SceneProperty;
34
31
  timelineManagerRef?: TimelineManagerRef;
35
32
  cursor?: CursorType;
36
33
  onLayerSelect?: (
@@ -104,7 +101,6 @@ export default function ({
104
101
  );
105
102
 
106
103
  useTimelineManager({
107
- init: sceneProperty?.timeline,
108
104
  engineRef,
109
105
  timelineManagerRef,
110
106
  });
package/src/Map/index.tsx CHANGED
@@ -8,7 +8,7 @@ import Sketch, { SketchProps } from "./Sketch";
8
8
  import type { Engine, EngineProps } from "./types";
9
9
 
10
10
  export * from "./types";
11
- export { useGet, type WrappedRef, type Undefinable, useOverriddenProperty } from "./utils";
11
+ export { useGet, type WrappedRef, type Undefinable } from "./utils";
12
12
 
13
13
  export type {
14
14
  NaiveLayer,
@@ -36,7 +36,12 @@ export type Props = {
36
36
  engine?: string;
37
37
  } & Omit<
38
38
  LayersProps,
39
- "Feature" | "clusterComponent" | "selectionReason" | "delegatedDataTypes" | "selectedLayerId"
39
+ | "Feature"
40
+ | "clusterComponent"
41
+ | "selectionReason"
42
+ | "delegatedDataTypes"
43
+ | "selectedLayerId"
44
+ | "viewerProperty"
40
45
  > &
41
46
  Omit<EngineProps, "onLayerSelect" | "layerSelectionReason" | "selectedLayerId"> &
42
47
  Omit<SketchProps, "layersRef" | "engineRef" | "SketchComponent"> & {
@@ -54,7 +59,6 @@ function MapFn(
54
59
  layers,
55
60
  overrides,
56
61
  timelineManagerRef,
57
- sceneProperty,
58
62
  interactionMode,
59
63
  selectedFeature,
60
64
  cursor,
@@ -80,7 +84,6 @@ function MapFn(
80
84
  handleEngineLayerSelect,
81
85
  } = useHooks({
82
86
  ref,
83
- sceneProperty,
84
87
  timelineManagerRef,
85
88
  cursor,
86
89
  onLayerSelect,
@@ -123,7 +126,7 @@ function MapFn(
123
126
  clusterComponent={currentEngine?.clusterComponent}
124
127
  delegatedDataTypes={currentEngine.delegatedDataTypes}
125
128
  meta={props.meta}
126
- sceneProperty={props.property}
129
+ viewerProperty={props.property}
127
130
  requestingRenderMode={requestingRenderMode}
128
131
  onLayerSelect={handleLayerSelect}
129
132
  />
package/src/Map/ref.ts CHANGED
@@ -117,14 +117,10 @@ const layersRefKeys: FunctionKeys<LayersRef> = {
117
117
  };
118
118
 
119
119
  const sketchRefKeys: FunctionKeys<SketchRef> = {
120
+ getType: 1,
120
121
  setType: 1,
121
- setColor: 1,
122
- setDefaultAppearance: 1,
123
- createDataOnly: 1,
124
- disableShadow: 1,
125
- enableRelativeHeight: 1,
126
- allowRightClickToAbort: 1,
127
- allowAutoResetInteractionMode: 1,
122
+ getOptions: 1,
123
+ overrideOptions: 1,
128
124
  };
129
125
 
130
126
  export function mapRef({