@reearth/core 0.0.7-alpha.38 → 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/core.js +11 -11
- package/dist/core.umd.cjs +3 -3
- package/package.json +1 -1
- package/src/engines/Cesium/common.ts +3 -2
- package/src/engines/Cesium/hooks.ts +1 -1
- package/src/mantle/evaluator/simple/expression/expression.test.ts +72 -0
- package/src/mantle/evaluator/simple/expression/node.ts +10 -12
package/package.json
CHANGED
|
@@ -58,6 +58,7 @@ import { DEFAULT_SCREEN_SPACE_CAMERA_ASSIGNMENTS } from "./constants";
|
|
|
58
58
|
export const layerIdField = `__reearth_layer_id`;
|
|
59
59
|
|
|
60
60
|
const defaultImageSize = 50;
|
|
61
|
+
const emptyCredites: Credits = { engine: {}, lightbox: [], screen: [] };
|
|
61
62
|
|
|
62
63
|
const drawIcon = (
|
|
63
64
|
image: HTMLImageElement | undefined,
|
|
@@ -904,7 +905,7 @@ export function getExtrudedHeight(
|
|
|
904
905
|
}
|
|
905
906
|
|
|
906
907
|
export function getCredits(viewer: Viewer) {
|
|
907
|
-
if (!viewer) return;
|
|
908
|
+
if (!viewer) return emptyCredites;
|
|
908
909
|
const creditDisplay = viewer.creditDisplay as
|
|
909
910
|
| (CreditDisplay & {
|
|
910
911
|
_currentFrameCredits: {
|
|
@@ -915,7 +916,7 @@ export function getCredits(viewer: Viewer) {
|
|
|
915
916
|
})
|
|
916
917
|
| undefined;
|
|
917
918
|
|
|
918
|
-
if (!creditDisplay) return;
|
|
919
|
+
if (!creditDisplay) return emptyCredites;
|
|
919
920
|
|
|
920
921
|
const { lightboxCredits, screenCredits } = creditDisplay?._currentFrameCredits || {};
|
|
921
922
|
const cesiumCredits = creditDisplay._currentCesiumCredit;
|
|
@@ -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
|
|
133
|
+
onCreditsUpdate?: (credits: Credits) => void;
|
|
134
134
|
}) => {
|
|
135
135
|
const cesium = useRef<CesiumComponentRef<CesiumViewer>>(null);
|
|
136
136
|
|
|
@@ -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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
property
|
|
186
|
-
}
|
|
187
|
-
|
|
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) {
|