TileCoordinatesImageryProvider.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. import Color from "../Core/Color.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import deprecationWarning from "../Core/deprecationWarning.js";
  5. import Event from "../Core/Event.js";
  6. import GeographicTilingScheme from "../Core/GeographicTilingScheme.js";
  7. /**
  8. * @typedef {object} TileCoordinatesImageryProvider.ConstructorOptions
  9. *
  10. * Initialization options for the TileCoordinatesImageryProvider constructor
  11. *
  12. * @property {TilingScheme} [tilingScheme=new GeographicTilingScheme()] The tiling scheme for which to draw tiles.
  13. * @property {Ellipsoid} [ellipsoid] The ellipsoid. If the tilingScheme is specified,
  14. * this parameter is ignored and the tiling scheme's ellipsoid is used instead. If neither
  15. * parameter is specified, the WGS84 ellipsoid is used.
  16. * @property {Color} [color=Color.YELLOW] The color to draw the tile box and label.
  17. * @property {number} [tileWidth=256] The width of the tile for level-of-detail selection purposes.
  18. * @property {number} [tileHeight=256] The height of the tile for level-of-detail selection purposes.
  19. */
  20. /**
  21. * An {@link ImageryProvider} that draws a box around every rendered tile in the tiling scheme, and draws
  22. * a label inside it indicating the X, Y, Level coordinates of the tile. This is mostly useful for
  23. * debugging terrain and imagery rendering problems.
  24. *
  25. * @alias TileCoordinatesImageryProvider
  26. * @constructor
  27. *
  28. * @param {TileCoordinatesImageryProvider.ConstructorOptions} [options] Object describing initialization options
  29. */
  30. function TileCoordinatesImageryProvider(options) {
  31. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  32. this._tilingScheme = defined(options.tilingScheme)
  33. ? options.tilingScheme
  34. : new GeographicTilingScheme({ ellipsoid: options.ellipsoid });
  35. this._color = defaultValue(options.color, Color.YELLOW);
  36. this._errorEvent = new Event();
  37. this._tileWidth = defaultValue(options.tileWidth, 256);
  38. this._tileHeight = defaultValue(options.tileHeight, 256);
  39. this._ready = true;
  40. this._readyPromise = Promise.resolve(true);
  41. this._defaultAlpha = undefined;
  42. this._defaultNightAlpha = undefined;
  43. this._defaultDayAlpha = undefined;
  44. this._defaultBrightness = undefined;
  45. this._defaultContrast = undefined;
  46. this._defaultHue = undefined;
  47. this._defaultSaturation = undefined;
  48. this._defaultGamma = undefined;
  49. this._defaultMinificationFilter = undefined;
  50. this._defaultMagnificationFilter = undefined;
  51. }
  52. Object.defineProperties(TileCoordinatesImageryProvider.prototype, {
  53. /**
  54. * Gets the proxy used by this provider.
  55. * @memberof TileCoordinatesImageryProvider.prototype
  56. * @type {Proxy}
  57. * @readonly
  58. */
  59. proxy: {
  60. get: function () {
  61. return undefined;
  62. },
  63. },
  64. /**
  65. * Gets the width of each tile, in pixels.
  66. * @memberof TileCoordinatesImageryProvider.prototype
  67. * @type {number}
  68. * @readonly
  69. */
  70. tileWidth: {
  71. get: function () {
  72. return this._tileWidth;
  73. },
  74. },
  75. /**
  76. * Gets the height of each tile, in pixels.
  77. * @memberof TileCoordinatesImageryProvider.prototype
  78. * @type {number}
  79. * @readonly
  80. */
  81. tileHeight: {
  82. get: function () {
  83. return this._tileHeight;
  84. },
  85. },
  86. /**
  87. * Gets the maximum level-of-detail that can be requested.
  88. * @memberof TileCoordinatesImageryProvider.prototype
  89. * @type {number|undefined}
  90. * @readonly
  91. */
  92. maximumLevel: {
  93. get: function () {
  94. return undefined;
  95. },
  96. },
  97. /**
  98. * Gets the minimum level-of-detail that can be requested.
  99. * @memberof TileCoordinatesImageryProvider.prototype
  100. * @type {number}
  101. * @readonly
  102. */
  103. minimumLevel: {
  104. get: function () {
  105. return undefined;
  106. },
  107. },
  108. /**
  109. * Gets the tiling scheme used by this provider.
  110. * @memberof TileCoordinatesImageryProvider.prototype
  111. * @type {TilingScheme}
  112. * @readonly
  113. */
  114. tilingScheme: {
  115. get: function () {
  116. return this._tilingScheme;
  117. },
  118. },
  119. /**
  120. * Gets the rectangle, in radians, of the imagery provided by this instance.
  121. * @memberof TileCoordinatesImageryProvider.prototype
  122. * @type {Rectangle}
  123. * @readonly
  124. */
  125. rectangle: {
  126. get: function () {
  127. return this._tilingScheme.rectangle;
  128. },
  129. },
  130. /**
  131. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  132. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  133. * returns undefined, no tiles are filtered.
  134. * @memberof TileCoordinatesImageryProvider.prototype
  135. * @type {TileDiscardPolicy}
  136. * @readonly
  137. */
  138. tileDiscardPolicy: {
  139. get: function () {
  140. return undefined;
  141. },
  142. },
  143. /**
  144. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  145. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  146. * are passed an instance of {@link TileProviderError}.
  147. * @memberof TileCoordinatesImageryProvider.prototype
  148. * @type {Event}
  149. * @readonly
  150. */
  151. errorEvent: {
  152. get: function () {
  153. return this._errorEvent;
  154. },
  155. },
  156. /**
  157. * Gets a value indicating whether or not the provider is ready for use.
  158. * @memberof TileCoordinatesImageryProvider.prototype
  159. * @type {boolean}
  160. * @readonly
  161. * @deprecated
  162. */
  163. ready: {
  164. get: function () {
  165. deprecationWarning(
  166. "TileCoordinatesImageryProvider.ready",
  167. "TileCoordinatesImageryProvider.ready was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107."
  168. );
  169. return true;
  170. },
  171. },
  172. /**
  173. * Gets a promise that resolves to true when the provider is ready for use.
  174. * @memberof TileCoordinatesImageryProvider.prototype
  175. * @type {Promise<boolean>}
  176. * @readonly
  177. * @deprecated
  178. */
  179. readyPromise: {
  180. get: function () {
  181. deprecationWarning(
  182. "TileCoordinatesImageryProvider.readyPromise",
  183. "TileCoordinatesImageryProvider.readyPromise was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107."
  184. );
  185. return this._readyPromise;
  186. },
  187. },
  188. /**
  189. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  190. * the source of the imagery.
  191. * @memberof TileCoordinatesImageryProvider.prototype
  192. * @type {Credit}
  193. * @readonly
  194. */
  195. credit: {
  196. get: function () {
  197. return undefined;
  198. },
  199. },
  200. /**
  201. * Gets a value indicating whether or not the images provided by this imagery provider
  202. * include an alpha channel. If this property is false, an alpha channel, if present, will
  203. * be ignored. If this property is true, any images without an alpha channel will be treated
  204. * as if their alpha is 1.0 everywhere. Setting this property to false reduces memory usage
  205. * and texture upload time.
  206. * @memberof TileCoordinatesImageryProvider.prototype
  207. * @type {boolean}
  208. * @readonly
  209. */
  210. hasAlphaChannel: {
  211. get: function () {
  212. return true;
  213. },
  214. },
  215. /**
  216. * The default alpha blending value of this provider, with 0.0 representing fully transparent and
  217. * 1.0 representing fully opaque.
  218. * @memberof TileCoordinatesImageryProvider.prototype
  219. * @type {Number|undefined}
  220. * @deprecated
  221. */
  222. defaultAlpha: {
  223. get: function () {
  224. deprecationWarning(
  225. "TileCoordinatesImageryProvider.defaultAlpha",
  226. "TileCoordinatesImageryProvider.defaultAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.alpha instead."
  227. );
  228. return this._defaultAlpha;
  229. },
  230. set: function (value) {
  231. deprecationWarning(
  232. "TileCoordinatesImageryProvider.defaultAlpha",
  233. "TileCoordinatesImageryProvider.defaultAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.alpha instead."
  234. );
  235. this._defaultAlpha = value;
  236. },
  237. },
  238. /**
  239. * The default alpha blending value on the night side of the globe of this provider, with 0.0 representing fully transparent and
  240. * 1.0 representing fully opaque.
  241. * @memberof TileCoordinatesImageryProvider.prototype
  242. * @type {Number|undefined}
  243. * @deprecated
  244. */
  245. defaultNightAlpha: {
  246. get: function () {
  247. deprecationWarning(
  248. "TileCoordinatesImageryProvider.defaultNightAlpha",
  249. "TileCoordinatesImageryProvider.defaultNightAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.nightAlpha instead."
  250. );
  251. return this._defaultNightAlpha;
  252. },
  253. set: function (value) {
  254. deprecationWarning(
  255. "TileCoordinatesImageryProvider.defaultNightAlpha",
  256. "TileCoordinatesImageryProvider.defaultNightAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.nightAlpha instead."
  257. );
  258. this._defaultNightAlpha = value;
  259. },
  260. },
  261. /**
  262. * The default alpha blending value on the day side of the globe of this provider, with 0.0 representing fully transparent and
  263. * 1.0 representing fully opaque.
  264. * @memberof TileCoordinatesImageryProvider.prototype
  265. * @type {Number|undefined}
  266. * @deprecated
  267. */
  268. defaultDayAlpha: {
  269. get: function () {
  270. deprecationWarning(
  271. "TileCoordinatesImageryProvider.defaultDayAlpha",
  272. "TileCoordinatesImageryProvider.defaultDayAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.dayAlpha instead."
  273. );
  274. return this._defaultDayAlpha;
  275. },
  276. set: function (value) {
  277. deprecationWarning(
  278. "TileCoordinatesImageryProvider.defaultDayAlpha",
  279. "TileCoordinatesImageryProvider.defaultDayAlpha was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.dayAlpha instead."
  280. );
  281. this._defaultDayAlpha = value;
  282. },
  283. },
  284. /**
  285. * The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
  286. * makes the imagery darker while greater than 1.0 makes it brighter.
  287. * @memberof TileCoordinatesImageryProvider.prototype
  288. * @type {Number|undefined}
  289. * @deprecated
  290. */
  291. defaultBrightness: {
  292. get: function () {
  293. deprecationWarning(
  294. "TileCoordinatesImageryProvider.defaultBrightness",
  295. "TileCoordinatesImageryProvider.defaultBrightness was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.brightness instead."
  296. );
  297. return this._defaultBrightness;
  298. },
  299. set: function (value) {
  300. deprecationWarning(
  301. "TileCoordinatesImageryProvider.defaultBrightness",
  302. "TileCoordinatesImageryProvider.defaultBrightness was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.brightness instead."
  303. );
  304. this._defaultBrightness = value;
  305. },
  306. },
  307. /**
  308. * The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
  309. * the contrast while greater than 1.0 increases it.
  310. * @memberof TileCoordinatesImageryProvider.prototype
  311. * @type {Number|undefined}
  312. * @deprecated
  313. */
  314. defaultContrast: {
  315. get: function () {
  316. deprecationWarning(
  317. "TileCoordinatesImageryProvider.defaultContrast",
  318. "TileCoordinatesImageryProvider.defaultContrast was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.contrast instead."
  319. );
  320. return this._defaultContrast;
  321. },
  322. set: function (value) {
  323. deprecationWarning(
  324. "TileCoordinatesImageryProvider.defaultContrast",
  325. "TileCoordinatesImageryProvider.defaultContrast was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.contrast instead."
  326. );
  327. this._defaultContrast = value;
  328. },
  329. },
  330. /**
  331. * The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
  332. * @memberof TileCoordinatesImageryProvider.prototype
  333. * @type {Number|undefined}
  334. * @deprecated
  335. */
  336. defaultHue: {
  337. get: function () {
  338. deprecationWarning(
  339. "TileCoordinatesImageryProvider.defaultHue",
  340. "TileCoordinatesImageryProvider.defaultHue was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.hue instead."
  341. );
  342. return this._defaultHue;
  343. },
  344. set: function (value) {
  345. deprecationWarning(
  346. "TileCoordinatesImageryProvider.defaultHue",
  347. "TileCoordinatesImageryProvider.defaultHue was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.hue instead."
  348. );
  349. this._defaultHue = value;
  350. },
  351. },
  352. /**
  353. * The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
  354. * saturation while greater than 1.0 increases it.
  355. * @memberof TileCoordinatesImageryProvider.prototype
  356. * @type {Number|undefined}
  357. * @deprecated
  358. */
  359. defaultSaturation: {
  360. get: function () {
  361. deprecationWarning(
  362. "TileCoordinatesImageryProvider.defaultSaturation",
  363. "TileCoordinatesImageryProvider.defaultSaturation was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.saturation instead."
  364. );
  365. return this._defaultSaturation;
  366. },
  367. set: function (value) {
  368. deprecationWarning(
  369. "TileCoordinatesImageryProvider.defaultSaturation",
  370. "TileCoordinatesImageryProvider.defaultSaturation was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.saturation instead."
  371. );
  372. this._defaultSaturation = value;
  373. },
  374. },
  375. /**
  376. * The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
  377. * @memberof TileCoordinatesImageryProvider.prototype
  378. * @type {Number|undefined}
  379. * @deprecated
  380. */
  381. defaultGamma: {
  382. get: function () {
  383. deprecationWarning(
  384. "TileCoordinatesImageryProvider.defaultGamma",
  385. "TileCoordinatesImageryProvider.defaultGamma was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.gamma instead."
  386. );
  387. return this._defaultGamma;
  388. },
  389. set: function (value) {
  390. deprecationWarning(
  391. "TileCoordinatesImageryProvider.defaultGamma",
  392. "TileCoordinatesImageryProvider.defaultGamma was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.gamma instead."
  393. );
  394. this._defaultGamma = value;
  395. },
  396. },
  397. /**
  398. * The default texture minification filter to apply to this provider.
  399. * @memberof TileCoordinatesImageryProvider.prototype
  400. * @type {TextureMinificationFilter}
  401. * @deprecated
  402. */
  403. defaultMinificationFilter: {
  404. get: function () {
  405. deprecationWarning(
  406. "TileCoordinatesImageryProvider.defaultMinificationFilter",
  407. "TileCoordinatesImageryProvider.defaultMinificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.minificationFilter instead."
  408. );
  409. return this._defaultMinificationFilter;
  410. },
  411. set: function (value) {
  412. deprecationWarning(
  413. "TileCoordinatesImageryProvider.defaultMinificationFilter",
  414. "TileCoordinatesImageryProvider.defaultMinificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.minificationFilter instead."
  415. );
  416. this._defaultMinificationFilter = value;
  417. },
  418. },
  419. /**
  420. * The default texture magnification filter to apply to this provider.
  421. * @memberof TileCoordinatesImageryProvider.prototype
  422. * @type {TextureMagnificationFilter}
  423. * @deprecated
  424. */
  425. defaultMagnificationFilter: {
  426. get: function () {
  427. deprecationWarning(
  428. "TileCoordinatesImageryProvider.defaultMagnificationFilter",
  429. "TileCoordinatesImageryProvider.defaultMagnificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.magnificationFilter instead."
  430. );
  431. return this._defaultMagnificationFilter;
  432. },
  433. set: function (value) {
  434. deprecationWarning(
  435. "TileCoordinatesImageryProvider.defaultMagnificationFilter",
  436. "TileCoordinatesImageryProvider.defaultMagnificationFilter was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use ImageryLayer.magnificationFilter instead."
  437. );
  438. this._defaultMagnificationFilter = value;
  439. },
  440. },
  441. });
  442. /**
  443. * Gets the credits to be displayed when a given tile is displayed.
  444. *
  445. * @param {number} x The tile X coordinate.
  446. * @param {number} y The tile Y coordinate.
  447. * @param {number} level The tile level;
  448. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  449. */
  450. TileCoordinatesImageryProvider.prototype.getTileCredits = function (
  451. x,
  452. y,
  453. level
  454. ) {
  455. return undefined;
  456. };
  457. /**
  458. * Requests the image for a given tile.
  459. *
  460. * @param {number} x The tile X coordinate.
  461. * @param {number} y The tile Y coordinate.
  462. * @param {number} level The tile level.
  463. * @param {Request} [request] The request object. Intended for internal use only.
  464. * @returns {Promise<HTMLCanvasElement>} The resolved image as a Canvas DOM object.
  465. */
  466. TileCoordinatesImageryProvider.prototype.requestImage = function (
  467. x,
  468. y,
  469. level,
  470. request
  471. ) {
  472. const canvas = document.createElement("canvas");
  473. canvas.width = 256;
  474. canvas.height = 256;
  475. const context = canvas.getContext("2d");
  476. const cssColor = this._color.toCssColorString();
  477. context.strokeStyle = cssColor;
  478. context.lineWidth = 2;
  479. context.strokeRect(1, 1, 255, 255);
  480. context.font = "bold 25px Arial";
  481. context.textAlign = "center";
  482. context.fillStyle = cssColor;
  483. context.fillText(`L: ${level}`, 124, 86);
  484. context.fillText(`X: ${x}`, 124, 136);
  485. context.fillText(`Y: ${y}`, 124, 186);
  486. return Promise.resolve(canvas);
  487. };
  488. /**
  489. * Picking features is not currently supported by this imagery provider, so this function simply returns
  490. * undefined.
  491. *
  492. * @param {number} x The tile X coordinate.
  493. * @param {number} y The tile Y coordinate.
  494. * @param {number} level The tile level.
  495. * @param {number} longitude The longitude at which to pick features.
  496. * @param {number} latitude The latitude at which to pick features.
  497. * @return {undefined} Undefined since picking is not supported.
  498. */
  499. TileCoordinatesImageryProvider.prototype.pickFeatures = function (
  500. x,
  501. y,
  502. level,
  503. longitude,
  504. latitude
  505. ) {
  506. return undefined;
  507. };
  508. export default TileCoordinatesImageryProvider;