@reearth/core 0.0.7-alpha.12 → 0.0.7-alpha.14
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 +114 -99
- package/dist/core.umd.cjs +4 -4
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/Map/types/viewerProperty.ts +2 -0
- package/src/engines/Cesium/common.ts +8 -9
- package/src/engines/Cesium/core/labels/JapanGSIOptimalBVmapVectorMapLabel/JapanGSIOptimalBVmapLabelImagery.tsx +8 -1
- package/src/engines/Cesium/core/labels/JapanGSIOptimalBVmapVectorMapLabel/JapanGSIOptimalBVmapVectorMapLabel.tsx +14 -2
- package/src/engines/Cesium/core/labels/LabelImageryLayers.tsx +10 -1
- package/src/utils/image.ts +1 -11
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
CameraEventType,
|
|
37
37
|
KeyboardEventModifier,
|
|
38
38
|
} from "cesium";
|
|
39
|
-
import {
|
|
39
|
+
import { MutableRefObject, useMemo } from "react";
|
|
40
40
|
|
|
41
41
|
import type { Camera, Clock } from "..";
|
|
42
42
|
import { ClassificationType } from "../../mantle";
|
|
@@ -48,7 +48,7 @@ import type {
|
|
|
48
48
|
OverideKeyboardEventModifier,
|
|
49
49
|
ScreenSpaceCameraControllerOptions,
|
|
50
50
|
} from "../../types";
|
|
51
|
-
import { tweenInterval,
|
|
51
|
+
import { tweenInterval, useImage, LatLngHeight } from "../../utils";
|
|
52
52
|
|
|
53
53
|
import { DEFAULT_SCREEN_SPACE_CAMERA_ASSIGNMENTS } from "./constants";
|
|
54
54
|
|
|
@@ -56,8 +56,7 @@ export const layerIdField = `__reearth_layer_id`;
|
|
|
56
56
|
|
|
57
57
|
const defaultImageSize = 50;
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
c: HTMLCanvasElement,
|
|
59
|
+
const drawIcon = (
|
|
61
60
|
image: HTMLImageElement | undefined,
|
|
62
61
|
w: number,
|
|
63
62
|
h: number,
|
|
@@ -68,6 +67,7 @@ export const drawIcon = (
|
|
|
68
67
|
shadowOffsetX = 0,
|
|
69
68
|
shadowOffsetY = 0,
|
|
70
69
|
) => {
|
|
70
|
+
const c = document.createElement("canvas");
|
|
71
71
|
const ctx = c.getContext("2d");
|
|
72
72
|
if (!image || !ctx) return;
|
|
73
73
|
|
|
@@ -104,6 +104,7 @@ export const drawIcon = (
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
ctx.restore();
|
|
107
|
+
return c.toDataURL();
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
export const useIcon = ({
|
|
@@ -138,13 +139,11 @@ export const useIcon = ({
|
|
|
138
139
|
? Math.floor(img.height * imageSize)
|
|
139
140
|
: Math.floor((w / img.width) * img.height);
|
|
140
141
|
|
|
141
|
-
const
|
|
142
|
-
(
|
|
143
|
-
drawIcon(can, img, w, h, crop, shadow, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY),
|
|
142
|
+
const canvas = useMemo(
|
|
143
|
+
() => drawIcon(img, w, h, crop, shadow, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY),
|
|
144
144
|
[crop, h, img, shadow, shadowBlur, shadowColor, shadowOffsetX, shadowOffsetY, w],
|
|
145
145
|
);
|
|
146
|
-
|
|
147
|
-
return [canvas, w, h];
|
|
146
|
+
return [canvas ?? "", w, h];
|
|
148
147
|
};
|
|
149
148
|
|
|
150
149
|
export const ho = (o: "left" | "center" | "right" | undefined): HorizontalOrigin | undefined =>
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type Ellipsoid,
|
|
13
13
|
type Label,
|
|
14
14
|
} from "@cesium/engine";
|
|
15
|
+
import { DistanceDisplayCondition } from "cesium";
|
|
15
16
|
import { merge, omit } from "lodash-es";
|
|
16
17
|
import { type Feature } from "protomaps";
|
|
17
18
|
import { memo, useCallback, useEffect, useMemo, useRef, type FC } from "react";
|
|
@@ -170,6 +171,8 @@ export interface JapanGSIOptimalBVmapLabelImageryProps {
|
|
|
170
171
|
height?: number;
|
|
171
172
|
style?: AnnotationStyle;
|
|
172
173
|
labelCollection?: LabelCollection;
|
|
174
|
+
near?: number;
|
|
175
|
+
far?: number;
|
|
173
176
|
}
|
|
174
177
|
|
|
175
178
|
export const JapanGSIOptimalBVmapLabelImagery: FC<JapanGSIOptimalBVmapLabelImageryProps> = memo(
|
|
@@ -180,6 +183,8 @@ export const JapanGSIOptimalBVmapLabelImagery: FC<JapanGSIOptimalBVmapLabelImage
|
|
|
180
183
|
height = 50,
|
|
181
184
|
style = defaultStyle,
|
|
182
185
|
labelCollection,
|
|
186
|
+
near,
|
|
187
|
+
far,
|
|
183
188
|
}) => {
|
|
184
189
|
const cesiumContext = useCesium();
|
|
185
190
|
|
|
@@ -282,6 +287,8 @@ export const JapanGSIOptimalBVmapLabelImagery: FC<JapanGSIOptimalBVmapLabelImage
|
|
|
282
287
|
horizontalOrigin: HorizontalOrigin.CENTER,
|
|
283
288
|
verticalOrigin: VerticalOrigin.BOTTOM,
|
|
284
289
|
heightReference: HeightReference.CLAMP_TO_GROUND,
|
|
290
|
+
distanceDisplayCondition:
|
|
291
|
+
near || far ? new DistanceDisplayCondition(near, far) : undefined,
|
|
285
292
|
disableDepthTestDistance: Infinity,
|
|
286
293
|
...styleOptions,
|
|
287
294
|
};
|
|
@@ -308,7 +315,7 @@ export const JapanGSIOptimalBVmapLabelImagery: FC<JapanGSIOptimalBVmapLabelImage
|
|
|
308
315
|
scene?.postRender.addEventListener(removeLabels);
|
|
309
316
|
}
|
|
310
317
|
};
|
|
311
|
-
}, [style, annotations, scene, labelCollection]);
|
|
318
|
+
}, [style, annotations, scene, labelCollection, near, far]);
|
|
312
319
|
|
|
313
320
|
useEffect(() => {
|
|
314
321
|
updateVisibility();
|
|
@@ -143,7 +143,9 @@ const LabelImageryCollection: FC<{
|
|
|
143
143
|
imageriesAtom: Atom<KeyedImagery[]>;
|
|
144
144
|
style?: AnnotationStyle;
|
|
145
145
|
labelCollection?: LabelCollection;
|
|
146
|
-
|
|
146
|
+
near?: number;
|
|
147
|
+
far?: number;
|
|
148
|
+
}> = ({ imageryProvider, imageriesAtom, style, labelCollection, near, far }) => {
|
|
147
149
|
const imageries = useAtomValue(imageriesAtom);
|
|
148
150
|
return (
|
|
149
151
|
<>
|
|
@@ -155,6 +157,8 @@ const LabelImageryCollection: FC<{
|
|
|
155
157
|
descendants={imagery.descendants}
|
|
156
158
|
style={style}
|
|
157
159
|
labelCollection={labelCollection}
|
|
160
|
+
near={near}
|
|
161
|
+
far={far}
|
|
158
162
|
/>
|
|
159
163
|
</Suspense>
|
|
160
164
|
))}
|
|
@@ -164,9 +168,15 @@ const LabelImageryCollection: FC<{
|
|
|
164
168
|
|
|
165
169
|
export interface VectorMapLabelProps {
|
|
166
170
|
style?: Record<string, any>;
|
|
171
|
+
near?: number;
|
|
172
|
+
far?: number;
|
|
167
173
|
}
|
|
168
174
|
|
|
169
|
-
export const JapanGSIOptimalBVmapVectorMapLabel: FC<VectorMapLabelProps> = ({
|
|
175
|
+
export const JapanGSIOptimalBVmapVectorMapLabel: FC<VectorMapLabelProps> = ({
|
|
176
|
+
style,
|
|
177
|
+
near,
|
|
178
|
+
far,
|
|
179
|
+
}) => {
|
|
170
180
|
const [imageryProvider, setImageryProvider] =
|
|
171
181
|
useState<JapanGSIOptimalBVmapLabelImageryProvider>();
|
|
172
182
|
const setRef = useCallback((handle: CesiumComponentRef<CesiumImageryLayer> | null) => {
|
|
@@ -251,6 +261,8 @@ export const JapanGSIOptimalBVmapVectorMapLabel: FC<VectorMapLabelProps> = ({ st
|
|
|
251
261
|
imageriesAtom={imageriesAtom}
|
|
252
262
|
style={style}
|
|
253
263
|
labelCollection={labels}
|
|
264
|
+
near={near}
|
|
265
|
+
far={far}
|
|
254
266
|
/>
|
|
255
267
|
)}
|
|
256
268
|
</>
|
|
@@ -8,6 +8,8 @@ export interface TileLabelConfig {
|
|
|
8
8
|
labelType: "japan_gsi_optimal_bvmap";
|
|
9
9
|
fillColor?: string;
|
|
10
10
|
outlineColor?: string;
|
|
11
|
+
near?: number;
|
|
12
|
+
far?: number;
|
|
11
13
|
style: Record<string, any>;
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -23,7 +25,14 @@ const LabelImageryLayers = memo(
|
|
|
23
25
|
if (!label) return null;
|
|
24
26
|
switch (label.labelType) {
|
|
25
27
|
case "japan_gsi_optimal_bvmap":
|
|
26
|
-
return
|
|
28
|
+
return (
|
|
29
|
+
<JapanGSIOptimalBVmapVectorMapLabel
|
|
30
|
+
key={label.id}
|
|
31
|
+
style={label.style}
|
|
32
|
+
near={label.near}
|
|
33
|
+
far={label.far}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
27
36
|
default:
|
|
28
37
|
return null;
|
|
29
38
|
}
|
package/src/utils/image.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect,
|
|
1
|
+
import { useState, useEffect, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
export const useImage = (src?: string): HTMLImageElement | undefined => {
|
|
4
4
|
const imgRef = useRef<HTMLImageElement>();
|
|
@@ -23,13 +23,3 @@ export const useImage = (src?: string): HTMLImageElement | undefined => {
|
|
|
23
23
|
|
|
24
24
|
return img;
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
export const useCanvas = (cb: (canvas: HTMLCanvasElement) => void): string => {
|
|
28
|
-
const can = useMemo(() => document.createElement("canvas"), []);
|
|
29
|
-
const [data, setData] = useState<string>("");
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
cb(can);
|
|
32
|
-
setData(can.toDataURL());
|
|
33
|
-
}, [can, cb]);
|
|
34
|
-
return data;
|
|
35
|
-
};
|