import buildModuleUrl from "../Core/buildModuleUrl.js"; import Check from "../Core/Check.js"; import Credit from "../Core/Credit.js"; import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Event from "../Core/Event.js"; import GeographicTilingScheme from "../Core/GeographicTilingScheme.js"; import Rectangle from "../Core/Rectangle.js"; import Resource from "../Core/Resource.js"; import RuntimeError from "../Core/RuntimeError.js"; import TileProviderError from "../Core/TileProviderError.js"; import WebMercatorTilingScheme from "../Core/WebMercatorTilingScheme.js"; import ImageryProvider from "./ImageryProvider.js"; /** * @typedef {object} GoogleEarthEnterpriseMapsProvider.ConstructorOptions * * Initialization options for the GoogleEarthEnterpriseMapsProvider constructor * * @property {number} channel The channel (id) to be used when requesting data from the server. * The channel number can be found by looking at the json file located at: * earth.localdomain/default_map/query?request=Json&vars=geeServerDefs The /default_map path may * differ depending on your Google Earth Enterprise server configuration. Look for the "id" that * is associated with a "ImageryMaps" requestType. There may be more than one id available. * Example: * { * layers: [ * { * id: 1002, * requestType: "ImageryMaps" * }, * { * id: 1007, * requestType: "VectorMapsRaster" * } * ] * } * @property {string} [path="/default_map"] The path of the Google Earth server hosting the imagery. * @property {number} [maximumLevel] The maximum level-of-detail supported by the Google Earth * Enterprise server, or undefined if there is no limit. * @property {TileDiscardPolicy} [tileDiscardPolicy] The policy that determines if a tile * is invalid and should be discarded. To ensure that no tiles are discarded, construct and pass * a {@link NeverTileDiscardPolicy} for this parameter. * @property {Ellipsoid} [ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used. */ /** * Used to track creation details while fetching initial metadata * * @constructor * @private * * @param {GoogleEarthEnterpriseMapsProvider.ConstructorOptions} options An object describing initialization options */ function ImageryProviderBuilder(options) { this.channel = options.channel; this.ellipsoid = options.ellipsoid; this.tilingScheme = undefined; this.version = undefined; } /** * Complete GoogleEarthEnterpriseMapsProvider creation based on builder values. * * @private * * @param {GoogleEarthEnterpriseMapsProvider} provider */ ImageryProviderBuilder.prototype.build = function (provider) { provider._channel = this.channel; provider._version = this.version; provider._tilingScheme = this.tilingScheme; }; function metadataSuccess(text, imageryProviderBuilder) { let data; // The Google Earth server sends malformed JSON data currently... try { // First, try parsing it like normal in case a future version sends correctly formatted JSON data = JSON.parse(text); } catch (e) { // Quote object strings manually, then try parsing again data = JSON.parse( text.replace(/([\[\{,])[\n\r ]*([A-Za-z0-9]+)[\n\r ]*:/g, '$1"$2":') ); } let layer; for (let i = 0; i < data.layers.length; i++) { if (data.layers[i].id === imageryProviderBuilder.channel) { layer = data.layers[i]; break; } } if (!defined(layer)) { const message = `Could not find layer with channel (id) of ${imageryProviderBuilder.channel}.`; throw new RuntimeError(message); } if (!defined(layer.version)) { const message = `Could not find a version in channel (id) ${imageryProviderBuilder.channel}.`; throw new RuntimeError(message); } imageryProviderBuilder.version = layer.version; if (defined(data.projection) && data.projection === "flat") { imageryProviderBuilder.tilingScheme = new GeographicTilingScheme({ numberOfLevelZeroTilesX: 2, numberOfLevelZeroTilesY: 2, rectangle: new Rectangle(-Math.PI, -Math.PI, Math.PI, Math.PI), ellipsoid: imageryProviderBuilder.ellipsoid, }); // Default to mercator projection when projection is undefined } else if (!defined(data.projection) || data.projection === "mercator") { imageryProviderBuilder.tilingScheme = new WebMercatorTilingScheme({ numberOfLevelZeroTilesX: 2, numberOfLevelZeroTilesY: 2, ellipsoid: imageryProviderBuilder.ellipsoid, }); } else { const message = `Unsupported projection ${data.projection}.`; throw new RuntimeError(message); } return true; } function metadataFailure(error, metadataResource, provider) { let message = `An error occurred while accessing ${metadataResource.url}.`; if (defined(error) && defined(error.message)) { message += `: ${error.message}`; } TileProviderError.reportError( undefined, provider, defined(provider) ? provider._errorEvent : undefined, message ); throw new RuntimeError(message); } async function requestMetadata( metadataResource, imageryProviderBuilder, provider ) { try { const text = await metadataResource.fetchText(); metadataSuccess(text, imageryProviderBuilder); } catch (error) { metadataFailure(error, metadataResource, provider); } } /** *
options.channel.
* @exception {RuntimeError} Could not find a version in channel (id) options.channel.
* @exception {RuntimeError} Unsupported projection data.projection.
*
* @see ArcGisMapServerImageryProvider
* @see BingMapsImageryProvider
* @see OpenStreetMapImageryProvider
* @see SingleTileImageryProvider
* @see TileMapServiceImageryProvider
* @see WebMapServiceImageryProvider
* @see WebMapTileServiceImageryProvider
* @see UrlTemplateImageryProvider
*
*
* @example
* const google = await Cesium.GoogleEarthEnterpriseMapsProvider.fromUrl("https://earth.localdomain", 1008);
*
* @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
*/
function GoogleEarthEnterpriseMapsProvider(options) {
options = defaultValue(options, {});
this._defaultAlpha = undefined;
this._defaultNightAlpha = undefined;
this._defaultDayAlpha = undefined;
this._defaultBrightness = undefined;
this._defaultContrast = undefined;
this._defaultHue = undefined;
this._defaultSaturation = undefined;
this._defaultGamma = 1.9;
this._defaultMinificationFilter = undefined;
this._defaultMagnificationFilter = undefined;
this._tileDiscardPolicy = options.tileDiscardPolicy;
this._channel = options.channel;
this._requestType = "ImageryMaps";
this._credit = new Credit(
`options.channel.
* @exception {RuntimeError} Could not find a version in channel (id) options.channel.
* @exception {RuntimeError} Unsupported projection data.projection.
*
* @example
* const google = await Cesium.GoogleEarthEnterpriseMapsProvider.fromUrl("https://earth.localdomain", 1008);
*/
GoogleEarthEnterpriseMapsProvider.fromUrl = async function (
url,
channel,
options
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("url", url);
Check.defined("channel", channel);
//>>includeEnd('debug');
options = defaultValue(options, {});
const path = defaultValue(options.path, "/default_map");
const resource = Resource.createIfNeeded(url).getDerivedResource({
// We used to just append path to url, so now that we do proper URI resolution, removed the /
url: path[0] === "/" ? path.substring(1) : path,
});
resource.appendForwardSlash();
const metadataResource = resource.getDerivedResource({
url: "query",
queryParameters: {
request: "Json",
vars: "geeServerDefs",
is2d: "t",
},
});
const imageryProviderBuilder = new ImageryProviderBuilder(options);
imageryProviderBuilder.channel = channel;
await requestMetadata(metadataResource, imageryProviderBuilder);
const provider = new GoogleEarthEnterpriseMapsProvider(options);
imageryProviderBuilder.build(provider);
provider._resource = resource;
provider._url = url;
provider._path = path;
return provider;
};
/**
* Gets the credits to be displayed when a given tile is displayed.
*
* @param {number} x The tile X coordinate.
* @param {number} y The tile Y coordinate.
* @param {number} level The tile level;
* @returns {Credit[]} The credits to be displayed when the tile is displayed.
*/
GoogleEarthEnterpriseMapsProvider.prototype.getTileCredits = function (
x,
y,
level
) {
return undefined;
};
/**
* Requests the image for a given tile.
*
* @param {number} x The tile X coordinate.
* @param {number} y The tile Y coordinate.
* @param {number} level The tile level.
* @param {Request} [request] The request object. Intended for internal use only.
* @returns {Promise