TileCoordinatesImageryProvider.js 12 KB

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