123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771 |
- 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 DeveloperError from "../Core/DeveloperError.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 when from "../ThirdParty/when.js";
- import ImageryProvider from "./ImageryProvider.js";
- function GoogleEarthEnterpriseMapsProvider(options) {
- options = defaultValue(options, {});
-
- if (!defined(options.url)) {
- throw new DeveloperError("options.url is required.");
- }
- if (!defined(options.channel)) {
- throw new DeveloperError("options.channel is required.");
- }
-
-
- 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;
- var url = options.url;
- var path = defaultValue(options.path, "/default_map");
- var resource = Resource.createIfNeeded(url).getDerivedResource({
-
- url: path[0] === "/" ? path.substring(1) : path,
- });
- resource.appendForwardSlash();
- this._resource = resource;
- this._url = url;
- this._path = path;
- this._tileDiscardPolicy = options.tileDiscardPolicy;
- this._channel = options.channel;
- this._requestType = "ImageryMaps";
- this._credit = new Credit(
- '<a href="http://www.google.com/enterprise/mapsearth/products/earthenterprise.html"><img src="' +
- GoogleEarthEnterpriseMapsProvider.logoUrl +
- '" title="Google Imagery"/></a>'
- );
- this._tilingScheme = undefined;
- this._version = undefined;
- this._tileWidth = 256;
- this._tileHeight = 256;
- this._maximumLevel = options.maximumLevel;
- this._errorEvent = new Event();
- this._ready = false;
- this._readyPromise = when.defer();
- var metadataResource = resource.getDerivedResource({
- url: "query",
- queryParameters: {
- request: "Json",
- vars: "geeServerDefs",
- is2d: "t",
- },
- });
- var that = this;
- var metadataError;
- function metadataSuccess(text) {
- var data;
-
- try {
-
- data = JSON.parse(text);
- } catch (e) {
-
- data = JSON.parse(
- text.replace(/([\[\{,])[\n\r ]*([A-Za-z0-9]+)[\n\r ]*:/g, '$1"$2":')
- );
- }
- var layer;
- for (var i = 0; i < data.layers.length; i++) {
- if (data.layers[i].id === that._channel) {
- layer = data.layers[i];
- break;
- }
- }
- var message;
- if (!defined(layer)) {
- message =
- "Could not find layer with channel (id) of " + that._channel + ".";
- metadataError = TileProviderError.handleError(
- metadataError,
- that,
- that._errorEvent,
- message,
- undefined,
- undefined,
- undefined,
- requestMetadata
- );
- throw new RuntimeError(message);
- }
- if (!defined(layer.version)) {
- message =
- "Could not find a version in channel (id) " + that._channel + ".";
- metadataError = TileProviderError.handleError(
- metadataError,
- that,
- that._errorEvent,
- message,
- undefined,
- undefined,
- undefined,
- requestMetadata
- );
- throw new RuntimeError(message);
- }
- that._version = layer.version;
- if (defined(data.projection) && data.projection === "flat") {
- that._tilingScheme = new GeographicTilingScheme({
- numberOfLevelZeroTilesX: 2,
- numberOfLevelZeroTilesY: 2,
- rectangle: new Rectangle(-Math.PI, -Math.PI, Math.PI, Math.PI),
- ellipsoid: options.ellipsoid,
- });
-
- } else if (!defined(data.projection) || data.projection === "mercator") {
- that._tilingScheme = new WebMercatorTilingScheme({
- numberOfLevelZeroTilesX: 2,
- numberOfLevelZeroTilesY: 2,
- ellipsoid: options.ellipsoid,
- });
- } else {
- message = "Unsupported projection " + data.projection + ".";
- metadataError = TileProviderError.handleError(
- metadataError,
- that,
- that._errorEvent,
- message,
- undefined,
- undefined,
- undefined,
- requestMetadata
- );
- throw new RuntimeError(message);
- }
- that._ready = true;
- that._readyPromise.resolve(true);
- TileProviderError.handleSuccess(metadataError);
- }
- function metadataFailure(e) {
- var message =
- "An error occurred while accessing " + metadataResource.url + ".";
- metadataError = TileProviderError.handleError(
- metadataError,
- that,
- that._errorEvent,
- message,
- undefined,
- undefined,
- undefined,
- requestMetadata
- );
- that._readyPromise.reject(new RuntimeError(message));
- }
- function requestMetadata() {
- var metadata = metadataResource.fetchText();
- when(metadata, metadataSuccess, metadataFailure);
- }
- requestMetadata();
- }
- Object.defineProperties(GoogleEarthEnterpriseMapsProvider.prototype, {
-
- url: {
- get: function () {
- return this._url;
- },
- },
-
- path: {
- get: function () {
- return this._path;
- },
- },
-
- proxy: {
- get: function () {
- return this._resource.proxy;
- },
- },
-
- channel: {
- get: function () {
- return this._channel;
- },
- },
-
- tileWidth: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "tileWidth must not be called before the imagery provider is ready."
- );
- }
-
- return this._tileWidth;
- },
- },
-
- tileHeight: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "tileHeight must not be called before the imagery provider is ready."
- );
- }
-
- return this._tileHeight;
- },
- },
-
- maximumLevel: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "maximumLevel must not be called before the imagery provider is ready."
- );
- }
-
- return this._maximumLevel;
- },
- },
-
- minimumLevel: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "minimumLevel must not be called before the imagery provider is ready."
- );
- }
-
- return 0;
- },
- },
-
- tilingScheme: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "tilingScheme must not be called before the imagery provider is ready."
- );
- }
-
- return this._tilingScheme;
- },
- },
-
- version: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "version must not be called before the imagery provider is ready."
- );
- }
-
- return this._version;
- },
- },
-
- requestType: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "requestType must not be called before the imagery provider is ready."
- );
- }
-
- return this._requestType;
- },
- },
-
- rectangle: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "rectangle must not be called before the imagery provider is ready."
- );
- }
-
- return this._tilingScheme.rectangle;
- },
- },
-
- tileDiscardPolicy: {
- get: function () {
-
- if (!this._ready) {
- throw new DeveloperError(
- "tileDiscardPolicy must not be called before the imagery provider is ready."
- );
- }
-
- return this._tileDiscardPolicy;
- },
- },
-
- errorEvent: {
- get: function () {
- return this._errorEvent;
- },
- },
-
- ready: {
- get: function () {
- return this._ready;
- },
- },
-
- readyPromise: {
- get: function () {
- return this._readyPromise.promise;
- },
- },
-
- credit: {
- get: function () {
- return this._credit;
- },
- },
-
- hasAlphaChannel: {
- get: function () {
- return true;
- },
- },
- });
- GoogleEarthEnterpriseMapsProvider.prototype.getTileCredits = function (
- x,
- y,
- level
- ) {
- return undefined;
- };
- GoogleEarthEnterpriseMapsProvider.prototype.requestImage = function (
- x,
- y,
- level,
- request
- ) {
-
- if (!this._ready) {
- throw new DeveloperError(
- "requestImage must not be called before the imagery provider is ready."
- );
- }
-
- var resource = this._resource.getDerivedResource({
- url: "query",
- request: request,
- queryParameters: {
- request: this._requestType,
- channel: this._channel,
- version: this._version,
- x: x,
- y: y,
- z: level + 1,
- },
- });
- return ImageryProvider.loadImage(this, resource);
- };
- GoogleEarthEnterpriseMapsProvider.prototype.pickFeatures = function (
- x,
- y,
- level,
- longitude,
- latitude
- ) {
- return undefined;
- };
- GoogleEarthEnterpriseMapsProvider._logoUrl = undefined;
- Object.defineProperties(GoogleEarthEnterpriseMapsProvider, {
-
- logoUrl: {
- get: function () {
- if (!defined(GoogleEarthEnterpriseMapsProvider._logoUrl)) {
- GoogleEarthEnterpriseMapsProvider._logoUrl = buildModuleUrl(
- "Assets/Images/google_earth_credit.png"
- );
- }
- return GoogleEarthEnterpriseMapsProvider._logoUrl;
- },
- set: function (value) {
-
- Check.defined("value", value);
-
- GoogleEarthEnterpriseMapsProvider._logoUrl = value;
- },
- },
- });
- export default GoogleEarthEnterpriseMapsProvider;
|