-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
createGooglePhotorealistic3DTileset.js
53 lines (47 loc) · 1.66 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
import Cesium3DTileset from "./Cesium3DTileset.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.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
* 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) {
key = defaultValue(key, GoogleMaps.defaultApiKey);
let credits;
const credit = GoogleMaps.getDefaultApiKeyCredit(key);
if (defined(credit)) {
credits = [credit];
}
options = defaultValue(options, {});
options.showCreditsOnScreen = true;
const resource = new Resource({
url: `${GoogleMaps.mapTilesApiEndpoint}3dtiles/root.json`,
queryParameters: {
key: key,
},
credits: credits,
});
return Cesium3DTileset.fromUrl(resource, options);
}
export default createGooglePhotorealistic3DTileset;