@reearth/core 0.0.7-alpha.37 → 0.0.7-alpha.39

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/index.d.ts CHANGED
@@ -368,13 +368,21 @@ export declare type CoreVisualizerProps = {
368
368
  onSketchFeatureDelete?: (layerId: string, featureId: string) => void;
369
369
  onInteractionModeChange?: (mode: InteractionModeType) => void;
370
370
  onAPIReady?: () => void;
371
- onCreditsUpdate?: (credits: Credit[]) => void;
371
+ onCreditsUpdate?: (credits?: Credits) => void;
372
372
  };
373
373
 
374
- export declare type Credit = {
374
+ export declare type CreditItem = {
375
375
  html?: string;
376
376
  };
377
377
 
378
+ export declare type Credits = {
379
+ engine: {
380
+ cesium?: CreditItem;
381
+ };
382
+ lightbox: CreditItem[];
383
+ screen: CreditItem[];
384
+ };
385
+
378
386
  declare type CursorType = "default" | "auto" | "help" | "pointer" | "grab" | "crosshair" | "wait";
379
387
 
380
388
  export declare type Data = {
@@ -518,7 +526,7 @@ export declare type EngineProps = {
518
526
  onLayerSelectWithRectStart?: (e: LayerSelectWithRectStart) => void;
519
527
  onLayerSelectWithRectMove?: (e: LayerSelectWithRectMove) => void;
520
528
  onLayerSelectWithRectEnd?: (e: LayerSelectWithRectEnd) => void;
521
- onCreditsUpdate?: (credits: Credit[]) => void;
529
+ onCreditsUpdate?: (credits?: Credits) => void;
522
530
  };
523
531
 
524
532
  export declare type EngineRef = {
@@ -607,7 +615,7 @@ export declare type EngineRef = {
607
615
  unselectFeatures: (layerId: string, featureId: string[]) => void;
608
616
  pickManyFromViewport: (windowPosition: [x: number, y: number], windowWidth: number, windowHeight: number, condition?: (f: PickedFeature) => boolean) => PickedFeature[] | undefined;
609
617
  calcRectangleControlPoint: (p1: Position3d, p2: Position3d, p3: Position3d) => [p1: Position3d, p2: Position3d, p3: Position3d];
610
- getCredits: () => Credit[] | undefined;
618
+ getCredits: () => Credits | undefined;
611
619
  } & MouseEventHandles;
612
620
 
613
621
  export declare const engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.37",
3
+ "version": "0.0.7-alpha.39",
4
4
  "author": "Re:Earth contributors <community@reearth.io>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A library that abstracts a map engine as one common API.",
@@ -212,7 +212,7 @@ export type EngineRef = {
212
212
  p2: Position3d,
213
213
  p3: Position3d,
214
214
  ) => [p1: Position3d, p2: Position3d, p3: Position3d];
215
- getCredits: () => Credit[] | undefined;
215
+ getCredits: () => Credits | undefined;
216
216
  } & MouseEventHandles;
217
217
 
218
218
  export type EngineProps = {
@@ -261,7 +261,7 @@ export type EngineProps = {
261
261
  onLayerSelectWithRectStart?: (e: LayerSelectWithRectStart) => void;
262
262
  onLayerSelectWithRectMove?: (e: LayerSelectWithRectMove) => void;
263
263
  onLayerSelectWithRectEnd?: (e: LayerSelectWithRectEnd) => void;
264
- onCreditsUpdate?: (credits: Credit[]) => void;
264
+ onCreditsUpdate?: (credits?: Credits) => void;
265
265
  };
266
266
 
267
267
  export type LayerEditEvent = {
@@ -386,6 +386,14 @@ export type SketchRef = {
386
386
  onEditFeatureChange: (cb: SketchEditFeatureChangeCb) => void;
387
387
  };
388
388
 
389
- export type Credit = {
389
+ export type CreditItem = {
390
390
  html?: string;
391
391
  };
392
+
393
+ export type Credits = {
394
+ engine: {
395
+ cesium?: CreditItem;
396
+ };
397
+ lightbox: CreditItem[];
398
+ screen: CreditItem[];
399
+ };
@@ -12,7 +12,7 @@ import {
12
12
  type LatLng,
13
13
  type Cluster,
14
14
  type ComputedLayer,
15
- type Credit,
15
+ type Credits,
16
16
  } from "../Map";
17
17
  import { SketchFeature, SketchType } from "../Map/Sketch/types";
18
18
 
@@ -64,7 +64,7 @@ export type CoreVisualizerProps = {
64
64
  onSketchFeatureDelete?: (layerId: string, featureId: string) => void;
65
65
  onInteractionModeChange?: (mode: InteractionModeType) => void;
66
66
  onAPIReady?: () => void;
67
- onCreditsUpdate?: (credits: Credit[]) => void;
67
+ onCreditsUpdate?: (credits?: Credits) => void;
68
68
  };
69
69
 
70
70
  export const CoreVisualizer = memo(
@@ -42,6 +42,7 @@ import { MutableRefObject, useMemo } from "react";
42
42
 
43
43
  import type { Camera, Clock } from "..";
44
44
  import { ClassificationType } from "../../mantle";
45
+ import { Credits } from "../../Map";
45
46
  import type {
46
47
  CameraOptions,
47
48
  FlyToDestination,
@@ -57,6 +58,7 @@ import { DEFAULT_SCREEN_SPACE_CAMERA_ASSIGNMENTS } from "./constants";
57
58
  export const layerIdField = `__reearth_layer_id`;
58
59
 
59
60
  const defaultImageSize = 50;
61
+ const emptyCredites: Credits = { engine: {}, lightbox: [], screen: [] };
60
62
 
61
63
  const drawIcon = (
62
64
  image: HTMLImageElement | undefined,
@@ -903,7 +905,7 @@ export function getExtrudedHeight(
903
905
  }
904
906
 
905
907
  export function getCredits(viewer: Viewer) {
906
- if (!viewer) return;
908
+ if (!viewer) return emptyCredites;
907
909
  const creditDisplay = viewer.creditDisplay as
908
910
  | (CreditDisplay & {
909
911
  _currentFrameCredits: {
@@ -914,22 +916,22 @@ export function getCredits(viewer: Viewer) {
914
916
  })
915
917
  | undefined;
916
918
 
917
- if (!creditDisplay) return;
919
+ if (!creditDisplay) return emptyCredites;
918
920
 
919
921
  const { lightboxCredits, screenCredits } = creditDisplay?._currentFrameCredits || {};
920
922
  const cesiumCredits = creditDisplay._currentCesiumCredit;
921
923
 
922
- const credits: {
923
- html?: string;
924
- }[] = [
925
- ...(cesiumCredits?.html ? [{ html: cesiumCredits.html }] : []),
926
- ...Array.from(lightboxCredits?._array ?? []).map(c => ({
924
+ const credits: Credits = {
925
+ engine: {
926
+ cesium: cesiumCredits?.html ? { html: cesiumCredits.html } : undefined,
927
+ },
928
+ lightbox: Array.from(lightboxCredits?._array ?? []).map(c => ({
927
929
  html: c?.credit?.html,
928
930
  })),
929
- ...Array.from(screenCredits?._array ?? []).map(c => ({
931
+ screen: Array.from(screenCredits?._array ?? []).map(c => ({
930
932
  html: c?.credit?.html,
931
933
  })),
932
- ];
934
+ };
933
935
 
934
936
  return credits;
935
937
  }
@@ -27,7 +27,7 @@ import type {
27
27
  import { e2eAccessToken, setE2ECesiumViewer } from "../../e2eConfig";
28
28
  import { ComputedFeature, DataType, SelectedFeatureInfo, LatLng, Camera } from "../../mantle";
29
29
  import {
30
- Credit,
30
+ Credits,
31
31
  LayerLoadEvent,
32
32
  LayerSelectWithRectEnd,
33
33
  LayerSelectWithRectMove,
@@ -130,7 +130,7 @@ export default ({
130
130
  onLayerLoad?: (e: LayerLoadEvent) => void;
131
131
  onCameraChange?: (camera: Camera) => void;
132
132
  onMount?: () => void;
133
- onCreditsUpdate?: (credits: Credit[]) => void;
133
+ onCreditsUpdate?: (credits: Credits) => void;
134
134
  }) => {
135
135
  const cesium = useRef<CesiumComponentRef<CesiumViewer>>(null);
136
136
 
@@ -665,7 +665,7 @@ export default ({
665
665
  if (!onCreditsUpdateRef.current) return;
666
666
  const viewer = cesium.current?.cesiumElement;
667
667
  if (!viewer || viewer.isDestroyed()) return;
668
- const credits: Credit[] = getCredits(viewer) ?? [];
668
+ const credits = getCredits(viewer);
669
669
  onCreditsUpdateRef.current(credits);
670
670
  }, 3000);
671
671
  }, []);
@@ -26,6 +26,14 @@ describe("replaceDefines", () => {
26
26
  });
27
27
  expect(result).toBe("(value1) + (value2)");
28
28
  });
29
+
30
+ test("should handle Japanese text with multiple variables", () => {
31
+ const result = replaceDefines("${住所} (${人数}人)", {
32
+ 住所: "東京都渋谷区",
33
+ 人数: "5",
34
+ });
35
+ expect(result).toBe("(東京都渋谷区) ((5)人)");
36
+ });
29
37
  });
30
38
 
31
39
  describe("removeBackslashes", () => {
@@ -40,6 +48,70 @@ describe("removeBackslashes", () => {
40
48
  });
41
49
  });
42
50
 
51
+ describe("Expression evaluation", () => {
52
+ test("should evaluate Japanese expression with feature properties as string literal", () => {
53
+ const expressionString = '"${住所} (${人数}人)"';
54
+ const feature = {
55
+ properties: {
56
+ 住所: "緑町",
57
+ 人数: 2,
58
+ },
59
+ } as Feature;
60
+
61
+ const expression = new Expression(expressionString, feature);
62
+ const result = expression.evaluate();
63
+
64
+ expect(result).toBe("緑町 (2人)");
65
+ });
66
+
67
+ test("should evaluate Japanese expression with two spaces - user observation", () => {
68
+ const expressionString = '"${住所} (${人数}人)"';
69
+ const feature = {
70
+ properties: {
71
+ 住所: "緑町",
72
+ 人数: 2,
73
+ },
74
+ } as Feature;
75
+
76
+ const expression = new Expression(expressionString, feature);
77
+ const result = expression.evaluate();
78
+
79
+ expect(result).toBe("緑町 (2人)");
80
+ });
81
+
82
+ test("should evaluate expression with multiple variables", () => {
83
+ const expressionString = '"${name}: ${住所} (${人数}人) - ${status}"';
84
+ const feature = {
85
+ properties: {
86
+ name: "太郎",
87
+ 住所: "緑町",
88
+ 人数: 2,
89
+ status: "完了",
90
+ },
91
+ } as Feature;
92
+
93
+ const expression = new Expression(expressionString, feature);
94
+ const result = expression.evaluate();
95
+
96
+ expect(result).toBe("太郎: 緑町 (2人) - 完了");
97
+ });
98
+
99
+ test("should evaluate Japanese expression without quotes - shows the issue", () => {
100
+ const expressionString = "${住所} (${人数}人)";
101
+ const feature = {
102
+ properties: {
103
+ 住所: "緑町",
104
+ 人数: 2,
105
+ },
106
+ } as Feature;
107
+
108
+ expect(() => {
109
+ const expression = new Expression(expressionString, feature);
110
+ expression.evaluate();
111
+ }).toThrow('Unexpected function call "czm_住所"');
112
+ });
113
+ });
114
+
43
115
  describe("expression caches", () => {
44
116
  beforeEach(() => {
45
117
  EXPRESSION_CACHES.clear();
@@ -175,18 +175,16 @@ export class Node {
175
175
  }
176
176
  _evaluateVariableString(feature?: Feature) {
177
177
  const variableRegex = /\${(.*?)}/g;
178
- let result = this._value;
179
- let match = variableRegex.exec(result);
180
- while (match !== null) {
181
- const placeholder = match[0];
182
- const variableName = match[1];
183
- let property = feature?.properties[variableName];
184
- if (typeof property === "undefined") {
185
- property = "";
186
- }
187
- result = result.replace(placeholder, property);
188
- match = variableRegex.exec(result);
189
- }
178
+ const result = this._value.replace(
179
+ variableRegex,
180
+ (_placeholder: string, variableName: string) => {
181
+ let property = feature?.properties[variableName];
182
+ if (typeof property === "undefined") {
183
+ property = "";
184
+ }
185
+ return property;
186
+ },
187
+ );
190
188
  return result;
191
189
  }
192
190
  _evaluateVariable(feature?: Feature) {