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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | 1x 1x 12x 12x 1x 8x 1x 26x 26x 26x 4x 4x 1x 22x 22x 12x 12x 12x 12x 1x 12x 12x 12x 12x 12x 12x 1x 2x 3x 2x 1x 1x 1x 14x 13x 1x 12x 12x 12x 1x 4x 4x 4x 1x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 1x 21x 21x 4x 4x 4x 4x 4x 4x 4x 16x 16x 16x 4x 4x 4x 17x 21x 21x 21x 21x 21x 21x 4x 4x 4x 4x 17x 17x 17x 1x 5x 1x 258x 258x 258x 258x 258x 237x 237x 237x 1x 236x 236x 236x 236x 21x 21x 21x 21x 1x 22x 22x | import Check from "./Check.js";
import Credit from "./Credit.js";
import Frozen from "./Frozen.js";
import defined from "./defined.js";
import Event from "./Event.js";
import GeographicTilingScheme from "./GeographicTilingScheme.js";
import GoogleEarthEnterpriseMetadata from "./GoogleEarthEnterpriseMetadata.js";
import GoogleEarthEnterpriseTerrainData from "./GoogleEarthEnterpriseTerrainData.js";
import HeightmapTerrainData from "./HeightmapTerrainData.js";
import JulianDate from "./JulianDate.js";
import CesiumMath from "./Math.js";
import Rectangle from "./Rectangle.js";
import Request from "./Request.js";
import RequestState from "./RequestState.js";
import RequestType from "./RequestType.js";
import RuntimeError from "./RuntimeError.js";
import TaskProcessor from "./TaskProcessor.js";
const TerrainState = {
UNKNOWN: 0,
NONE: 1,
SELF: 2,
PARENT: 3,
};
const julianDateScratch = new JulianDate();
function TerrainCache() {
this._terrainCache = {};
this._lastTidy = JulianDate.now();
}
TerrainCache.prototype.add = function (quadKey, buffer) {
this._terrainCache[quadKey] = {
buffer: buffer,
timestamp: JulianDate.now(),
};
};
TerrainCache.prototype.get = function (quadKey) {
const terrainCache = this._terrainCache;
const result = terrainCache[quadKey];
if (defined(result)) {
delete this._terrainCache[quadKey];
return result.buffer;
}
};
TerrainCache.prototype.tidy = function () {
JulianDate.now(julianDateScratch);
Iif (JulianDate.secondsDifference(julianDateScratch, this._lastTidy) > 10) {
const terrainCache = this._terrainCache;
const keys = Object.keys(terrainCache);
const count = keys.length;
for (let i = 0; i < count; ++i) {
const k = keys[i];
const e = terrainCache[k];
if (JulianDate.secondsDifference(julianDateScratch, e.timestamp) > 10) {
delete terrainCache[k];
}
}
JulianDate.clone(julianDateScratch, this._lastTidy);
}
};
/**
* @typedef {object} GoogleEarthEnterpriseTerrainProvider.ConstructorOptions
*
* Initialization options for GoogleEarthEnterpriseTerrainProvider constructor
*
* @property {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid. If not specified, the default ellipsoid is used.
* @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.
*/
/**
* <div class="notice">
* To construct a GoogleEarthEnterpriseTerrainProvider, call {@link GoogleEarthEnterpriseTerrainProvider.fromMetadata}. Do not call the constructor directly.
* </div>
*
* Provides tiled terrain using the Google Earth Enterprise REST API.
*
* @alias GoogleEarthEnterpriseTerrainProvider
* @constructor
*
* @param {GoogleEarthEnterpriseTerrainProvider.ConstructorOptions} [options] An object describing initialization options
*
* @see GoogleEarthEnterpriseTerrainProvider.fromMetadata
* @see GoogleEarthEnterpriseMetadata.fromUrl
* @see GoogleEarthEnterpriseImageryProvider
* @see CesiumTerrainProvider
*
* @example
* const geeMetadata = await GoogleEarthEnterpriseMetadata.fromUrl("http://www.example.com");
* const gee = Cesium.GoogleEarthEnterpriseTerrainProvider.fromMetadata(geeMetadata);
*
* @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
*/
function GoogleEarthEnterpriseTerrainProvider(options) {
options = options ?? Frozen.EMPTY_OBJECT;
this._tilingScheme = new GeographicTilingScheme({
numberOfLevelZeroTilesX: 2,
numberOfLevelZeroTilesY: 2,
rectangle: new Rectangle(
-CesiumMath.PI,
-CesiumMath.PI,
CesiumMath.PI,
CesiumMath.PI,
),
ellipsoid: options.ellipsoid,
});
let credit = options.credit;
if (typeof credit === "string") {
credit = new Credit(credit);
}
this._credit = credit;
// Pulled from Google's documentation
this._levelZeroMaximumGeometricError = 40075.16;
this._terrainCache = new TerrainCache();
this._terrainPromises = {};
this._terrainRequests = {};
this._errorEvent = new Event();
}
Object.defineProperties(GoogleEarthEnterpriseTerrainProvider.prototype, {
/**
* Gets the name of the Google Earth Enterprise server url hosting the imagery.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {string}
* @readonly
*/
url: {
get: function () {
return this._metadata.url;
},
},
/**
* Gets the proxy used by this provider.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {Proxy}
* @readonly
*/
proxy: {
get: function () {
return this._metadata.proxy;
},
},
/**
* Gets the tiling scheme used by this provider.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {TilingScheme}
* @readonly
*/
tilingScheme: {
get: function () {
return this._tilingScheme;
},
},
/**
* Gets an event that is raised when the imagery 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 {@link TileProviderError}.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {Event}
* @readonly
*/
errorEvent: {
get: function () {
return this._errorEvent;
},
},
/**
* Gets the credit to display when this terrain provider is active. Typically this is used to credit
* the source of the terrain.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {Credit}
* @readonly
*/
credit: {
get: function () {
return this._credit;
},
},
/**
* Gets a value indicating whether or not the provider includes a water mask. The water mask
* indicates which areas of the globe are water rather than land, so they can be rendered
* as a reflective surface with animated waves.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {boolean}
* @readonly
*/
hasWaterMask: {
get: function () {
return false;
},
},
/**
* Gets a value indicating whether or not the requested tiles include vertex normals.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {boolean}
* @readonly
*/
hasVertexNormals: {
get: function () {
return false;
},
},
/**
* Gets an object that can be used to determine availability of terrain from this provider, such as
* at points and in rectangles. This property may be undefined if availability
* information is not available.
* @memberof GoogleEarthEnterpriseTerrainProvider.prototype
* @type {TileAvailability|undefined}
* @readonly
*/
availability: {
get: function () {
return undefined;
},
},
});
/**
* Creates a GoogleEarthTerrainProvider from GoogleEarthEnterpriseMetadata
*
* @param {GoogleEarthEnterpriseMetadata} metadata A metadata object that can be used to share metadata requests with a GoogleEarthEnterpriseImageryProvider.
* @param {GoogleEarthEnterpriseTerrainProvider.ConstructorOptions} options An object describing initialization options
* @returns {GoogleEarthEnterpriseTerrainProvider}
*
* @see GoogleEarthEnterpriseMetadata.fromUrl
*
* @exception {RuntimeError} metadata does not specify terrain
*
* @example
* const geeMetadata = await GoogleEarthEnterpriseMetadata.fromUrl("http://www.example.com");
* const gee = Cesium.GoogleEarthEnterpriseTerrainProvider.fromMetadata(geeMetadata);
*/
GoogleEarthEnterpriseTerrainProvider.fromMetadata = function (
metadata,
options,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("metadata", metadata);
//>>includeEnd('debug');
if (!metadata.terrainPresent) {
throw new RuntimeError(`The server ${metadata.url} doesn't have terrain`);
}
const provider = new GoogleEarthEnterpriseTerrainProvider(options);
provider._metadata = metadata;
return provider;
};
const taskProcessor = new TaskProcessor("decodeGoogleEarthEnterprisePacket");
// If the tile has its own terrain, then you can just use its child bitmask. If it was requested using it's parent
// then you need to check all of its children to see if they have terrain.
function computeChildMask(quadKey, info, metadata) {
let childMask = info.getChildBitmask();
Iif (info.terrainState === TerrainState.PARENT) {
childMask = 0;
for (let i = 0; i < 4; ++i) {
const child = metadata.getTileInformationFromQuadKey(
quadKey + i.toString(),
);
if (defined(child) && child.hasTerrain()) {
childMask |= 1 << i;
}
}
}
return childMask;
}
/**
* Requests the geometry for a given tile. The result must include terrain data and
* may optionally include a water mask and an indication of which child tiles are available.
*
* @param {number} x The X coordinate of the tile for which to request geometry.
* @param {number} y The Y coordinate of the tile for which to request geometry.
* @param {number} level The level of the tile for which to request geometry.
* @param {Request} [request] The request object. Intended for internal use only.
* @returns {Promise<TerrainData>|undefined} A promise for the requested geometry. If this method
* returns undefined instead of a promise, it is an indication that too many requests are already
* pending and the request will be retried later.
*/
GoogleEarthEnterpriseTerrainProvider.prototype.requestTileGeometry = function (
x,
y,
level,
request,
) {
const quadKey = GoogleEarthEnterpriseMetadata.tileXYToQuadKey(x, y, level);
const terrainCache = this._terrainCache;
const metadata = this._metadata;
const info = metadata.getTileInformationFromQuadKey(quadKey);
// Check if this tile is even possibly available
Iif (!defined(info)) {
return Promise.reject(new RuntimeError("Terrain tile doesn't exist"));
}
let terrainState = info.terrainState;
Iif (!defined(terrainState)) {
// First time we have tried to load this tile, so set terrain state to UNKNOWN
terrainState = info.terrainState = TerrainState.UNKNOWN;
}
// If its in the cache, return it
const buffer = terrainCache.get(quadKey);
Iif (defined(buffer)) {
const credit = metadata.providers[info.terrainProvider];
return Promise.resolve(
new GoogleEarthEnterpriseTerrainData({
buffer: buffer,
childTileMask: computeChildMask(quadKey, info, metadata),
credits: defined(credit) ? [credit] : undefined,
negativeAltitudeExponentBias: metadata.negativeAltitudeExponentBias,
negativeElevationThreshold: metadata.negativeAltitudeThreshold,
}),
);
}
// Clean up the cache
terrainCache.tidy();
// We have a tile, check to see if no ancestors have terrain or that we know for sure it doesn't
Iif (!info.ancestorHasTerrain) {
// We haven't reached a level with terrain, so return the ellipsoid
return Promise.resolve(
new HeightmapTerrainData({
buffer: new Uint8Array(16 * 16),
width: 16,
height: 16,
}),
);
} else Iif (terrainState === TerrainState.NONE) {
// Already have info and there isn't any terrain here
return Promise.reject(new RuntimeError("Terrain tile doesn't exist"));
}
// Figure out where we are getting the terrain and what version
let parentInfo;
let q = quadKey;
let terrainVersion = -1;
switch (terrainState) {
case TerrainState.SELF: // We have terrain and have retrieved it before
terrainVersion = info.terrainVersion;
break;
case TerrainState.PARENT: // We have terrain in our parent
q = q.substring(0, q.length - 1);
parentInfo = metadata.getTileInformationFromQuadKey(q);
terrainVersion = parentInfo.terrainVersion;
break;
case TerrainState.UNKNOWN: // We haven't tried to retrieve terrain yet
if (info.hasTerrain()) {
terrainVersion = info.terrainVersion; // We should have terrain
} else E{
q = q.substring(0, q.length - 1);
parentInfo = metadata.getTileInformationFromQuadKey(q);
if (defined(parentInfo) && parentInfo.hasTerrain()) {
terrainVersion = parentInfo.terrainVersion; // Try checking in the parent
}
}
break;
}
// We can't figure out where to get the terrain
Iif (terrainVersion < 0) {
return Promise.reject(new RuntimeError("Terrain tile doesn't exist"));
}
// Load that terrain
const terrainPromises = this._terrainPromises;
const terrainRequests = this._terrainRequests;
let sharedPromise;
let sharedRequest;
Iif (defined(terrainPromises[q])) {
// Already being loaded possibly from another child, so return existing promise
sharedPromise = terrainPromises[q];
sharedRequest = terrainRequests[q];
} else {
// Create new request for terrain
sharedRequest = request;
const requestPromise = buildTerrainResource(
this,
q,
terrainVersion,
sharedRequest,
).fetchArrayBuffer();
if (!defined(requestPromise)) {
return undefined; // Throttled
}
sharedPromise = requestPromise.then(function (terrain) {
if (defined(terrain)) {
return taskProcessor
.scheduleTask(
{
buffer: terrain,
type: "Terrain",
key: metadata.key,
},
[terrain],
)
.then(function (terrainTiles) {
// Add requested tile and mark it as SELF
const requestedInfo = metadata.getTileInformationFromQuadKey(q);
requestedInfo.terrainState = TerrainState.SELF;
terrainCache.add(q, terrainTiles[0]);
const provider = requestedInfo.terrainProvider;
// Add children to cache
const count = terrainTiles.length - 1;
for (let j = 0; j < count; ++j) {
const childKey = q + j.toString();
const child = metadata.getTileInformationFromQuadKey(childKey);
if (defined(child)) {
terrainCache.add(childKey, terrainTiles[j + 1]);
child.terrainState = TerrainState.PARENT;
Iif (child.terrainProvider === 0) {
child.terrainProvider = provider;
}
}
}
});
}
return Promise.reject(new RuntimeError("Failed to load terrain."));
});
terrainPromises[q] = sharedPromise; // Store promise without delete from terrainPromises
terrainRequests[q] = sharedRequest;
// Set promise so we remove from terrainPromises just one time
sharedPromise = sharedPromise.finally(function () {
delete terrainPromises[q];
delete terrainRequests[q];
});
}
return sharedPromise
.then(function () {
const buffer = terrainCache.get(quadKey);
Eif (defined(buffer)) {
const credit = metadata.providers[info.terrainProvider];
return new GoogleEarthEnterpriseTerrainData({
buffer: buffer,
childTileMask: computeChildMask(quadKey, info, metadata),
credits: defined(credit) ? [credit] : undefined,
negativeAltitudeExponentBias: metadata.negativeAltitudeExponentBias,
negativeElevationThreshold: metadata.negativeAltitudeThreshold,
});
}
return Promise.reject(new RuntimeError("Failed to load terrain."));
})
.catch(function (error) {
Iif (sharedRequest.state === RequestState.CANCELLED) {
request.state = sharedRequest.state;
return Promise.reject(error);
}
info.terrainState = TerrainState.NONE;
return Promise.reject(error);
});
};
/**
* Gets the maximum geometric error allowed in a tile at a given level.
*
* @param {number} level The tile level for which to get the maximum geometric error.
* @returns {number} The maximum geometric error.
*/
GoogleEarthEnterpriseTerrainProvider.prototype.getLevelMaximumGeometricError =
function (level) {
return this._levelZeroMaximumGeometricError / (1 << level);
};
/**
* Determines whether data for a tile is available to be loaded.
*
* @param {number} x The X coordinate of the tile for which to request geometry.
* @param {number} y The Y coordinate of the tile for which to request geometry.
* @param {number} level The level of the tile for which to request geometry.
* @returns {boolean|undefined} Undefined if not supported, otherwise true or false.
*/
GoogleEarthEnterpriseTerrainProvider.prototype.getTileDataAvailable = function (
x,
y,
level,
) {
const metadata = this._metadata;
let quadKey = GoogleEarthEnterpriseMetadata.tileXYToQuadKey(x, y, level);
const info = metadata.getTileInformation(x, y, level);
Iif (info === null) {
return false;
}
if (defined(info)) {
Iif (!info.ancestorHasTerrain) {
return true; // We'll just return the ellipsoid
}
const terrainState = info.terrainState;
if (terrainState === TerrainState.NONE) {
return false; // Terrain is not available
}
Eif (!defined(terrainState) || terrainState === TerrainState.UNKNOWN) {
info.terrainState = TerrainState.UNKNOWN;
Iif (!info.hasTerrain()) {
quadKey = quadKey.substring(0, quadKey.length - 1);
const parentInfo = metadata.getTileInformationFromQuadKey(quadKey);
if (!defined(parentInfo) || !parentInfo.hasTerrain()) {
return false;
}
}
}
return true;
}
Eif (metadata.isValid(quadKey)) {
// We will need this tile, so request metadata and return false for now
const request = new Request({
throttle: false,
throttleByServer: true,
type: RequestType.TERRAIN,
});
metadata.populateSubtree(x, y, level, request);
}
return false;
};
/**
* Makes sure we load availability data for a tile
*
* @param {number} x The X coordinate of the tile for which to request geometry.
* @param {number} y The Y coordinate of the tile for which to request geometry.
* @param {number} level The level of the tile for which to request geometry.
* @returns {undefined}
*/
GoogleEarthEnterpriseTerrainProvider.prototype.loadTileDataAvailability =
function (x, y, level) {
return undefined;
};
//
// Functions to handle imagery packets
//
function buildTerrainResource(terrainProvider, quadKey, version, request) {
version = defined(version) && version > 0 ? version : 1;
return terrainProvider._metadata.resource.getDerivedResource({
url: `flatfile?f1c-0${quadKey}-t.${version.toString()}`,
request: request,
});
}
export default GoogleEarthEnterpriseTerrainProvider;
|