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

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.17",
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);
@@ -708,31 +705,33 @@ export const useHooks = ({
708
705
  })();
709
706
  }, [styleUrl]);
710
707
 
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]);
708
+ const googleMapPhotorealisticResource = useMemo(() => {
709
+ if (type !== "google-photorealistic" || !isVisible) return null;
710
+
711
+ const loadTileset = async () => {
712
+ try {
713
+ const tileset = await createGooglePhotorealistic3DTileset(googleMapApiKey);
714
+ return tileset.resource;
715
+ } catch (error) {
716
+ console.error(`Error loading Photorealistic 3D Tiles tileset: ${error}`);
717
+ throw error;
718
+ }
719
+ };
720
+
721
+ return loadTileset();
722
+ }, [type, isVisible, googleMapApiKey]);
724
723
 
725
724
  const tilesetUrl = useMemo(() => {
726
725
  return type === "osm-buildings" && isVisible
727
726
  ? IonResource.fromAssetId(96188, {
728
727
  accessToken: meta?.cesiumIonAccessToken as string | undefined,
729
728
  }) // https://github.com/CesiumGS/cesium/blob/main/packages/engine/Source/Scene/createOsmBuildings.js#L53
730
- : googleMapResource
731
- ? googleMapResource
729
+ : googleMapPhotorealisticResource && isVisible
730
+ ? googleMapPhotorealisticResource
732
731
  : type === "3dtiles" && isVisible
733
732
  ? url ?? tileset
734
733
  : null;
735
- }, [isVisible, tileset, url, type, meta, googleMapResource]);
734
+ }, [type, isVisible, meta?.cesiumIonAccessToken, googleMapPhotorealisticResource, url, tileset]);
736
735
 
737
736
  const imageBasedLighting = useMemo(() => {
738
737
  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