智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import loadKTX2 from "../Core/loadKTX2.js";
  5. import Resource from "../Core/Resource.js";
  6. /**
  7. * @typedef {HTMLImageElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas} ImageryTypes
  8. *
  9. * The format in which {@link ImageryProvider} methods return an image may
  10. * vary by provider, configuration, or server settings. Most common are
  11. * <code>HTMLImageElement</code>, <code>HTMLCanvasElement</code>, or on supported
  12. * browsers, <code>ImageBitmap</code>.
  13. *
  14. * See the documentation for each ImageryProvider class for more information about how they return images.
  15. */
  16. /**
  17. * Provides imagery to be displayed on the surface of an ellipsoid. This type describes an
  18. * interface and is not intended to be instantiated directly.
  19. *
  20. * @alias ImageryProvider
  21. * @constructor
  22. * @abstract
  23. *
  24. * @see ArcGisMapServerImageryProvider
  25. * @see BingMapsImageryProvider
  26. * @see OpenStreetMapImageryProvider
  27. * @see TileMapServiceImageryProvider
  28. * @see GoogleEarthEnterpriseImageryProvider
  29. * @see GoogleEarthEnterpriseMapsProvider
  30. * @see GridImageryProvider
  31. * @see IonImageryProvider
  32. * @see MapboxImageryProvider
  33. * @see MapboxStyleImageryProvider
  34. * @see SingleTileImageryProvider
  35. * @see TileCoordinatesImageryProvider
  36. * @see UrlTemplateImageryProvider
  37. * @see WebMapServiceImageryProvider
  38. * @see WebMapTileServiceImageryProvider
  39. *
  40. * @demo {@link https://sandcastle.cesium.com/index.html?id=imagery-layers|Cesium Sandcastle Imagery Layers Demo}
  41. * @demo {@link https://sandcastle.cesium.com/index.html?id=imagery-layers-manipulation|Cesium Sandcastle Imagery Manipulation Demo}
  42. */
  43. function ImageryProvider() {
  44. DeveloperError.throwInstantiationError();
  45. }
  46. Object.defineProperties(ImageryProvider.prototype, {
  47. /**
  48. * Gets the rectangle, in radians, of the imagery provided by the instance.
  49. * @memberof ImageryProvider.prototype
  50. * @type {Rectangle}
  51. * @readonly
  52. */
  53. rectangle: {
  54. get: DeveloperError.throwInstantiationError,
  55. },
  56. /**
  57. * Gets the width of each tile, in pixels.
  58. * @memberof ImageryProvider.prototype
  59. * @type {number}
  60. * @readonly
  61. */
  62. tileWidth: {
  63. get: DeveloperError.throwInstantiationError,
  64. },
  65. /**
  66. * Gets the height of each tile, in pixels.
  67. * @memberof ImageryProvider.prototype
  68. * @type {number}
  69. * @readonly
  70. */
  71. tileHeight: {
  72. get: DeveloperError.throwInstantiationError,
  73. },
  74. /**
  75. * Gets the maximum level-of-detail that can be requested.
  76. * @memberof ImageryProvider.prototype
  77. * @type {number|undefined}
  78. * @readonly
  79. */
  80. maximumLevel: {
  81. get: DeveloperError.throwInstantiationError,
  82. },
  83. /**
  84. * Gets the minimum level-of-detail that can be requested. Generally,
  85. * a minimum level should only be used when the rectangle of the imagery is small
  86. * enough that the number of tiles at the minimum level is small. An imagery
  87. * provider with more than a few tiles at the minimum level will lead to
  88. * rendering problems.
  89. * @memberof ImageryProvider.prototype
  90. * @type {number}
  91. * @readonly
  92. */
  93. minimumLevel: {
  94. get: DeveloperError.throwInstantiationError,
  95. },
  96. /**
  97. * Gets the tiling scheme used by the provider.
  98. * @memberof ImageryProvider.prototype
  99. * @type {TilingScheme}
  100. * @readonly
  101. */
  102. tilingScheme: {
  103. get: DeveloperError.throwInstantiationError,
  104. },
  105. /**
  106. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  107. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  108. * returns undefined, no tiles are filtered.
  109. * @memberof ImageryProvider.prototype
  110. * @type {TileDiscardPolicy}
  111. * @readonly
  112. */
  113. tileDiscardPolicy: {
  114. get: DeveloperError.throwInstantiationError,
  115. },
  116. /**
  117. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  118. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  119. * are passed an instance of {@link TileProviderError}.
  120. * @memberof ImageryProvider.prototype
  121. * @type {Event}
  122. * @readonly
  123. */
  124. errorEvent: {
  125. get: DeveloperError.throwInstantiationError,
  126. },
  127. /**
  128. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  129. * the source of the imagery.
  130. * @memberof ImageryProvider.prototype
  131. * @type {Credit}
  132. * @readonly
  133. */
  134. credit: {
  135. get: DeveloperError.throwInstantiationError,
  136. },
  137. /**
  138. * Gets the proxy used by this provider.
  139. * @memberof ImageryProvider.prototype
  140. * @type {Proxy}
  141. * @readonly
  142. */
  143. proxy: {
  144. get: DeveloperError.throwInstantiationError,
  145. },
  146. /**
  147. * Gets a value indicating whether or not the images provided by this imagery provider
  148. * include an alpha channel. If this property is false, an alpha channel, if present, will
  149. * be ignored. If this property is true, any images without an alpha channel will be treated
  150. * as if their alpha is 1.0 everywhere. When this property is false, memory usage
  151. * and texture upload time are reduced.
  152. * @memberof ImageryProvider.prototype
  153. * @type {boolean}
  154. * @readonly
  155. */
  156. hasAlphaChannel: {
  157. get: DeveloperError.throwInstantiationError,
  158. },
  159. });
  160. /**
  161. * Gets the credits to be displayed when a given tile is displayed.
  162. *
  163. * @param {number} x The tile X coordinate.
  164. * @param {number} y The tile Y coordinate.
  165. * @param {number} level The tile level;
  166. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  167. */
  168. ImageryProvider.prototype.getTileCredits = function (x, y, level) {
  169. DeveloperError.throwInstantiationError();
  170. };
  171. /**
  172. * Requests the image for a given tile.
  173. *
  174. * @param {number} x The tile X coordinate.
  175. * @param {number} y The tile Y coordinate.
  176. * @param {number} level The tile level.
  177. * @param {Request} [request] The request object. Intended for internal use only.
  178. * @returns {Promise<ImageryTypes>|undefined} Returns a promise for the image that will resolve when the image is available, or
  179. * undefined if there are too many active requests to the server, and the request should be retried later.
  180. */
  181. ImageryProvider.prototype.requestImage = function (x, y, level, request) {
  182. DeveloperError.throwInstantiationError();
  183. };
  184. /**
  185. * Asynchronously determines what features, if any, are located at a given longitude and latitude within
  186. * a tile.
  187. * This function is optional, so it may not exist on all ImageryProviders.
  188. *
  189. * @function
  190. *
  191. * @param {number} x The tile X coordinate.
  192. * @param {number} y The tile Y coordinate.
  193. * @param {number} level The tile level.
  194. * @param {number} longitude The longitude at which to pick features.
  195. * @param {number} latitude The latitude at which to pick features.
  196. * @return {Promise<ImageryLayerFeatureInfo[]>|undefined} A promise for the picked features that will resolve when the asynchronous
  197. * picking completes. The resolved value is an array of {@link ImageryLayerFeatureInfo}
  198. * instances. The array may be empty if no features are found at the given location.
  199. * It may also be undefined if picking is not supported.
  200. *
  201. */
  202. ImageryProvider.prototype.pickFeatures = function (
  203. x,
  204. y,
  205. level,
  206. longitude,
  207. latitude,
  208. ) {
  209. DeveloperError.throwInstantiationError();
  210. };
  211. const ktx2Regex = /\.ktx2$/i;
  212. /**
  213. * Loads an image from a given URL. If the server referenced by the URL already has
  214. * too many requests pending, this function will instead return undefined, indicating
  215. * that the request should be retried later.
  216. *
  217. * @param {ImageryProvider} imageryProvider The imagery provider for the URL.
  218. * @param {Resource|string} url The URL of the image.
  219. * @returns {Promise<ImageryTypes|CompressedTextureBuffer>|undefined} A promise for the image that will resolve when the image is available, or
  220. * undefined if there are too many active requests to the server, and the request should be retried later.
  221. */
  222. ImageryProvider.loadImage = function (imageryProvider, url) {
  223. //>>includeStart('debug', pragmas.debug);
  224. Check.defined("url", url);
  225. //>>includeEnd('debug');
  226. const resource = Resource.createIfNeeded(url);
  227. if (ktx2Regex.test(resource.url)) {
  228. // Resolves with `CompressedTextureBuffer`
  229. return loadKTX2(resource);
  230. } else if (
  231. defined(imageryProvider) &&
  232. defined(imageryProvider.tileDiscardPolicy)
  233. ) {
  234. // Resolves with `HTMLImageElement` or `ImageBitmap`
  235. return resource.fetchImage({
  236. preferBlob: true,
  237. preferImageBitmap: true,
  238. flipY: true,
  239. });
  240. }
  241. return resource.fetchImage({
  242. preferImageBitmap: true,
  243. flipY: true,
  244. });
  245. };
  246. export default ImageryProvider;