-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
createGooglePhotorealistic3DTileset.js
87 lines (78 loc) · 2.62 KB
/
createGooglePhotorealistic3DTileset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Cesium3DTileset from "./Cesium3DTileset.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import IonResource from "../Core/IonResource.js";
import GoogleMaps from "../Core/GoogleMaps.js";
import Resource from "../Core/Resource.js";
/**
* Creates a {@link Cesium3DTileset} instance for the Google Photorealistic 3D Tiles tileset.
*
* @function
*
* @param {string} [key=GoogleMaps.defaultApiKey] Your API key to access Google Photorealistic 3D Tiles. See {@link https://developers.google.com/maps/documentation/javascript/get-api-key} for instructions on how to create your own key.
* @param {Cesium3DTileset.ConstructorOptions} [options] An object describing initialization options.
* @returns {Promise<Cesium3DTileset>}
*
* @see GoogleMaps
*
* @example
* const viewer = new Cesium.Viewer("cesiumContainer");
*
* try {
* const tileset = await Cesium.createGooglePhotorealistic3DTileset();
* viewer.scene.primitives.add(tileset));
* } catch (error) {
* console.log(`Error creating tileset: ${error}`);
* }
*
* @example
* // Use your own Google Maps API key
* Cesium.GoogleMaps.defaultApiKey = "your-api-key";
*
* const viewer = new Cesium.Viewer("cesiumContainer");
*
* try {
* const tileset = await Cesium.createGooglePhotorealistic3DTileset();
* viewer.scene.primitives.add(tileset));
* } catch (error) {
* console.log(`Error creating tileset: ${error}`);
* }
*/
async function createGooglePhotorealistic3DTileset(key, options) {
options = defaultValue(options, {});
options.cacheBytes = defaultValue(options.cacheBytes, 1536 * 1024 * 1024);
options.maximumCacheOverflowBytes = defaultValue(
options.maximumCacheOverflowBytes,
1024 * 1024 * 1024
);
key = defaultValue(key, GoogleMaps.defaultApiKey);
if (!defined(key)) {
return requestCachedIonTileset(options);
}
let credits;
const credit = GoogleMaps.getDefaultCredit();
if (defined(credit)) {
credits = [credit];
}
const resource = new Resource({
url: `${GoogleMaps.mapTilesApiEndpoint}3dtiles/root.json`,
queryParameters: {
key: key,
},
credits: credits,
});
return Cesium3DTileset.fromUrl(resource, options);
}
const metadataCache = {};
async function requestCachedIonTileset(options) {
const ionAssetId = 2275207;
const cacheKey = ionAssetId;
let promise = metadataCache[cacheKey];
if (!defined(promise)) {
promise = IonResource.fromAssetId(ionAssetId);
metadataCache[cacheKey] = promise;
}
const resource = await promise;
return Cesium3DTileset.fromUrl(resource, options);
}
export default createGooglePhotorealistic3DTileset;