TileCoordinatesImageryProvider.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*global define*/
  2. define([
  3. '../Core/Color',
  4. '../Core/defaultValue',
  5. '../Core/defined',
  6. '../Core/defineProperties',
  7. '../Core/Event',
  8. '../Core/GeographicTilingScheme'
  9. ], function(
  10. Color,
  11. defaultValue,
  12. defined,
  13. defineProperties,
  14. Event,
  15. GeographicTilingScheme) {
  16. "use strict";
  17. /**
  18. * An {@link ImageryProvider} that draws a box around every rendered tile in the tiling scheme, and draws
  19. * a label inside it indicating the X, Y, Level coordinates of the tile. This is mostly useful for
  20. * debugging terrain and imagery rendering problems.
  21. *
  22. * @alias TileCoordinatesImageryProvider
  23. * @constructor
  24. *
  25. * @param {Object} [options] Object with the following properties:
  26. * @param {TilingScheme} [options.tilingScheme=new GeographicTilingScheme()] The tiling scheme for which to draw tiles.
  27. * @param {Color} [options.color=Color.YELLOW] The color to draw the tile box and label.
  28. * @param {Number} [options.tileWidth=256] The width of the tile for level-of-detail selection purposes.
  29. * @param {Number} [options.tileHeight=256] The height of the tile for level-of-detail selection purposes.
  30. */
  31. var TileCoordinatesImageryProvider = function TileCoordinatesImageryProvider(options) {
  32. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  33. this._tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new GeographicTilingScheme();
  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. };
  39. defineProperties(TileCoordinatesImageryProvider.prototype, {
  40. /**
  41. * Gets the proxy used by this provider.
  42. * @memberof TileCoordinatesImageryProvider.prototype
  43. * @type {Proxy}
  44. * @readonly
  45. */
  46. proxy : {
  47. get : function() {
  48. return undefined;
  49. }
  50. },
  51. /**
  52. * Gets the width of each tile, in pixels. This function should
  53. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  54. * @memberof TileCoordinatesImageryProvider.prototype
  55. * @type {Number}
  56. * @readonly
  57. */
  58. tileWidth : {
  59. get : function() {
  60. return this._tileWidth;
  61. }
  62. },
  63. /**
  64. * Gets the height of each tile, in pixels. This function should
  65. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  66. * @memberof TileCoordinatesImageryProvider.prototype
  67. * @type {Number}
  68. * @readonly
  69. */
  70. tileHeight: {
  71. get : function() {
  72. return this._tileHeight;
  73. }
  74. },
  75. /**
  76. * Gets the maximum level-of-detail that can be requested. This function should
  77. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  78. * @memberof TileCoordinatesImageryProvider.prototype
  79. * @type {Number}
  80. * @readonly
  81. */
  82. maximumLevel : {
  83. get : function() {
  84. return undefined;
  85. }
  86. },
  87. /**
  88. * Gets the minimum level-of-detail that can be requested. This function should
  89. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  90. * @memberof TileCoordinatesImageryProvider.prototype
  91. * @type {Number}
  92. * @readonly
  93. */
  94. minimumLevel : {
  95. get : function() {
  96. return undefined;
  97. }
  98. },
  99. /**
  100. * Gets the tiling scheme used by this provider. This function should
  101. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  102. * @memberof TileCoordinatesImageryProvider.prototype
  103. * @type {TilingScheme}
  104. * @readonly
  105. */
  106. tilingScheme : {
  107. get : function() {
  108. return this._tilingScheme;
  109. }
  110. },
  111. /**
  112. * Gets the rectangle, in radians, of the imagery provided by this instance. This function should
  113. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  114. * @memberof TileCoordinatesImageryProvider.prototype
  115. * @type {Rectangle}
  116. * @readonly
  117. */
  118. rectangle : {
  119. get : function() {
  120. return this._tilingScheme.rectangle;
  121. }
  122. },
  123. /**
  124. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  125. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  126. * returns undefined, no tiles are filtered. This function should
  127. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  128. * @memberof TileCoordinatesImageryProvider.prototype
  129. * @type {TileDiscardPolicy}
  130. * @readonly
  131. */
  132. tileDiscardPolicy : {
  133. get : function() {
  134. return undefined;
  135. }
  136. },
  137. /**
  138. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  139. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  140. * are passed an instance of {@link TileProviderError}.
  141. * @memberof TileCoordinatesImageryProvider.prototype
  142. * @type {Event}
  143. * @readonly
  144. */
  145. errorEvent : {
  146. get : function() {
  147. return this._errorEvent;
  148. }
  149. },
  150. /**
  151. * Gets a value indicating whether or not the provider is ready for use.
  152. * @memberof TileCoordinatesImageryProvider.prototype
  153. * @type {Boolean}
  154. * @readonly
  155. */
  156. ready : {
  157. get : function() {
  158. return true;
  159. }
  160. },
  161. /**
  162. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  163. * the source of the imagery. This function should not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  164. * @memberof TileCoordinatesImageryProvider.prototype
  165. * @type {Credit}
  166. * @readonly
  167. */
  168. credit : {
  169. get : function() {
  170. return undefined;
  171. }
  172. },
  173. /**
  174. * Gets a value indicating whether or not the images provided by this imagery provider
  175. * include an alpha channel. If this property is false, an alpha channel, if present, will
  176. * be ignored. If this property is true, any images without an alpha channel will be treated
  177. * as if their alpha is 1.0 everywhere. Setting this property to false reduces memory usage
  178. * and texture upload time.
  179. * @memberof TileCoordinatesImageryProvider.prototype
  180. * @type {Boolean}
  181. * @readonly
  182. */
  183. hasAlphaChannel : {
  184. get : function() {
  185. return true;
  186. }
  187. }
  188. });
  189. /**
  190. * Gets the credits to be displayed when a given tile is displayed.
  191. *
  192. * @param {Number} x The tile X coordinate.
  193. * @param {Number} y The tile Y coordinate.
  194. * @param {Number} level The tile level;
  195. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  196. *
  197. * @exception {DeveloperError} <code>getTileCredits</code> must not be called before the imagery provider is ready.
  198. */
  199. TileCoordinatesImageryProvider.prototype.getTileCredits = function(x, y, level) {
  200. return undefined;
  201. };
  202. /**
  203. * Requests the image for a given tile. This function should
  204. * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
  205. *
  206. * @param {Number} x The tile X coordinate.
  207. * @param {Number} y The tile Y coordinate.
  208. * @param {Number} level The tile level.
  209. * @returns {Promise} A promise for the image that will resolve when the image is available, or
  210. * undefined if there are too many active requests to the server, and the request
  211. * should be retried later. The resolved image may be either an
  212. * Image or a Canvas DOM object.
  213. */
  214. TileCoordinatesImageryProvider.prototype.requestImage = function(x, y, level) {
  215. var canvas = document.createElement('canvas');
  216. canvas.width = 256;
  217. canvas.height = 256;
  218. var context = canvas.getContext('2d');
  219. var cssColor = this._color.toCssColorString();
  220. context.strokeStyle = cssColor;
  221. context.lineWidth = 2;
  222. context.strokeRect(1, 1, 255, 255);
  223. var label = 'L' + level + 'X' + x + 'Y' + y;
  224. context.font = 'bold 25px Arial';
  225. context.textAlign = 'center';
  226. context.fillStyle = 'black';
  227. context.fillText(label, 127, 127);
  228. context.fillStyle = cssColor;
  229. context.fillText(label, 124, 124);
  230. return canvas;
  231. };
  232. /**
  233. * Picking features is not currently supported by this imagery provider, so this function simply returns
  234. * undefined.
  235. *
  236. * @param {Number} x The tile X coordinate.
  237. * @param {Number} y The tile Y coordinate.
  238. * @param {Number} level The tile level.
  239. * @param {Number} longitude The longitude at which to pick features.
  240. * @param {Number} latitude The latitude at which to pick features.
  241. * @return {Promise} A promise for the picked features that will resolve when the asynchronous
  242. * picking completes. The resolved value is an array of {@link ImageryLayerFeatureInfo}
  243. * instances. The array may be empty if no features are found at the given location.
  244. * It may also be undefined if picking is not supported.
  245. */
  246. TileCoordinatesImageryProvider.prototype.pickFeatures = function() {
  247. return undefined;
  248. };
  249. return TileCoordinatesImageryProvider;
  250. });