Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | 8x 7x 7x 7x 7x 7x 1x 1x 5x 2x 1x 1x 1x 2x 1x 1x 7x 7x 5x 5x 5x 2x | import Check from "../Core/Check.js";
import Event from "../Core/Event.js";
import createWorldBathymetryAsync from "../Core/createWorldBathymetryAsync.js";
import createWorldTerrainAsync from "../Core/createWorldTerrainAsync.js";
/**
* A helper to manage async operations of a terrain provider.
*
* @alias Terrain
* @constructor
*
* @see Terrain.fromWorldTerrain
* @see CesiumTerrainProvider
* @see VRTheWorldTerrainProvider
* @see GoogleEarthEnterpriseTerrainProvider
*
* @example
* // Create
* const viewer = new Cesium.Viewer("cesiumContainer", {
* terrain: new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));
* });
*
* @example
* // Handle loading events
* const terrain = new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));
*
* scene.setTerrain(terrain);
*
* terrain.readyEvent.addEventListener(provider => {
* scene.globe.enableLighting = true;
*
* terrain.provider.errorEvent.addEventListener(error => {
* alert(`Encountered an error while loading terrain tiles! ${error}`);
* });
* });
*
* terrain.errorEvent.addEventListener(error => {
* alert(`Encountered an error while creating terrain! ${error}`);
* });
*
* @param {Promise<TerrainProvider>} terrainProviderPromise A promise which resolves to a terrain provider
*/
function Terrain(terrainProviderPromise) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("terrainProviderPromise", terrainProviderPromise);
//>>includeEnd('debug');
this._ready = false;
this._provider = undefined;
this._errorEvent = new Event();
this._readyEvent = new Event();
handlePromise(this, terrainProviderPromise);
}
Object.defineProperties(Terrain.prototype, {
/**
* Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing
* to the event, you will be notified of the error and can potentially recover from it. Event listeners
* are passed an instance of the thrown error.
* @memberof Terrain.prototype
* @type {Event<Terrain.ErrorEventCallback>}
* @readonly
*/
errorEvent: {
get: function () {
return this._errorEvent;
},
},
/**
* Gets an event that is raised when the terrain provider has been successfully created. Event listeners
* are passed the created instance of {@link TerrainProvider}.
* @memberof Terrain.prototype
* @type {Event<Terrain.ReadyEventCallback>}
* @readonly
*/
readyEvent: {
get: function () {
return this._readyEvent;
},
},
/**
* Returns true when the terrain provider has been successfully created. Otherwise, returns false.
* @memberof Terrain.prototype
*
* @type {boolean}
* @readonly
*/
ready: {
get: function () {
return this._ready;
},
},
/**
* The terrain provider providing surface geometry to a globe. Do not use until {@link Terrain.readyEvent} is raised.
* @memberof Terrain.prototype
*
* @type {TerrainProvider}
* @readonly
*/
provider: {
get: function () {
return this._provider;
},
},
});
/**
* Creates a {@link Terrain} instance for {@link https://cesium.com/content/#cesium-world-terrain|Cesium World Terrain}.
*
* @function
*
* @param {object} [options] Object with the following properties:
* @param {boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server if available.
* @param {boolean} [options.requestWaterMask=false] Flag that indicates if the client should request per tile water masks from the server if available.
* @returns {Terrain} An asynchronous helper object for a CesiumTerrainProvider
*
* @see Ion
* @see createWorldTerrainAsync
*
* @example
* // Create Cesium World Terrain with default settings
* const viewer = new Cesium.Viewer("cesiumContainer", {
* terrain: Cesium.Terrain.fromWorldTerrain()
* });
*
* @example
* // Create Cesium World Terrain with water and normals.
* const viewer1 = new Cesium.Viewer("cesiumContainer", {
* terrain: Cesium.Terrain.fromWorldTerrain({
* requestWaterMask: true,
* requestVertexNormals: true
* });
* });
*
* @example
* // Handle loading events
* const terrain = Cesium.Terrain.fromWorldTerrain();
*
* scene.setTerrain(terrain);
*
* terrain.readyEvent.addEventListener(provider => {
* scene.globe.enableLighting = true;
*
* terrain.provider.errorEvent.addEventListener(error => {
* alert(`Encountered an error while loading terrain tiles! ${error}`);
* });
* });
*
* terrain.errorEvent.addEventListener(error => {
* alert(`Encountered an error while creating terrain! ${error}`);
* });
*/
Terrain.fromWorldTerrain = function (options) {
return new Terrain(createWorldTerrainAsync(options));
};
/**
* Creates a {@link Terrain} instance for {@link https://cesium.com/content/#cesium-world-bathymetry|Cesium World Bathymetry}.
*
* @function
*
* @param {object} [options] Object with the following properties:
* @param {boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server if available.
* @returns {Terrain} An asynchronous helper object for a CesiumTerrainProvider
*
* @see Ion
* @see createWorldBathymetryAsync
*
* @example
* // Create Cesium World Bathymetry with default settings
* const viewer = new Cesium.Viewer("cesiumContainer", {
* terrain: Cesium.Terrain.fromWorldBathymetry)
* });
*
* @example
* // Create Cesium World Terrain with normals.
* const viewer1 = new Cesium.Viewer("cesiumContainer", {
* terrain: Cesium.Terrain.fromWorldBathymetry({
* requestVertexNormals: true
* });
* });
*
* @example
* // Handle loading events
* const bathymetry = Cesium.Terrain.fromWorldBathymetry();
*
* scene.setTerrain(bathymetry);
*
* bathymetry.readyEvent.addEventListener(provider => {
* scene.globe.enableLighting = true;
*
* bathymetry.provider.errorEvent.addEventListener(error => {
* alert(`Encountered an error while loading bathymetric terrain tiles! ${error}`);
* });
* });
*
* bathymetry.errorEvent.addEventListener(error => {
* alert(`Encountered an error while creating bathymetric terrain! ${error}`);
* });
*/
Terrain.fromWorldBathymetry = function (options) {
return new Terrain(createWorldBathymetryAsync(options));
};
function handleError(errorEvent, error) {
if (errorEvent.numberOfListeners > 0) {
errorEvent.raiseEvent(error);
} else {
// Default handler is to log to the console
console.error(error);
}
}
async function handlePromise(instance, promise) {
let provider;
try {
provider = await Promise.resolve(promise);
instance._provider = provider;
instance._ready = true;
instance._readyEvent.raiseEvent(provider);
} catch (error) {
handleError(instance._errorEvent, error);
}
}
export default Terrain;
/**
* A function that is called when an error occurs.
* @callback Terrain.ErrorEventCallback
*
* @this Terrain
* @param {Error} err An object holding details about the error that occurred.
*/
/**
* A function that is called when the provider has been created
* @callback Terrain.ReadyEventCallback
*
* @this Terrain
* @param {TerrainProvider} provider The created terrain provider.
*/
|