@reearth/core 0.0.7-alpha.16 → 0.0.7-alpha.18

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
@@ -169,7 +169,6 @@ export declare type Cesium3DTilesAppearance = {
169
169
  selectedFeatureColor?: string;
170
170
  disableIndexingFeature?: boolean;
171
171
  tileset?: string;
172
- apiKey?: string;
173
172
  experimental_clipping?: EXPERIMENTAL_clipping;
174
173
  pointSize?: number;
175
174
  meta?: unknown;
@@ -389,6 +388,9 @@ export declare type Data = {
389
388
  updateInterval?: number;
390
389
  parameters?: Record<string, any>;
391
390
  idProperty?: string;
391
+ serviceTokens?: {
392
+ googleMapApiKey?: string;
393
+ };
392
394
  time?: {
393
395
  property?: string;
394
396
  interval?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.16",
3
+ "version": "0.0.7-alpha.18",
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.",
@@ -15,13 +15,11 @@ import {
15
15
  Cesium3DTileFeature,
16
16
  Model,
17
17
  Cesium3DTilePointFeature,
18
- GoogleMaps as CesiumGoogleMaps,
19
- Resource,
20
- defaultValue,
21
18
  ImageBasedLighting,
22
19
  Cesium3DTileContent,
23
20
  Color,
24
21
  Viewer,
22
+ createGooglePhotorealistic3DTileset,
25
23
  } from "cesium";
26
24
  import { pick } from "lodash-es";
27
25
  import { MutableRefObject, useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -57,7 +55,6 @@ import {
57
55
  } from "../utils";
58
56
 
59
57
  import { TilesetFeatureIndex } from "./TilesetFeatureIndex";
60
- import { GoogleMaps } from "./types";
61
58
  import { useClippingBox } from "./useClippingBox";
62
59
  import { useDrawClipping } from "./useDrawClipping";
63
60
 
@@ -77,6 +74,7 @@ const useData = (layer: ComputedLayer | undefined) => {
77
74
  ? data.layers.join(",")
78
75
  : data?.layers
79
76
  : undefined,
77
+ googleMapApiKey: data?.serviceTokens?.googleMapApiKey,
80
78
  };
81
79
  }, [layer]);
82
80
  };
@@ -460,7 +458,6 @@ export const useHooks = ({
460
458
  edgeColor,
461
459
  edgeWidth,
462
460
  experimental_clipping,
463
- apiKey,
464
461
  selectedFeatureColor,
465
462
  disableIndexingFeature,
466
463
  } = property ?? {};
@@ -481,7 +478,7 @@ export const useHooks = ({
481
478
  } = useClippingBox({ clipping: experimental_clipping, boxId });
482
479
 
483
480
  const [style, setStyle] = useState<Cesium3DTileStyle>();
484
- const { url, type, idProperty } = useData(layer);
481
+ const { url, type, idProperty, googleMapApiKey } = useData(layer);
485
482
  const shouldUseFeatureIndex = !disableIndexingFeature && !!idProperty;
486
483
 
487
484
  const [isTilesetReady, setIsTilesetReady] = useState(false);
@@ -503,8 +500,9 @@ export const useHooks = ({
503
500
  return prevPlanes.current;
504
501
  }, [_planes]);
505
502
  const clipDirection = direction === "inside" ? -1 : 1;
503
+
506
504
  // Create immutable object
507
- const [clippingPlanes] = useState(
505
+ const [clippingPlanes, setClippingPlanes] = useState<CesiumClippingPlaneCollection>(
508
506
  () =>
509
507
  new CesiumClippingPlaneCollection({
510
508
  planes: planes?.map(
@@ -519,6 +517,27 @@ export const useHooks = ({
519
517
  edgeColor: toColor(edgeColor),
520
518
  }),
521
519
  );
520
+ // Initialize clipping planes
521
+ // This is workaround to reinitialize ClippingPlanes in strict mode.
522
+ useEffect(
523
+ () => () => {
524
+ setClippingPlanes(
525
+ new CesiumClippingPlaneCollection({
526
+ planes: planes?.map(
527
+ plane =>
528
+ new ClippingPlane(
529
+ new Cartesian3(plane.normal?.x, plane.normal?.y, plane.normal?.z),
530
+ (plane.distance || 0) * clipDirection,
531
+ ),
532
+ ),
533
+ unionClippingRegions: direction === "outside",
534
+ edgeWidth: edgeWidth,
535
+ edgeColor: toColor(edgeColor),
536
+ }),
537
+ );
538
+ },
539
+ [], // eslint-disable-line react-hooks/exhaustive-deps
540
+ );
522
541
 
523
542
  const { drawClippingEnabled, drawClippingEdgeProps } = useDrawClipping({
524
543
  ...experimental_clipping?.draw,
@@ -708,31 +727,33 @@ export const useHooks = ({
708
727
  })();
709
728
  }, [styleUrl]);
710
729
 
711
- const googleMapResource = useMemo(() => {
712
- if (type !== "google-photorealistic" || !isVisible) return;
713
- // Ref: https://github.com/CesiumGS/cesium/blob/b208135a095073386e5f04a59956ee11a03aa847/packages/engine/Source/Scene/createGooglePhotorealistic3DTileset.js#L30
714
- const googleMaps = CesiumGoogleMaps as GoogleMaps;
715
- // Default key: https://github.com/CesiumGS/cesium/blob/b208135a095073386e5f04a59956ee11a03aa847/packages/engine/Source/Core/GoogleMaps.js#L6C36-L6C36
716
- const key = defaultValue(apiKey, googleMaps.defaultApiKey);
717
- const credit = googleMaps.getDefaultApiKeyCredit(key);
718
- return new Resource({
719
- url: `${googleMaps.mapTilesApiEndpoint}3dtiles/root.json`,
720
- queryParameters: { key },
721
- credits: credit ? [credit] : undefined,
722
- } as Resource.ConstructorOptions);
723
- }, [apiKey, type, isVisible]);
730
+ const googleMapPhotorealisticResource = useMemo(() => {
731
+ if (type !== "google-photorealistic" || !isVisible) return null;
732
+
733
+ const loadTileset = async () => {
734
+ try {
735
+ const tileset = await createGooglePhotorealistic3DTileset(googleMapApiKey);
736
+ return tileset.resource;
737
+ } catch (error) {
738
+ console.error(`Error loading Photorealistic 3D Tiles tileset: ${error}`);
739
+ throw error;
740
+ }
741
+ };
742
+
743
+ return loadTileset();
744
+ }, [type, isVisible, googleMapApiKey]);
724
745
 
725
746
  const tilesetUrl = useMemo(() => {
726
747
  return type === "osm-buildings" && isVisible
727
748
  ? IonResource.fromAssetId(96188, {
728
749
  accessToken: meta?.cesiumIonAccessToken as string | undefined,
729
750
  }) // https://github.com/CesiumGS/cesium/blob/main/packages/engine/Source/Scene/createOsmBuildings.js#L53
730
- : googleMapResource
731
- ? googleMapResource
751
+ : googleMapPhotorealisticResource && isVisible
752
+ ? googleMapPhotorealisticResource
732
753
  : type === "3dtiles" && isVisible
733
754
  ? url ?? tileset
734
755
  : null;
735
- }, [isVisible, tileset, url, type, meta, googleMapResource]);
756
+ }, [type, isVisible, meta?.cesiumIonAccessToken, googleMapPhotorealisticResource, url, tileset]);
736
757
 
737
758
  const imageBasedLighting = useMemo(() => {
738
759
  if (
@@ -200,7 +200,6 @@ export type Cesium3DTilesAppearance = {
200
200
  selectedFeatureColor?: string; // This doesn't support expression
201
201
  disableIndexingFeature?: boolean;
202
202
  tileset?: string;
203
- apiKey?: string;
204
203
  experimental_clipping?: EXPERIMENTAL_clipping;
205
204
  pointSize?: number;
206
205
  meta?: unknown;
@@ -76,6 +76,9 @@ export type Data = {
76
76
  updateInterval?: number; // milliseconds
77
77
  parameters?: Record<string, any>;
78
78
  idProperty?: string;
79
+ serviceTokens?: {
80
+ googleMapApiKey?: string;
81
+ };
79
82
  time?: {
80
83
  property?: string;
81
84
  interval?: number; // milliseconds