@reearth/core 0.0.7-alpha.45 → 0.0.7-alpha.47
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 +960 -947
- package/dist/core.umd.cjs +57 -57
- package/package.json +1 -1
- package/src/Map/useTimelineManager.ts +1 -1
- package/src/engines/Cesium/Feature/Tileset/hooks.ts +57 -40
package/package.json
CHANGED
|
@@ -112,7 +112,7 @@ export default ({ init, engineRef, timelineManagerRef }: Props) => {
|
|
|
112
112
|
const currentTime = current.getTime();
|
|
113
113
|
|
|
114
114
|
const convertedStartTime = startTime > currentTime ? currentTime : startTime;
|
|
115
|
-
const convertedStopTime = stopTime
|
|
115
|
+
const convertedStopTime = stopTime < currentTime ? currentTime + DEFAULT_RANGE : stopTime;
|
|
116
116
|
|
|
117
117
|
return {
|
|
118
118
|
start: new Date(convertedStartTime),
|
|
@@ -187,6 +187,7 @@ const useFeature = ({
|
|
|
187
187
|
onComputedFeatureFetch,
|
|
188
188
|
shouldUseFeatureIndex,
|
|
189
189
|
isTilesetReady,
|
|
190
|
+
useExternalStyle,
|
|
190
191
|
}: {
|
|
191
192
|
id?: string;
|
|
192
193
|
tilesetRef: MutableRefObject<Cesium3DTileset | undefined>;
|
|
@@ -199,6 +200,7 @@ const useFeature = ({
|
|
|
199
200
|
selectedFeatureIdsRef: MutableRefObject<string[]>;
|
|
200
201
|
shouldUseFeatureIndex?: boolean;
|
|
201
202
|
isTilesetReady: boolean;
|
|
203
|
+
useExternalStyle?: boolean;
|
|
202
204
|
}) => {
|
|
203
205
|
const cachedFeaturesRef = useRef<CachedFeature[]>([]);
|
|
204
206
|
const cachedCalculatedLayerRef = useRef(layer);
|
|
@@ -220,49 +222,51 @@ const useFeature = ({
|
|
|
220
222
|
|
|
221
223
|
const computedFeature = evalFeature(layer, { ...feature?.feature, properties });
|
|
222
224
|
|
|
223
|
-
|
|
225
|
+
if (!useExternalStyle) {
|
|
226
|
+
const style = computedFeature?.["3dtiles"];
|
|
224
227
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (name === "color") {
|
|
229
|
-
// Reset color to default so that new style could update all.
|
|
230
|
-
raw.color = DEFAULT_FEATURE_COLOR;
|
|
228
|
+
COMMON_STYLE_PROPERTIES.forEach(({ name, convert }) => {
|
|
229
|
+
const val = convertStyle(style?.[name], convert);
|
|
231
230
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
raw.color =
|
|
231
|
+
if (name === "color") {
|
|
232
|
+
// Reset color to default so that new style could update all.
|
|
233
|
+
raw.color = DEFAULT_FEATURE_COLOR;
|
|
234
|
+
|
|
235
|
+
// Apply color from style.
|
|
236
|
+
if (val !== undefined) {
|
|
237
|
+
raw.color = val;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Apply color for selected feature.
|
|
241
|
+
if (isFeatureSelected && typeof layer["3dtiles"]?.selectedFeatureColor === "string") {
|
|
242
|
+
raw.color = toColor(layer["3dtiles"]?.selectedFeatureColor) ?? val;
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
if (val !== undefined) {
|
|
246
|
+
raw[name] = val;
|
|
247
|
+
}
|
|
235
248
|
}
|
|
249
|
+
});
|
|
236
250
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
251
|
+
if (raw instanceof Cesium3DTilePointFeature) {
|
|
252
|
+
POINT_STYLE_PROPERTIES.forEach(({ name, convert }) => {
|
|
253
|
+
const val = convertStyle(style?.[name], convert);
|
|
254
|
+
if (val !== undefined) {
|
|
255
|
+
raw[name] = val;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
245
258
|
}
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
if (raw instanceof Cesium3DTilePointFeature) {
|
|
249
|
-
POINT_STYLE_PROPERTIES.forEach(({ name, convert }) => {
|
|
250
|
-
const val = convertStyle(style?.[name], convert);
|
|
251
|
-
if (val !== undefined) {
|
|
252
|
-
raw[name] = val;
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
259
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
260
|
+
if ("style" in raw) {
|
|
261
|
+
raw.style = new Cesium3DTileStyle(
|
|
262
|
+
// TODO: Convert value if it's necessary
|
|
263
|
+
MODEL_STYLE_PROPERTIES.reduce((res, { name, convert }) => {
|
|
264
|
+
const val = convertStyle(style?.[name as keyof typeof style], convert);
|
|
265
|
+
if (val === undefined) return res;
|
|
266
|
+
return { ...res, [name]: val };
|
|
267
|
+
}, {}),
|
|
268
|
+
);
|
|
269
|
+
}
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
attachTag(feature.raw, {
|
|
@@ -276,7 +280,7 @@ const useFeature = ({
|
|
|
276
280
|
}
|
|
277
281
|
return;
|
|
278
282
|
},
|
|
279
|
-
[evalFeature, layerId, viewer, shouldUseFeatureIndex, selectedFeatureIdsRef],
|
|
283
|
+
[evalFeature, layerId, viewer, shouldUseFeatureIndex, selectedFeatureIdsRef, useExternalStyle],
|
|
280
284
|
);
|
|
281
285
|
|
|
282
286
|
const handleTilesetLoad = useCallback(
|
|
@@ -615,6 +619,7 @@ export const useHooks = ({
|
|
|
615
619
|
selectedFeatureIdsRef,
|
|
616
620
|
shouldUseFeatureIndex,
|
|
617
621
|
isTilesetReady,
|
|
622
|
+
useExternalStyle: !!styleUrl,
|
|
618
623
|
});
|
|
619
624
|
|
|
620
625
|
const [terrainHeightEstimate, setTerrainHeightEstimate] = useState(0);
|
|
@@ -730,11 +735,23 @@ export const useHooks = ({
|
|
|
730
735
|
}
|
|
731
736
|
(async () => {
|
|
732
737
|
const res = await fetch(styleUrl);
|
|
733
|
-
if (!res.ok)
|
|
734
|
-
|
|
738
|
+
if (!res.ok) {
|
|
739
|
+
console.warn("Failed to fetch style from:", styleUrl);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const styleData = await res.json();
|
|
743
|
+
const newStyle = new Cesium3DTileStyle(styleData);
|
|
744
|
+
setStyle(newStyle);
|
|
735
745
|
})();
|
|
736
746
|
}, [styleUrl]);
|
|
737
747
|
|
|
748
|
+
// Apply style to tileset when both external style and tileset are ready
|
|
749
|
+
useEffect(() => {
|
|
750
|
+
if (style && tilesetRef.current && isTilesetReady) {
|
|
751
|
+
tilesetRef.current.style = style;
|
|
752
|
+
}
|
|
753
|
+
}, [style, isTilesetReady]);
|
|
754
|
+
|
|
738
755
|
const googleMapPhotorealisticResource = useMemo(() => {
|
|
739
756
|
if (type !== "google-photorealistic" || !isVisible) return null;
|
|
740
757
|
|