TileCoordinatesImageryProvider.js 11 KB

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