GoogleEarthEnterpriseImageryProvider.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. import Check from "../Core/Check.js";
  2. import Credit from "../Core/Credit.js";
  3. import decodeGoogleEarthEnterpriseData from "../Core/decodeGoogleEarthEnterpriseData.js";
  4. import defaultValue from "../Core/defaultValue.js";
  5. import defined from "../Core/defined.js";
  6. import deprecationWarning from "../Core/deprecationWarning.js";
  7. import Event from "../Core/Event.js";
  8. import GeographicTilingScheme from "../Core/GeographicTilingScheme.js";
  9. import GoogleEarthEnterpriseMetadata from "../Core/GoogleEarthEnterpriseMetadata.js";
  10. import loadImageFromTypedArray from "../Core/loadImageFromTypedArray.js";
  11. import CesiumMath from "../Core/Math.js";
  12. import Rectangle from "../Core/Rectangle.js";
  13. import Request from "../Core/Request.js";
  14. import Resource from "../Core/Resource.js";
  15. import RuntimeError from "../Core/RuntimeError.js";
  16. import TileProviderError from "../Core/TileProviderError.js";
  17. import * as protobuf from "protobufjs/dist/minimal/protobuf.js";
  18. /**
  19. * @private
  20. */
  21. function GoogleEarthEnterpriseDiscardPolicy() {
  22. this._image = new Image();
  23. }
  24. /**
  25. * Determines if the discard policy is ready to process images.
  26. * @returns {boolean} True if the discard policy is ready to process images; otherwise, false.
  27. */
  28. GoogleEarthEnterpriseDiscardPolicy.prototype.isReady = function () {
  29. return true;
  30. };
  31. /**
  32. * Given a tile image, decide whether to discard that image.
  33. *
  34. * @param {HTMLImageElement} image An image to test.
  35. * @returns {boolean} True if the image should be discarded; otherwise, false.
  36. */
  37. GoogleEarthEnterpriseDiscardPolicy.prototype.shouldDiscardImage = function (
  38. image
  39. ) {
  40. return image === this._image;
  41. };
  42. /**
  43. * @typedef {object} GoogleEarthEnterpriseImageryProvider.ConstructorOptions
  44. *
  45. * Initialization options for the GoogleEarthEnterpriseImageryProvider constructor
  46. *
  47. * @property {Resource|string} [url] The url of the Google Earth Enterprise server hosting the imagery. Deprecated.
  48. * @property {GoogleEarthEnterpriseMetadata} [metadata] A metadata object that can be used to share metadata requests with a GoogleEarthEnterpriseTerrainProvider. Deprecated.
  49. * @property {Ellipsoid} [ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
  50. * @property {TileDiscardPolicy} [tileDiscardPolicy] The policy that determines if a tile
  51. * is invalid and should be discarded. If this value is not specified, a default
  52. * is to discard tiles that fail to download.
  53. * @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.
  54. */
  55. /**
  56. * <div class="notice">
  57. * To construct a GoogleEarthEnterpriseImageryProvider, call {@link GoogleEarthEnterpriseImageryProvider.fromMetadata}. Do not call the constructor directly.
  58. * </div>
  59. *
  60. * Provides tiled imagery using the Google Earth Enterprise REST API.
  61. *
  62. * Notes: This provider is for use with the 3D Earth API of Google Earth Enterprise,
  63. * {@link GoogleEarthEnterpriseMapsProvider} should be used with 2D Maps API.
  64. *
  65. * @alias GoogleEarthEnterpriseImageryProvider
  66. * @constructor
  67. *
  68. * @param {GoogleEarthEnterpriseImageryProvider.ConstructorOptions} options Object describing initialization options
  69. *
  70. * @see GoogleEarthEnterpriseImageryProvider.fromMetadata
  71. * @see GoogleEarthEnterpriseTerrainProvider
  72. * @see ArcGisMapServerImageryProvider
  73. * @see GoogleEarthEnterpriseMapsProvider
  74. * @see OpenStreetMapImageryProvider
  75. * @see SingleTileImageryProvider
  76. * @see TileMapServiceImageryProvider
  77. * @see WebMapServiceImageryProvider
  78. * @see WebMapTileServiceImageryProvider
  79. * @see UrlTemplateImageryProvider
  80. *
  81. *
  82. * @example
  83. * const geeMetadata = await GoogleEarthEnterpriseMetadata.fromUrl("http://www.example.com");
  84. * const gee = Cesium.GoogleEarthEnterpriseImageryProvider.fromMetadata(geeMetadata);
  85. *
  86. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  87. */
  88. function GoogleEarthEnterpriseImageryProvider(options) {
  89. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  90. this._defaultAlpha = undefined;
  91. this._defaultNightAlpha = undefined;
  92. this._defaultDayAlpha = undefined;
  93. this._defaultBrightness = undefined;
  94. this._defaultContrast = undefined;
  95. this._defaultHue = undefined;
  96. this._defaultSaturation = undefined;
  97. this._defaultGamma = undefined;
  98. this._defaultMinificationFilter = undefined;
  99. this._defaultMagnificationFilter = undefined;
  100. this._tileDiscardPolicy = options.tileDiscardPolicy;
  101. this._tilingScheme = new GeographicTilingScheme({
  102. numberOfLevelZeroTilesX: 2,
  103. numberOfLevelZeroTilesY: 2,
  104. rectangle: new Rectangle(
  105. -CesiumMath.PI,
  106. -CesiumMath.PI,
  107. CesiumMath.PI,
  108. CesiumMath.PI
  109. ),
  110. ellipsoid: options.ellipsoid,
  111. });
  112. let credit = options.credit;
  113. if (typeof credit === "string") {
  114. credit = new Credit(credit);
  115. }
  116. this._credit = credit;
  117. this._tileWidth = 256;
  118. this._tileHeight = 256;
  119. this._maximumLevel = 23;
  120. // Install the default tile discard policy if none has been supplied.
  121. if (!defined(this._tileDiscardPolicy)) {
  122. this._tileDiscardPolicy = new GoogleEarthEnterpriseDiscardPolicy();
  123. }
  124. this._errorEvent = new Event();
  125. this._ready = false;
  126. const that = this;
  127. let metadataError;
  128. let metadata;
  129. if (defined(options.url)) {
  130. deprecationWarning(
  131. "GoogleEarthEnterpriseImageryProvider options.url",
  132. "options.url was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use GoogleEarthEnterpriseImageryProvider.fromMetadata instead."
  133. );
  134. const resource = Resource.createIfNeeded(options.url);
  135. metadata = new GoogleEarthEnterpriseMetadata(resource);
  136. }
  137. if (defined(options.metadata)) {
  138. deprecationWarning(
  139. "GoogleEarthEnterpriseImageryProvider options.metadata",
  140. "options.metadata was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use GoogleEarthEnterpriseImageryProvider.fromMetadata instead."
  141. );
  142. metadata = options.metadata;
  143. }
  144. this._metadata = metadata;
  145. if (defined(metadata)) {
  146. this._readyPromise = metadata.readyPromise
  147. .then(function (result) {
  148. if (!metadata.imageryPresent) {
  149. const e = new RuntimeError(
  150. `The server ${metadata.url} doesn't have imagery`
  151. );
  152. metadataError = TileProviderError.reportError(
  153. metadataError,
  154. that,
  155. that._errorEvent,
  156. e.message,
  157. undefined,
  158. undefined,
  159. undefined,
  160. e
  161. );
  162. return Promise.reject(e);
  163. }
  164. TileProviderError.reportSuccess(metadataError);
  165. that._ready = result;
  166. return result;
  167. })
  168. .catch(function (e) {
  169. metadataError = TileProviderError.reportError(
  170. metadataError,
  171. that,
  172. that._errorEvent,
  173. e.message,
  174. undefined,
  175. undefined,
  176. undefined,
  177. e
  178. );
  179. return Promise.reject(e);
  180. });
  181. }
  182. }
  183. Object.defineProperties(GoogleEarthEnterpriseImageryProvider.prototype, {
  184. /**
  185. * Gets the name of the Google Earth Enterprise server url hosting the imagery.
  186. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  187. * @type {string}
  188. * @readonly
  189. */
  190. url: {
  191. get: function () {
  192. return this._metadata.url;
  193. },
  194. },
  195. /**
  196. * Gets the proxy used by this provider.
  197. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  198. * @type {Proxy}
  199. * @readonly
  200. */
  201. proxy: {
  202. get: function () {
  203. return this._metadata.proxy;
  204. },
  205. },
  206. /**
  207. * Gets the width of each tile, in pixels.
  208. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  209. * @type {number}
  210. * @readonly
  211. */
  212. tileWidth: {
  213. get: function () {
  214. return this._tileWidth;
  215. },
  216. },
  217. /**
  218. * Gets the height of each tile, in pixels.
  219. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  220. * @type {number}
  221. * @readonly
  222. */
  223. tileHeight: {
  224. get: function () {
  225. return this._tileHeight;
  226. },
  227. },
  228. /**
  229. * Gets the maximum level-of-detail that can be requested.
  230. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  231. * @type {number|undefined}
  232. * @readonly
  233. */
  234. maximumLevel: {
  235. get: function () {
  236. return this._maximumLevel;
  237. },
  238. },
  239. /**
  240. * Gets the minimum level-of-detail that can be requested.
  241. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  242. * @type {number}
  243. * @readonly
  244. */
  245. minimumLevel: {
  246. get: function () {
  247. return 0;
  248. },
  249. },
  250. /**
  251. * Gets the tiling scheme used by this provider.
  252. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  253. * @type {TilingScheme}
  254. * @readonly
  255. */
  256. tilingScheme: {
  257. get: function () {
  258. return this._tilingScheme;
  259. },
  260. },
  261. /**
  262. * Gets the rectangle, in radians, of the imagery provided by this instance.
  263. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  264. * @type {Rectangle}
  265. * @readonly
  266. */
  267. rectangle: {
  268. get: function () {
  269. return this._tilingScheme.rectangle;
  270. },
  271. },
  272. /**
  273. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  274. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  275. * returns undefined, no tiles are filtered.
  276. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  277. * @type {TileDiscardPolicy}
  278. * @readonly
  279. */
  280. tileDiscardPolicy: {
  281. get: function () {
  282. return this._tileDiscardPolicy;
  283. },
  284. },
  285. /**
  286. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  287. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  288. * are passed an instance of {@link TileProviderError}.
  289. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  290. * @type {Event}
  291. * @readonly
  292. */
  293. errorEvent: {
  294. get: function () {
  295. return this._errorEvent;
  296. },
  297. },
  298. /**
  299. * Gets a value indicating whether or not the provider is ready for use.
  300. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  301. * @type {boolean}
  302. * @readonly
  303. * @deprecated
  304. */
  305. ready: {
  306. get: function () {
  307. deprecationWarning(
  308. "GoogleEarthEnterpriseImageryProvider.ready",
  309. "GoogleEarthEnterpriseImageryProvider.ready was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use GoogleEarthEnterpriseImageryProvider.fromMetadata instead."
  310. );
  311. return this._ready;
  312. },
  313. },
  314. /**
  315. * Gets a promise that resolves to true when the provider is ready for use.
  316. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  317. * @type {Promise<boolean>}
  318. * @readonly
  319. * @deprecated
  320. */
  321. readyPromise: {
  322. get: function () {
  323. deprecationWarning(
  324. "GoogleEarthEnterpriseImageryProvider.readyPromise",
  325. "GoogleEarthEnterpriseImageryProvider.readyPromise was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use GoogleEarthEnterpriseImageryProvider.fromMetadata instead."
  326. );
  327. return this._readyPromise;
  328. },
  329. },
  330. /**
  331. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  332. * the source of the imagery.
  333. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  334. * @type {Credit}
  335. * @readonly
  336. */
  337. credit: {
  338. get: function () {
  339. return this._credit;
  340. },
  341. },
  342. /**
  343. * Gets a value indicating whether or not the images provided by this imagery provider
  344. * include an alpha channel. If this property is false, an alpha channel, if present, will
  345. * be ignored. If this property is true, any images without an alpha channel will be treated
  346. * as if their alpha is 1.0 everywhere. Setting this property to false reduces memory usage
  347. * and texture upload time.
  348. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  349. * @type {boolean}
  350. * @readonly
  351. */
  352. hasAlphaChannel: {
  353. get: function () {
  354. return false;
  355. },
  356. },
  357. /**
  358. * The default alpha blending value of this provider, with 0.0 representing fully transparent and
  359. * 1.0 representing fully opaque.
  360. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  361. * @type {Number|undefined}
  362. * @deprecated
  363. */
  364. defaultAlpha: {
  365. get: function () {
  366. deprecationWarning(
  367. "GoogleEarthEnterpriseImageryProvider.defaultAlpha",
  368. "GoogleEarthEnterpriseImageryProvider.defaultAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.alpha instead."
  369. );
  370. return this._defaultAlpha;
  371. },
  372. set: function (value) {
  373. deprecationWarning(
  374. "GoogleEarthEnterpriseImageryProvider.defaultAlpha",
  375. "GoogleEarthEnterpriseImageryProvider.defaultAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.alpha instead."
  376. );
  377. this._defaultAlpha = value;
  378. },
  379. },
  380. /**
  381. * The default alpha blending value on the night side of the globe of this provider, with 0.0 representing fully transparent and
  382. * 1.0 representing fully opaque.
  383. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  384. * @type {Number|undefined}
  385. * @deprecated
  386. */
  387. defaultNightAlpha: {
  388. get: function () {
  389. deprecationWarning(
  390. "GoogleEarthEnterpriseImageryProvider.defaultNightAlpha",
  391. "GoogleEarthEnterpriseImageryProvider.defaultNightAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.nightAlpha instead."
  392. );
  393. return this.defaultNightAlpha;
  394. },
  395. set: function (value) {
  396. deprecationWarning(
  397. "GoogleEarthEnterpriseImageryProvider.defaultNightAlpha",
  398. "GoogleEarthEnterpriseImageryProvider.defaultNightAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.nightAlpha instead."
  399. );
  400. this.defaultNightAlpha = value;
  401. },
  402. },
  403. /**
  404. * The default alpha blending value on the day side of the globe of this provider, with 0.0 representing fully transparent and
  405. * 1.0 representing fully opaque.
  406. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  407. * @type {Number|undefined}
  408. * @deprecated
  409. */
  410. defaultDayAlpha: {
  411. get: function () {
  412. deprecationWarning(
  413. "GoogleEarthEnterpriseImageryProvider.defaultDayAlpha",
  414. "GoogleEarthEnterpriseImageryProvider.defaultDayAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.dayAlpha instead."
  415. );
  416. return this._defaultDayAlpha;
  417. },
  418. set: function (value) {
  419. deprecationWarning(
  420. "GoogleEarthEnterpriseImageryProvider.defaultDayAlpha",
  421. "GoogleEarthEnterpriseImageryProvider.defaultDayAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.dayAlpha instead."
  422. );
  423. this._defaultDayAlpha = value;
  424. },
  425. },
  426. /**
  427. * The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
  428. * makes the imagery darker while greater than 1.0 makes it brighter.
  429. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  430. * @type {Number|undefined}
  431. * @deprecated
  432. */
  433. defaultBrightness: {
  434. get: function () {
  435. deprecationWarning(
  436. "GoogleEarthEnterpriseImageryProvider.defaultBrightness",
  437. "GoogleEarthEnterpriseImageryProvider.defaultBrightness was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.brightness instead."
  438. );
  439. return this._defaultBrightness;
  440. },
  441. set: function (value) {
  442. deprecationWarning(
  443. "GoogleEarthEnterpriseImageryProvider.defaultBrightness",
  444. "GoogleEarthEnterpriseImageryProvider.defaultBrightness was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.brightness instead."
  445. );
  446. this._defaultBrightness = value;
  447. },
  448. },
  449. /**
  450. * The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
  451. * the contrast while greater than 1.0 increases it.
  452. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  453. * @type {Number|undefined}
  454. * @deprecated
  455. */
  456. defaultContrast: {
  457. get: function () {
  458. deprecationWarning(
  459. "GoogleEarthEnterpriseImageryProvider.defaultContrast",
  460. "GoogleEarthEnterpriseImageryProvider.defaultContrast was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.contrast instead."
  461. );
  462. return this._defaultContrast;
  463. },
  464. set: function (value) {
  465. deprecationWarning(
  466. "GoogleEarthEnterpriseImageryProvider.defaultContrast",
  467. "GoogleEarthEnterpriseImageryProvider.defaultContrast was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.contrast instead."
  468. );
  469. this._defaultContrast = value;
  470. },
  471. },
  472. /**
  473. * The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
  474. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  475. * @type {Number|undefined}
  476. * @deprecated
  477. */
  478. defaultHue: {
  479. get: function () {
  480. deprecationWarning(
  481. "GoogleEarthEnterpriseImageryProvider.defaultHue",
  482. "GoogleEarthEnterpriseImageryProvider.defaultHue was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.hue instead."
  483. );
  484. return this._defaultHue;
  485. },
  486. set: function (value) {
  487. deprecationWarning(
  488. "GoogleEarthEnterpriseImageryProvider.defaultHue",
  489. "GoogleEarthEnterpriseImageryProvider.defaultHue was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.hue instead."
  490. );
  491. this._defaultHue = value;
  492. },
  493. },
  494. /**
  495. * The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
  496. * saturation while greater than 1.0 increases it.
  497. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  498. * @type {Number|undefined}
  499. * @deprecated
  500. */
  501. defaultSaturation: {
  502. get: function () {
  503. deprecationWarning(
  504. "GoogleEarthEnterpriseImageryProvider.defaultSaturation",
  505. "GoogleEarthEnterpriseImageryProvider.defaultSaturation was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.saturation instead."
  506. );
  507. return this._defaultSaturation;
  508. },
  509. set: function (value) {
  510. deprecationWarning(
  511. "GoogleEarthEnterpriseImageryProvider.defaultSaturation",
  512. "GoogleEarthEnterpriseImageryProvider.defaultSaturation was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.saturation instead."
  513. );
  514. this._defaultSaturation = value;
  515. },
  516. },
  517. /**
  518. * The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
  519. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  520. * @type {Number|undefined}
  521. * @deprecated
  522. */
  523. defaultGamma: {
  524. get: function () {
  525. deprecationWarning(
  526. "GoogleEarthEnterpriseImageryProvider.defaultGamma",
  527. "GoogleEarthEnterpriseImageryProvider.defaultGamma was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.gamma instead."
  528. );
  529. return this._defaultGamma;
  530. },
  531. set: function (value) {
  532. deprecationWarning(
  533. "GoogleEarthEnterpriseImageryProvider.defaultGamma",
  534. "GoogleEarthEnterpriseImageryProvider.defaultGamma was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.gamma instead."
  535. );
  536. this._defaultGamma = value;
  537. },
  538. },
  539. /**
  540. * The default texture minification filter to apply to this provider.
  541. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  542. * @type {TextureMinificationFilter}
  543. * @deprecated
  544. */
  545. defaultMinificationFilter: {
  546. get: function () {
  547. deprecationWarning(
  548. "GoogleEarthEnterpriseImageryProvider.defaultMinificationFilter",
  549. "GoogleEarthEnterpriseImageryProvider.defaultMinificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.minificationFilter instead."
  550. );
  551. return this._defaultMinificationFilter;
  552. },
  553. set: function (value) {
  554. deprecationWarning(
  555. "GoogleEarthEnterpriseImageryProvider.defaultMinificationFilter",
  556. "GoogleEarthEnterpriseImageryProvider.defaultMinificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.minificationFilter instead."
  557. );
  558. this._defaultMinificationFilter = value;
  559. },
  560. },
  561. /**
  562. * The default texture magnification filter to apply to this provider.
  563. * @memberof GoogleEarthEnterpriseImageryProvider.prototype
  564. * @type {TextureMagnificationFilter}
  565. * @deprecated
  566. */
  567. defaultMagnificationFilter: {
  568. get: function () {
  569. deprecationWarning(
  570. "GoogleEarthEnterpriseImageryProvider.defaultMagnificationFilter",
  571. "GoogleEarthEnterpriseImageryProvider.defaultMagnificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.magnificationFilter instead."
  572. );
  573. return this._defaultMagnificationFilter;
  574. },
  575. set: function (value) {
  576. deprecationWarning(
  577. "GoogleEarthEnterpriseImageryProvider.defaultMagnificationFilter",
  578. "GoogleEarthEnterpriseImageryProvider.defaultMagnificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.magnificationFilter instead."
  579. );
  580. this._defaultMagnificationFilter = value;
  581. },
  582. },
  583. });
  584. /**
  585. * Creates a tiled imagery provider using the Google Earth Enterprise REST API.
  586. * @param {GoogleEarthEnterpriseMetadata} metadata A metadata object that can be used to share metadata requests with a GoogleEarthEnterpriseTerrainProvider.
  587. * @param {GoogleEarthEnterpriseImageryProvider.ConstructorOptions} options Object describing initialization options.
  588. * @returns {GoogleEarthEnterpriseImageryProvider}
  589. *
  590. * @exception {RuntimeError} The metadata url does not have imagery
  591. *
  592. * @example
  593. * const geeMetadata = await GoogleEarthEnterpriseMetadata.fromUrl("http://www.example.com");
  594. * const gee = Cesium.GoogleEarthEnterpriseImageryProvider.fromMetadata(geeMetadata);
  595. */
  596. GoogleEarthEnterpriseImageryProvider.fromMetadata = function (
  597. metadata,
  598. options
  599. ) {
  600. //>>includeStart('debug', pragmas.debug);
  601. Check.defined("metadata", metadata);
  602. //>>includeEnd('debug');
  603. if (!metadata.imageryPresent) {
  604. throw new RuntimeError(`The server ${metadata.url} doesn't have imagery`);
  605. }
  606. const provider = new GoogleEarthEnterpriseImageryProvider(options);
  607. provider._metadata = metadata;
  608. provider._ready = true;
  609. provider._readyPromise = Promise.resolve(true);
  610. return provider;
  611. };
  612. /**
  613. * Gets the credits to be displayed when a given tile is displayed.
  614. *
  615. * @param {number} x The tile X coordinate.
  616. * @param {number} y The tile Y coordinate.
  617. * @param {number} level The tile level;
  618. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  619. */
  620. GoogleEarthEnterpriseImageryProvider.prototype.getTileCredits = function (
  621. x,
  622. y,
  623. level
  624. ) {
  625. const metadata = this._metadata;
  626. const info = metadata.getTileInformation(x, y, level);
  627. if (defined(info)) {
  628. const credit = metadata.providers[info.imageryProvider];
  629. if (defined(credit)) {
  630. return [credit];
  631. }
  632. }
  633. return undefined;
  634. };
  635. /**
  636. * Requests the image for a given tile.
  637. *
  638. * @param {number} x The tile X coordinate.
  639. * @param {number} y The tile Y coordinate.
  640. * @param {number} level The tile level.
  641. * @param {Request} [request] The request object. Intended for internal use only.
  642. * @returns {Promise<ImageryTypes>|undefined} A promise for the image that will resolve when the image is available, or
  643. * undefined if there are too many active requests to the server, and the request should be retried later.
  644. */
  645. GoogleEarthEnterpriseImageryProvider.prototype.requestImage = function (
  646. x,
  647. y,
  648. level,
  649. request
  650. ) {
  651. const invalidImage = this._tileDiscardPolicy._image; // Empty image or undefined depending on discard policy
  652. const metadata = this._metadata;
  653. const quadKey = GoogleEarthEnterpriseMetadata.tileXYToQuadKey(x, y, level);
  654. const info = metadata.getTileInformation(x, y, level);
  655. if (!defined(info)) {
  656. if (metadata.isValid(quadKey)) {
  657. const metadataRequest = new Request({
  658. throttle: request.throttle,
  659. throttleByServer: request.throttleByServer,
  660. type: request.type,
  661. priorityFunction: request.priorityFunction,
  662. });
  663. metadata.populateSubtree(x, y, level, metadataRequest);
  664. return undefined; // No metadata so return undefined so we can be loaded later
  665. }
  666. return Promise.resolve(invalidImage); // Image doesn't exist
  667. }
  668. if (!info.hasImagery()) {
  669. // Already have info and there isn't any imagery here
  670. return Promise.resolve(invalidImage);
  671. }
  672. const promise = buildImageResource(
  673. this,
  674. info,
  675. x,
  676. y,
  677. level,
  678. request
  679. ).fetchArrayBuffer();
  680. if (!defined(promise)) {
  681. return undefined; // Throttled
  682. }
  683. return promise.then(function (image) {
  684. decodeGoogleEarthEnterpriseData(metadata.key, image);
  685. let a = new Uint8Array(image);
  686. let type;
  687. const protoImagery = metadata.protoImagery;
  688. if (!defined(protoImagery) || !protoImagery) {
  689. type = getImageType(a);
  690. }
  691. if (!defined(type) && (!defined(protoImagery) || protoImagery)) {
  692. const message = decodeEarthImageryPacket(a);
  693. type = message.imageType;
  694. a = message.imageData;
  695. }
  696. if (!defined(type) || !defined(a)) {
  697. return invalidImage;
  698. }
  699. return loadImageFromTypedArray({
  700. uint8Array: a,
  701. format: type,
  702. flipY: true,
  703. });
  704. });
  705. };
  706. /**
  707. * Picking features is not currently supported by this imagery provider, so this function simply returns
  708. * undefined.
  709. *
  710. * @param {number} x The tile X coordinate.
  711. * @param {number} y The tile Y coordinate.
  712. * @param {number} level The tile level.
  713. * @param {number} longitude The longitude at which to pick features.
  714. * @param {number} latitude The latitude at which to pick features.
  715. * @return {undefined} Undefined since picking is not supported.
  716. */
  717. GoogleEarthEnterpriseImageryProvider.prototype.pickFeatures = function (
  718. x,
  719. y,
  720. level,
  721. longitude,
  722. latitude
  723. ) {
  724. return undefined;
  725. };
  726. //
  727. // Functions to handle imagery packets
  728. //
  729. function buildImageResource(imageryProvider, info, x, y, level, request) {
  730. const quadKey = GoogleEarthEnterpriseMetadata.tileXYToQuadKey(x, y, level);
  731. let version = info.imageryVersion;
  732. version = defined(version) && version > 0 ? version : 1;
  733. return imageryProvider._metadata.resource.getDerivedResource({
  734. url: `flatfile?f1-0${quadKey}-i.${version.toString()}`,
  735. request: request,
  736. });
  737. }
  738. // Detects if a Uint8Array is a JPEG or PNG
  739. function getImageType(image) {
  740. const jpeg = "JFIF";
  741. if (
  742. image[6] === jpeg.charCodeAt(0) &&
  743. image[7] === jpeg.charCodeAt(1) &&
  744. image[8] === jpeg.charCodeAt(2) &&
  745. image[9] === jpeg.charCodeAt(3)
  746. ) {
  747. return "image/jpeg";
  748. }
  749. const png = "PNG";
  750. if (
  751. image[1] === png.charCodeAt(0) &&
  752. image[2] === png.charCodeAt(1) &&
  753. image[3] === png.charCodeAt(2)
  754. ) {
  755. return "image/png";
  756. }
  757. return undefined;
  758. }
  759. // Decodes an Imagery protobuf into the message
  760. // Partially generated with the help of protobuf.js static generator
  761. function decodeEarthImageryPacket(data) {
  762. const reader = protobuf.Reader.create(data);
  763. const end = reader.len;
  764. const message = {};
  765. while (reader.pos < end) {
  766. const tag = reader.uint32();
  767. let copyrightIds;
  768. switch (tag >>> 3) {
  769. case 1:
  770. message.imageType = reader.uint32();
  771. break;
  772. case 2:
  773. message.imageData = reader.bytes();
  774. break;
  775. case 3:
  776. message.alphaType = reader.uint32();
  777. break;
  778. case 4:
  779. message.imageAlpha = reader.bytes();
  780. break;
  781. case 5:
  782. copyrightIds = message.copyrightIds;
  783. if (!defined(copyrightIds)) {
  784. copyrightIds = message.copyrightIds = [];
  785. }
  786. if ((tag & 7) === 2) {
  787. const end2 = reader.uint32() + reader.pos;
  788. while (reader.pos < end2) {
  789. copyrightIds.push(reader.uint32());
  790. }
  791. } else {
  792. copyrightIds.push(reader.uint32());
  793. }
  794. break;
  795. default:
  796. reader.skipType(tag & 7);
  797. break;
  798. }
  799. }
  800. const imageType = message.imageType;
  801. if (defined(imageType)) {
  802. switch (imageType) {
  803. case 0:
  804. message.imageType = "image/jpeg";
  805. break;
  806. case 4:
  807. message.imageType = "image/png";
  808. break;
  809. default:
  810. throw new RuntimeError(
  811. "GoogleEarthEnterpriseImageryProvider: Unsupported image type."
  812. );
  813. }
  814. }
  815. const alphaType = message.alphaType;
  816. if (defined(alphaType) && alphaType !== 0) {
  817. console.log(
  818. "GoogleEarthEnterpriseImageryProvider: External alpha not supported."
  819. );
  820. delete message.alphaType;
  821. delete message.imageAlpha;
  822. }
  823. return message;
  824. }
  825. export default GoogleEarthEnterpriseImageryProvider;