TileCoordinatesImageryProvider.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. import Color from "../Core/Color.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import Event from "../Core/Event.js";
  5. import GeographicTilingScheme from "../Core/GeographicTilingScheme.js";
  6. /**
  7. * @typedef {Object} TileCoordinatesImageryProvider.ConstructorOptions
  8. *
  9. * Initialization options for the TileCoordinatesImageryProvider constructor
  10. *
  11. * @property {TilingScheme} [tilingScheme=new GeographicTilingScheme()] The tiling scheme for which to draw tiles.
  12. * @property {Ellipsoid} [ellipsoid] The ellipsoid. If the tilingScheme is specified,
  13. * this parameter is ignored and the tiling scheme's ellipsoid is used instead. If neither
  14. * parameter is specified, the WGS84 ellipsoid is used.
  15. * @property {Color} [color=Color.YELLOW] The color to draw the tile box and label.
  16. * @property {Number} [tileWidth=256] The width of the tile for level-of-detail selection purposes.
  17. * @property {Number} [tileHeight=256] The height of the tile for level-of-detail selection purposes.
  18. */
  19. /**
  20. * An {@link ImageryProvider} that draws a box around every rendered tile in the tiling scheme, and draws
  21. * a label inside it indicating the X, Y, Level coordinates of the tile. This is mostly useful for
  22. * debugging terrain and imagery rendering problems.
  23. *
  24. * @alias TileCoordinatesImageryProvider
  25. * @constructor
  26. *
  27. * @param {TileCoordinatesImageryProvider.ConstructorOptions} [options] Object describing initialization options
  28. */
  29. function TileCoordinatesImageryProvider(options) {
  30. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  31. this._tilingScheme = defined(options.tilingScheme)
  32. ? options.tilingScheme
  33. : new GeographicTilingScheme({ ellipsoid: options.ellipsoid });
  34. this._color = defaultValue(options.color, Color.YELLOW);
  35. this._errorEvent = new Event();
  36. this._tileWidth = defaultValue(options.tileWidth, 256);
  37. this._tileHeight = defaultValue(options.tileHeight, 256);
  38. this._readyPromise = Promise.resolve(true);
  39. /**
  40. * The default alpha blending value of this provider, with 0.0 representing fully transparent and
  41. * 1.0 representing fully opaque.
  42. *
  43. * @type {Number|undefined}
  44. * @default undefined
  45. */
  46. this.defaultAlpha = undefined;
  47. /**
  48. * The default alpha blending value on the night side of the globe of this provider, with 0.0 representing fully transparent and
  49. * 1.0 representing fully opaque.
  50. *
  51. * @type {Number|undefined}
  52. * @default undefined
  53. */
  54. this.defaultNightAlpha = undefined;
  55. /**
  56. * The default alpha blending value on the day side of the globe of this provider, with 0.0 representing fully transparent and
  57. * 1.0 representing fully opaque.
  58. *
  59. * @type {Number|undefined}
  60. * @default undefined
  61. */
  62. this.defaultDayAlpha = undefined;
  63. /**
  64. * The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
  65. * makes the imagery darker while greater than 1.0 makes it brighter.
  66. *
  67. * @type {Number|undefined}
  68. * @default undefined
  69. */
  70. this.defaultBrightness = undefined;
  71. /**
  72. * The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
  73. * the contrast while greater than 1.0 increases it.
  74. *
  75. * @type {Number|undefined}
  76. * @default undefined
  77. */
  78. this.defaultContrast = undefined;
  79. /**
  80. * The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
  81. *
  82. * @type {Number|undefined}
  83. * @default undefined
  84. */
  85. this.defaultHue = undefined;
  86. /**
  87. * The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
  88. * saturation while greater than 1.0 increases it.
  89. *
  90. * @type {Number|undefined}
  91. * @default undefined
  92. */
  93. this.defaultSaturation = undefined;
  94. /**
  95. * The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
  96. *
  97. * @type {Number|undefined}
  98. * @default undefined
  99. */
  100. this.defaultGamma = undefined;
  101. /**
  102. * The default texture minification filter to apply to this provider.
  103. *
  104. * @type {TextureMinificationFilter}
  105. * @default undefined
  106. */
  107. this.defaultMinificationFilter = undefined;
  108. /**
  109. * The default texture magnification filter to apply to this provider.
  110. *
  111. * @type {TextureMagnificationFilter}
  112. * @default undefined
  113. */
  114. this.defaultMagnificationFilter = undefined;
  115. }
  116. Object.defineProperties(TileCoordinatesImageryProvider.prototype, {
  117. /**
  118. * Gets the proxy used by this provider.
  119. * @memberof TileCoordinatesImageryProvider.prototype
  120. * @type {Proxy}
  121. * @readonly
  122. */
  123. proxy: {
  124. get: function () {
  125. return undefined;
  126. },
  127. },
  128. /**
  129. * Gets the width of each tile, in pixels. This function should
  130. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  131. * @memberof TileCoordinatesImageryProvider.prototype
  132. * @type {Number}
  133. * @readonly
  134. */
  135. tileWidth: {
  136. get: function () {
  137. return this._tileWidth;
  138. },
  139. },
  140. /**
  141. * Gets the height of each tile, in pixels. This function should
  142. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  143. * @memberof TileCoordinatesImageryProvider.prototype
  144. * @type {Number}
  145. * @readonly
  146. */
  147. tileHeight: {
  148. get: function () {
  149. return this._tileHeight;
  150. },
  151. },
  152. /**
  153. * Gets the maximum level-of-detail that can be requested. This function should
  154. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  155. * @memberof TileCoordinatesImageryProvider.prototype
  156. * @type {Number|undefined}
  157. * @readonly
  158. */
  159. maximumLevel: {
  160. get: function () {
  161. return undefined;
  162. },
  163. },
  164. /**
  165. * Gets the minimum level-of-detail that can be requested. This function should
  166. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  167. * @memberof TileCoordinatesImageryProvider.prototype
  168. * @type {Number}
  169. * @readonly
  170. */
  171. minimumLevel: {
  172. get: function () {
  173. return undefined;
  174. },
  175. },
  176. /**
  177. * Gets the tiling scheme used by this provider. This function should
  178. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  179. * @memberof TileCoordinatesImageryProvider.prototype
  180. * @type {TilingScheme}
  181. * @readonly
  182. */
  183. tilingScheme: {
  184. get: function () {
  185. return this._tilingScheme;
  186. },
  187. },
  188. /**
  189. * Gets the rectangle, in radians, of the imagery provided by this instance. This function should
  190. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  191. * @memberof TileCoordinatesImageryProvider.prototype
  192. * @type {Rectangle}
  193. * @readonly
  194. */
  195. rectangle: {
  196. get: function () {
  197. return this._tilingScheme.rectangle;
  198. },
  199. },
  200. /**
  201. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  202. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  203. * returns undefined, no tiles are filtered. This function should
  204. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  205. * @memberof TileCoordinatesImageryProvider.prototype
  206. * @type {TileDiscardPolicy}
  207. * @readonly
  208. */
  209. tileDiscardPolicy: {
  210. get: function () {
  211. return undefined;
  212. },
  213. },
  214. /**
  215. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  216. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  217. * are passed an instance of {@link TileProviderError}.
  218. * @memberof TileCoordinatesImageryProvider.prototype
  219. * @type {Event}
  220. * @readonly
  221. */
  222. errorEvent: {
  223. get: function () {
  224. return this._errorEvent;
  225. },
  226. },
  227. /**
  228. * Gets a value indicating whether or not the provider is ready for use.
  229. * @memberof TileCoordinatesImageryProvider.prototype
  230. * @type {Boolean}
  231. * @readonly
  232. */
  233. ready: {
  234. get: function () {
  235. return true;
  236. },
  237. },
  238. /**
  239. * Gets a promise that resolves to true when the provider is ready for use.
  240. * @memberof TileCoordinatesImageryProvider.prototype
  241. * @type {Promise.<Boolean>}
  242. * @readonly
  243. */
  244. readyPromise: {
  245. get: function () {
  246. return this._readyPromise;
  247. },
  248. },
  249. /**
  250. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  251. * the source of the imagery. This function should not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  252. * @memberof TileCoordinatesImageryProvider.prototype
  253. * @type {Credit}
  254. * @readonly
  255. */
  256. credit: {
  257. get: function () {
  258. return undefined;
  259. },
  260. },
  261. /**
  262. * Gets a value indicating whether or not the images provided by this imagery provider
  263. * include an alpha channel. If this property is false, an alpha channel, if present, will
  264. * be ignored. If this property is true, any images without an alpha channel will be treated
  265. * as if their alpha is 1.0 everywhere. Setting this property to false reduces memory usage
  266. * and texture upload time.
  267. * @memberof TileCoordinatesImageryProvider.prototype
  268. * @type {Boolean}
  269. * @readonly
  270. */
  271. hasAlphaChannel: {
  272. get: function () {
  273. return true;
  274. },
  275. },
  276. });
  277. /**
  278. * Gets the credits to be displayed when a given tile is displayed.
  279. *
  280. * @param {Number} x The tile X coordinate.
  281. * @param {Number} y The tile Y coordinate.
  282. * @param {Number} level The tile level;
  283. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  284. *
  285. * @exception {DeveloperError} <code>getTileCredits</code> must not be called before the imagery provider is ready.
  286. */
  287. TileCoordinatesImageryProvider.prototype.getTileCredits = function (
  288. x,
  289. y,
  290. level
  291. ) {
  292. return undefined;
  293. };
  294. /**
  295. * Requests the image for a given tile. This function should
  296. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  297. *
  298. * @param {Number} x The tile X coordinate.
  299. * @param {Number} y The tile Y coordinate.
  300. * @param {Number} level The tile level.
  301. * @param {Request} [request] The request object. Intended for internal use only.
  302. * @returns {Promise.<HTMLCanvasElement>} The resolved image as a Canvas DOM object.
  303. */
  304. TileCoordinatesImageryProvider.prototype.requestImage = function (
  305. x,
  306. y,
  307. level,
  308. request
  309. ) {
  310. const canvas = document.createElement("canvas");
  311. canvas.width = 256;
  312. canvas.height = 256;
  313. const context = canvas.getContext("2d");
  314. const cssColor = this._color.toCssColorString();
  315. context.strokeStyle = cssColor;
  316. context.lineWidth = 2;
  317. context.strokeRect(1, 1, 255, 255);
  318. context.font = "bold 25px Arial";
  319. context.textAlign = "center";
  320. context.fillStyle = cssColor;
  321. context.fillText(`L: ${level}`, 124, 86);
  322. context.fillText(`X: ${x}`, 124, 136);
  323. context.fillText(`Y: ${y}`, 124, 186);
  324. return Promise.resolve(canvas);
  325. };
  326. /**
  327. * Picking features is not currently supported by this imagery provider, so this function simply returns
  328. * undefined.
  329. *
  330. * @param {Number} x The tile X coordinate.
  331. * @param {Number} y The tile Y coordinate.
  332. * @param {Number} level The tile level.
  333. * @param {Number} longitude The longitude at which to pick features.
  334. * @param {Number} latitude The latitude at which to pick features.
  335. * @return {undefined} Undefined since picking is not supported.
  336. */
  337. TileCoordinatesImageryProvider.prototype.pickFeatures = function (
  338. x,
  339. y,
  340. level,
  341. longitude,
  342. latitude
  343. ) {
  344. return undefined;
  345. };
  346. export default TileCoordinatesImageryProvider;