ImageryProvider.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*global define*/
  2. define([
  3. '../Core/defined',
  4. '../Core/defineProperties',
  5. '../Core/DeveloperError',
  6. '../Core/loadImage',
  7. '../Core/loadImageViaBlob',
  8. '../Core/throttleRequestByServer'
  9. ], function(
  10. defined,
  11. defineProperties,
  12. DeveloperError,
  13. loadImage,
  14. loadImageViaBlob,
  15. throttleRequestByServer) {
  16. "use strict";
  17. /**
  18. * Provides imagery to be displayed on the surface of an ellipsoid. This type describes an
  19. * interface and is not intended to be instantiated directly.
  20. *
  21. * @alias ImageryProvider
  22. * @constructor
  23. *
  24. * @see ArcGisMapServerImageryProvider
  25. * @see SingleTileImageryProvider
  26. * @see BingMapsImageryProvider
  27. * @see GoogleEarthImageryProvider
  28. * @see OpenStreetMapImageryProvider
  29. * @see WebMapTileServiceImageryProvider
  30. * @see WebMapServiceImageryProvider
  31. *
  32. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Imagery%20Layers.html|Cesium Sandcastle Imagery Layers Demo}
  33. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Imagery%20Layers%20Manipulation.html|Cesium Sandcastle Imagery Manipulation Demo}
  34. */
  35. var ImageryProvider = function ImageryProvider() {
  36. /**
  37. * The default alpha blending value of this provider, with 0.0 representing fully transparent and
  38. * 1.0 representing fully opaque.
  39. *
  40. * @type {Number}
  41. * @default undefined
  42. */
  43. this.defaultAlpha = undefined;
  44. /**
  45. * The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
  46. * makes the imagery darker while greater than 1.0 makes it brighter.
  47. *
  48. * @type {Number}
  49. * @default undefined
  50. */
  51. this.defaultBrightness = undefined;
  52. /**
  53. * The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
  54. * the contrast while greater than 1.0 increases it.
  55. *
  56. * @type {Number}
  57. * @default undefined
  58. */
  59. this.defaultContrast = undefined;
  60. /**
  61. * The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
  62. *
  63. * @type {Number}
  64. * @default undefined
  65. */
  66. this.defaultHue = undefined;
  67. /**
  68. * The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
  69. * saturation while greater than 1.0 increases it.
  70. *
  71. * @type {Number}
  72. * @default undefined
  73. */
  74. this.defaultSaturation = undefined;
  75. /**
  76. * The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
  77. *
  78. * @type {Number}
  79. * @default undefined
  80. */
  81. this.defaultGamma = undefined;
  82. DeveloperError.throwInstantiationError();
  83. };
  84. defineProperties(ImageryProvider.prototype, {
  85. /**
  86. * Gets a value indicating whether or not the provider is ready for use.
  87. * @memberof ImageryProvider.prototype
  88. * @type {Boolean}
  89. * @readonly
  90. */
  91. ready : {
  92. get : DeveloperError.throwInstantiationError
  93. },
  94. /**
  95. * Gets the rectangle, in radians, of the imagery provided by the instance. This function should
  96. * not be called before {@link ImageryProvider#ready} returns true.
  97. * @memberof ImageryProvider.prototype
  98. * @type {Rectangle}
  99. * @readonly
  100. */
  101. rectangle: {
  102. get : DeveloperError.throwInstantiationError
  103. },
  104. /**
  105. * Gets the width of each tile, in pixels. This function should
  106. * not be called before {@link ImageryProvider#ready} returns true.
  107. * @memberof ImageryProvider.prototype
  108. * @type {Number}
  109. * @readonly
  110. */
  111. tileWidth : {
  112. get : DeveloperError.throwInstantiationError
  113. },
  114. /**
  115. * Gets the height of each tile, in pixels. This function should
  116. * not be called before {@link ImageryProvider#ready} returns true.
  117. * @memberof ImageryProvider.prototype
  118. * @type {Number}
  119. * @readonly
  120. */
  121. tileHeight : {
  122. get : DeveloperError.throwInstantiationError
  123. },
  124. /**
  125. * Gets the maximum level-of-detail that can be requested. This function should
  126. * not be called before {@link ImageryProvider#ready} returns true.
  127. * @memberof ImageryProvider.prototype
  128. * @type {Number}
  129. * @readonly
  130. */
  131. maximumLevel : {
  132. get : DeveloperError.throwInstantiationError
  133. },
  134. /**
  135. * Gets the minimum level-of-detail that can be requested. This function should
  136. * not be called before {@link ImageryProvider#ready} returns true. Generally,
  137. * a minimum level should only be used when the rectangle of the imagery is small
  138. * enough that the number of tiles at the minimum level is small. An imagery
  139. * provider with more than a few tiles at the minimum level will lead to
  140. * rendering problems.
  141. * @memberof ImageryProvider.prototype
  142. * @type {Number}
  143. * @readonly
  144. */
  145. minimumLevel : {
  146. get : DeveloperError.throwInstantiationError
  147. },
  148. /**
  149. * Gets the tiling scheme used by the provider. This function should
  150. * not be called before {@link ImageryProvider#ready} returns true.
  151. * @memberof ImageryProvider.prototype
  152. * @type {TilingScheme}
  153. * @readonly
  154. */
  155. tilingScheme : {
  156. get : DeveloperError.throwInstantiationError
  157. },
  158. /**
  159. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  160. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  161. * returns undefined, no tiles are filtered. This function should
  162. * not be called before {@link ImageryProvider#ready} returns true.
  163. * @memberof ImageryProvider.prototype
  164. * @type {TileDiscardPolicy}
  165. * @readonly
  166. */
  167. tileDiscardPolicy : {
  168. get : DeveloperError.throwInstantiationError
  169. },
  170. /**
  171. * Gets an event that is raised when the imagery provider encounters an asynchronous error.. By subscribing
  172. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  173. * are passed an instance of {@link TileProviderError}.
  174. * @memberof ImageryProvider.prototype
  175. * @type {Event}
  176. * @readonly
  177. */
  178. errorEvent : {
  179. get : DeveloperError.throwInstantiationError
  180. },
  181. /**
  182. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  183. * the source of the imagery. This function should
  184. * not be called before {@link ImageryProvider#ready} returns true.
  185. * @memberof ImageryProvider.prototype
  186. * @type {Credit}
  187. * @readonly
  188. */
  189. credit : {
  190. get : DeveloperError.throwInstantiationError
  191. },
  192. /**
  193. * Gets the proxy used by this provider.
  194. * @memberof ImageryProvider.prototype
  195. * @type {Proxy}
  196. * @readonly
  197. */
  198. proxy : {
  199. get : DeveloperError.throwInstantiationError
  200. },
  201. /**
  202. * Gets a value indicating whether or not the images provided by this imagery provider
  203. * include an alpha channel. If this property is false, an alpha channel, if present, will
  204. * be ignored. If this property is true, any images without an alpha channel will be treated
  205. * as if their alpha is 1.0 everywhere. When this property is false, memory usage
  206. * and texture upload time are reduced.
  207. * @memberof ImageryProvider.prototype
  208. * @type {Boolean}
  209. * @readonly
  210. */
  211. hasAlphaChannel : {
  212. get : DeveloperError.throwInstantiationError
  213. }
  214. });
  215. /**
  216. * Gets the credits to be displayed when a given tile is displayed.
  217. * @function
  218. *
  219. * @param {Number} x The tile X coordinate.
  220. * @param {Number} y The tile Y coordinate.
  221. * @param {Number} level The tile level;
  222. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  223. *
  224. * @exception {DeveloperError} <code>getTileCredits</code> must not be called before the imagery provider is ready.
  225. */
  226. ImageryProvider.prototype.getTileCredits = DeveloperError.throwInstantiationError;
  227. /**
  228. * Requests the image for a given tile. This function should
  229. * not be called before {@link ImageryProvider#ready} returns true.
  230. * @function
  231. *
  232. * @param {Number} x The tile X coordinate.
  233. * @param {Number} y The tile Y coordinate.
  234. * @param {Number} level The tile level.
  235. * @returns {Promise} A promise for the image that will resolve when the image is available, or
  236. * undefined if there are too many active requests to the server, and the request
  237. * should be retried later. The resolved image may be either an
  238. * Image or a Canvas DOM object.
  239. *
  240. * @exception {DeveloperError} <code>requestImage</code> must not be called before the imagery provider is ready.
  241. */
  242. ImageryProvider.prototype.requestImage = DeveloperError.throwInstantiationError;
  243. /**
  244. * Asynchronously determines what features, if any, are located at a given longitude and latitude within
  245. * a tile. This function should not be called before {@link ImageryProvider#ready} returns true.
  246. * This function is optional, so it may not exist on all ImageryProviders.
  247. *
  248. * @function
  249. *
  250. * @param {Number} x The tile X coordinate.
  251. * @param {Number} y The tile Y coordinate.
  252. * @param {Number} level The tile level.
  253. * @param {Number} longitude The longitude at which to pick features.
  254. * @param {Number} latitude The latitude at which to pick features.
  255. * @return {Promise} A promise for the picked features that will resolve when the asynchronous
  256. * picking completes. The resolved value is an array of {@link ImageryLayerFeatureInfo}
  257. * instances. The array may be empty if no features are found at the given location.
  258. * It may also be undefined if picking is not supported.
  259. *
  260. * @exception {DeveloperError} <code>pickFeatures</code> must not be called before the imagery provider is ready.
  261. */
  262. ImageryProvider.prototype.pickFeatures = DeveloperError.throwInstantiationError;
  263. /**
  264. * Loads an image from a given URL. If the server referenced by the URL already has
  265. * too many requests pending, this function will instead return undefined, indicating
  266. * that the request should be retried later.
  267. *
  268. * @param {String} url The URL of the image.
  269. * @returns {Promise} A promise for the image that will resolve when the image is available, or
  270. * undefined if there are too many active requests to the server, and the request
  271. * should be retried later. The resolved image may be either an
  272. * Image or a Canvas DOM object.
  273. */
  274. ImageryProvider.loadImage = function(imageryProvider, url) {
  275. if (defined(imageryProvider.tileDiscardPolicy)) {
  276. return throttleRequestByServer(url, loadImageViaBlob);
  277. }
  278. return throttleRequestByServer(url, loadImage);
  279. };
  280. return ImageryProvider;
  281. });