@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.45",
3
+ "version": "0.0.7-alpha.47",
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.",
@@ -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 <= currentTime ? currentTime + DEFAULT_RANGE : 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
- const style = computedFeature?.["3dtiles"];
225
+ if (!useExternalStyle) {
226
+ const style = computedFeature?.["3dtiles"];
224
227
 
225
- COMMON_STYLE_PROPERTIES.forEach(({ name, convert }) => {
226
- const val = convertStyle(style?.[name], convert);
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
- // Apply color from style.
233
- if (val !== undefined) {
234
- raw.color = val;
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
- // Apply color for selected feature.
238
- if (isFeatureSelected && typeof layer["3dtiles"]?.selectedFeatureColor === "string") {
239
- raw.color = toColor(layer["3dtiles"]?.selectedFeatureColor) ?? val;
240
- }
241
- } else {
242
- if (val !== undefined) {
243
- raw[name] = val;
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
- if ("style" in raw) {
258
- raw.style = new Cesium3DTileStyle(
259
- // TODO: Convert value if it's necessary
260
- MODEL_STYLE_PROPERTIES.reduce((res, { name, convert }) => {
261
- const val = convertStyle(style?.[name as keyof typeof style], convert);
262
- if (val === undefined) return res;
263
- return { ...res, [name]: val };
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) return;
734
- setStyle(new Cesium3DTileStyle(await res.json()));
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