@reearth/core 0.0.7-alpha.23 → 0.0.7-alpha.24

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/src/Map/index.tsx CHANGED
@@ -5,6 +5,7 @@ import { INTERACTION_MODES } from "../Visualizer/interactionMode";
5
5
  import useHooks, { MapRef } from "./hooks";
6
6
  import Layers, { type Props as LayersProps } from "./Layers";
7
7
  import Sketch, { SketchProps } from "./Sketch";
8
+ import SpatialId from "./SpatialId";
8
9
  import type { Engine, EngineProps } from "./types";
9
10
 
10
11
  export * from "./types";
@@ -85,6 +86,7 @@ function MapFn(
85
86
  engineRef,
86
87
  layersRef,
87
88
  sketchRef,
89
+ spatialIdRef,
88
90
  selectedLayer,
89
91
  requestingRenderMode,
90
92
  handleLayerSelect,
@@ -94,6 +96,7 @@ function MapFn(
94
96
  handleEngineMount,
95
97
  handleLayersMount,
96
98
  handleSketchMount,
99
+ handleSpatialIdMount,
97
100
  } = useHooks({
98
101
  ref,
99
102
  timelineManagerRef,
@@ -167,6 +170,14 @@ function MapFn(
167
170
  onSketchEditFeature={setSketchEditingFeature}
168
171
  onMount={handleSketchMount}
169
172
  />
173
+ <SpatialId
174
+ ref={spatialIdRef}
175
+ engineRef={engineRef}
176
+ interactionMode={interactionMode}
177
+ terrainEnabled={!!props.property?.terrain?.enabled}
178
+ overrideInteractionMode={overrideInteractionMode}
179
+ onMount={handleSpatialIdMount}
180
+ />
170
181
  </Engine>
171
182
  ) : null;
172
183
  }
package/src/Map/ref.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { RefObject } from "react";
2
2
 
3
+ import { SpatialIdRef } from "./SpatialId/types";
3
4
  import type { EngineRef, LayersRef, SketchRef } from "./types";
4
5
  import { TimelineManagerRef } from "./useTimelineManager";
5
6
  import { FunctionKeys, WrappedRef, wrapRef } from "./utils";
@@ -8,6 +9,7 @@ export type MapRef = {
8
9
  engine: WrappedRef<EngineRef>;
9
10
  layers: WrappedRef<LayersRef>;
10
11
  sketch: WrappedRef<SketchRef>;
12
+ spatialId?: WrappedRef<SpatialIdRef>;
11
13
  timeline?: TimelineManagerRef;
12
14
  };
13
15
 
@@ -133,21 +135,30 @@ const sketchRefKeys: FunctionKeys<SketchRef> = {
133
135
  onEditFeatureChange: 1,
134
136
  };
135
137
 
138
+ const spatialIdRefKeys: FunctionKeys<SpatialIdRef> = {
139
+ pickSpace: 1,
140
+ exitPickSpace: 1,
141
+ onSpacePick: 1,
142
+ };
143
+
136
144
  export function mapRef({
137
145
  engineRef,
138
146
  layersRef,
139
147
  sketchRef,
148
+ spatialIdRef,
140
149
  timelineManagerRef,
141
150
  }: {
142
151
  engineRef: RefObject<EngineRef>;
143
152
  layersRef: RefObject<LayersRef>;
144
153
  sketchRef: RefObject<SketchRef>;
154
+ spatialIdRef: RefObject<SpatialIdRef>;
145
155
  timelineManagerRef?: TimelineManagerRef;
146
156
  }): MapRef {
147
157
  return {
148
158
  engine: wrapRef(engineRef, engineRefKeys),
149
159
  layers: wrapRef(layersRef, layersRefKeys),
150
160
  sketch: wrapRef(sketchRef, sketchRefKeys),
161
+ spatialId: wrapRef(spatialIdRef, spatialIdRefKeys),
151
162
  timeline: timelineManagerRef,
152
163
  };
153
164
  }
@@ -119,6 +119,7 @@ export type EngineRef = {
119
119
  getExtrudedHeight: (
120
120
  position: [x: number, y: number, z: number],
121
121
  windowPosition: [x: number, y: number],
122
+ allowNegative?: boolean,
122
123
  ) => number | undefined;
123
124
  getExtrudedPoint: (
124
125
  position: [x: number, y: number, z: number],
@@ -329,6 +329,7 @@ export default function useHooks(
329
329
  cameraForceHorizontalRoll,
330
330
  coreContextValue,
331
331
  containerStyle,
332
+ overriddenInteractionMode: interactionMode,
332
333
  handleLayerSelect,
333
334
  handleLayerDrag,
334
335
  handleLayerDrop,
@@ -116,6 +116,7 @@ export const CoreVisualizer = memo(
116
116
  cameraForceHorizontalRoll,
117
117
  coreContextValue,
118
118
  containerStyle,
119
+ overriddenInteractionMode,
119
120
  handleLayerSelect,
120
121
  handleLayerDrag,
121
122
  handleLayerDrop,
@@ -174,7 +175,7 @@ export const CoreVisualizer = memo(
174
175
  small={small}
175
176
  ready={ready}
176
177
  timelineManagerRef={timelineManagerRef}
177
- interactionMode={interactionMode}
178
+ interactionMode={overriddenInteractionMode}
178
179
  selectedFeature={selectedFeature}
179
180
  cursor={cursor}
180
181
  onCameraChange={handleCameraChange}
@@ -1,6 +1,6 @@
1
1
  import { FEATURE_FLAGS } from "./featureFlags";
2
2
 
3
- export type InteractionModeType = "default" | "move" | "selection" | "sketch";
3
+ export type InteractionModeType = "default" | "move" | "selection" | "sketch" | "spatialId";
4
4
 
5
5
  // If you would like enable a feature in a specific mode,
6
6
  // just set the feature's flag here to that mode.
@@ -22,4 +22,5 @@ export const INTERACTION_MODES: Record<InteractionModeType, number> = {
22
22
  FEATURE_FLAGS.CAMERA_ZOOM |
23
23
  FEATURE_FLAGS.CAMERA_TILT,
24
24
  sketch: FEATURE_FLAGS.SKETCH | FEATURE_FLAGS.CAMERA_ZOOM | FEATURE_FLAGS.CAMERA_TILT,
25
+ spatialId: FEATURE_FLAGS.CAMERA_ZOOM | FEATURE_FLAGS.CAMERA_TILT,
25
26
  };
@@ -54,6 +54,7 @@ export default function Polygon({
54
54
  fillColor,
55
55
  strokeColor,
56
56
  strokeWidth = 1,
57
+ height,
57
58
  heightReference: hr,
58
59
  shadows,
59
60
  extrudedHeight,
@@ -83,7 +84,7 @@ export default function Polygon({
83
84
  coordiantes && stroke && !disableWorkaround
84
85
  ? coordiantes.flatMap(hole => [
85
86
  // bottom
86
- hole.map(c => Cartesian3.fromDegrees(c[0], c[1], c[2] ?? 0)),
87
+ hole.map(c => Cartesian3.fromDegrees(c[0], c[1], c[2] ?? height)),
87
88
  ...(extrudedHeight
88
89
  ? [
89
90
  // top
@@ -92,14 +93,14 @@ export default function Polygon({
92
93
  ...hole
93
94
  .slice(0, -1)
94
95
  .map(c => [
95
- Cartesian3.fromDegrees(c[0], c[1], 0),
96
+ Cartesian3.fromDegrees(c[0], c[1], height ?? 0),
96
97
  Cartesian3.fromDegrees(c[0], c[1], extrudedHeight),
97
98
  ]),
98
99
  ]
99
100
  : []),
100
101
  ])
101
102
  : [],
102
- [coordiantes, stroke, disableWorkaround],
103
+ [coordiantes, stroke, disableWorkaround, height, extrudedHeight],
103
104
  );
104
105
 
105
106
  const memoStrokeColor = useMemo(
@@ -152,6 +153,7 @@ export default function Polygon({
152
153
  outline={!!memoStrokeColor}
153
154
  outlineColor={memoStrokeColor}
154
155
  outlineWidth={strokeWidth}
156
+ height={height}
155
157
  heightReference={heightReference(hr)}
156
158
  shadows={shadowMode(shadows)}
157
159
  distanceDisplayCondition={distanceDisplayCondition}
@@ -0,0 +1,42 @@
1
+ import { ClassificationType, Color, HeightReference, Rectangle } from "cesium";
2
+ import { FC, memo, useMemo } from "react";
3
+ import { Entity } from "resium";
4
+
5
+ import { SpatialIdSpaceType } from "../../../Map/SpatialId/types";
6
+
7
+ const DEFAULT_COLOR = "#00bebe";
8
+
9
+ type SpatialIdComponentProps = {
10
+ space: SpatialIdSpaceType;
11
+ };
12
+
13
+ const SpatialIdSpace: FC<SpatialIdComponentProps> = memo(({ space }) => {
14
+ const options = useMemo(
15
+ () => ({
16
+ rectangle: {
17
+ coordinates: Rectangle.fromDegrees(...space.wsen),
18
+ height: space.type === "coordinate" ? undefined : space.height,
19
+ heightReference: space.type === "coordinate" ? undefined : HeightReference.NONE,
20
+ extrudedHeight: space.type === "coordinate" ? undefined : space.extrudedHeight,
21
+ clampToGround: space.type === "coordinate",
22
+ fill: true,
23
+ outline: space.type !== "coordinate",
24
+ outlineColor: Color.fromCssColorString(space.color ?? DEFAULT_COLOR).withAlpha(
25
+ space.type === "floor" ? 0.5 : 1,
26
+ ),
27
+ material: Color.fromCssColorString(space.color ?? DEFAULT_COLOR).withAlpha(
28
+ space.type === "floor" ? 0.05 : 0.2,
29
+ ),
30
+ classificationType:
31
+ space.type === "coordinate" ? ClassificationType.BOTH : ClassificationType.TERRAIN,
32
+ },
33
+ }),
34
+ [space],
35
+ );
36
+
37
+ return <Entity id={space.id} {...options} />;
38
+ });
39
+
40
+ SpatialIdSpace.displayName = "SpatialIdSpace";
41
+
42
+ export default SpatialIdSpace;
@@ -554,7 +554,7 @@ export const colorBlendModeFor3DTile = (
554
554
  replace: Cesium3DTileColorBlendMode.REPLACE,
555
555
  mix: Cesium3DTileColorBlendMode.MIX,
556
556
  }) as { [key in string]?: Cesium3DTileColorBlendMode }
557
- )[colorBlendMode]
557
+ )[colorBlendMode];
558
558
 
559
559
  export const heightReference = (
560
560
  heightReference?: "none" | "clamp" | "relative",
@@ -853,6 +853,7 @@ export function getExtrudedHeight(
853
853
  scene: Scene,
854
854
  position: Cartesian3,
855
855
  windowPosition: Cartesian2,
856
+ allowNegative = false,
856
857
  ): number | undefined {
857
858
  const cartesianScratch = new Cartesian3();
858
859
  const normalScratch = new Cartesian3();
@@ -894,7 +895,7 @@ export function getExtrudedHeight(
894
895
  scene.globe.ellipsoid,
895
896
  cartographicScratch,
896
897
  ).height;
897
- return Math.max(0, toHeight - fromHeight);
898
+ return allowNegative ? toHeight - fromHeight : Math.max(0, toHeight - fromHeight);
898
899
  } catch (error) {
899
900
  console.error(error);
900
901
  }
@@ -35,6 +35,7 @@ import {
35
35
  getCredits,
36
36
  } from "../common";
37
37
  import { attachTag, getTag } from "../Feature";
38
+ import { getGeometryFromEntity } from "../helpers/getGeometryFromEntity";
38
39
  import { PickedFeature, pickManyFromViewportAsFeature } from "../pickMany";
39
40
  import { createGeometry } from "../Sketch/createGeometry";
40
41
  import { CursorType } from "../types";
@@ -46,7 +47,6 @@ import {
46
47
  findEntity,
47
48
  findFeaturesFromLayer,
48
49
  } from "../utils/utils";
49
- import { getGeometryFromEntity } from "../helpers/getGeometryFromEntity";
50
50
 
51
51
  export default function useEngineRef(
52
52
  ref: Ref<EngineRef>,
@@ -261,13 +261,14 @@ export default function useEngineRef(
261
261
  }
262
262
  return;
263
263
  },
264
- getExtrudedHeight: (position, windowPosition) => {
264
+ getExtrudedHeight: (position, windowPosition, allowNegative) => {
265
265
  const viewer = cesium.current?.cesiumElement;
266
266
  if (!viewer || viewer.isDestroyed()) return;
267
267
  return getExtrudedHeight(
268
268
  viewer.scene,
269
269
  new Cesium.Cartesian3(position[0], position[1], position[2]),
270
270
  new Cesium.Cartesian2(windowPosition[0], windowPosition[1]),
271
+ allowNegative,
271
272
  );
272
273
  },
273
274
  getExtrudedPoint: (position, extrudedHeight) => {
@@ -102,6 +102,7 @@ export type PolygonAppearance = {
102
102
  stroke?: boolean;
103
103
  strokeColor?: string;
104
104
  strokeWidth?: number;
105
+ height?: number;
105
106
  heightReference?: "none" | "clamp" | "relative";
106
107
  shadows?: "disabled" | "enabled" | "cast_only" | "receive_only";
107
108
  lineJoin?: CanvasLineJoin;