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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import Check from "../Core/Check.js";
  2. import Event from "../Core/Event.js";
  3. import createWorldBathymetryAsync from "../Core/createWorldBathymetryAsync.js";
  4. import createWorldTerrainAsync from "../Core/createWorldTerrainAsync.js";
  5. /**
  6. * A helper to manage async operations of a terrain provider.
  7. *
  8. * @alias Terrain
  9. * @constructor
  10. *
  11. * @see Terrain.fromWorldTerrain
  12. * @see CesiumTerrainProvider
  13. * @see VRTheWorldTerrainProvider
  14. * @see GoogleEarthEnterpriseTerrainProvider
  15. *
  16. * @example
  17. * // Create
  18. * const viewer = new Cesium.Viewer("cesiumContainer", {
  19. * terrain: new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));
  20. * });
  21. *
  22. * @example
  23. * // Handle loading events
  24. * const terrain = new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));
  25. *
  26. * scene.setTerrain(terrain);
  27. *
  28. * terrain.readyEvent.addEventListener(provider => {
  29. * scene.globe.enableLighting = true;
  30. *
  31. * terrain.provider.errorEvent.addEventListener(error => {
  32. * alert(`Encountered an error while loading terrain tiles! ${error}`);
  33. * });
  34. * });
  35. *
  36. * terrain.errorEvent.addEventListener(error => {
  37. * alert(`Encountered an error while creating terrain! ${error}`);
  38. * });
  39. *
  40. * @param {Promise<TerrainProvider>} terrainProviderPromise A promise which resolves to a terrain provider
  41. */
  42. function Terrain(terrainProviderPromise) {
  43. //>>includeStart('debug', pragmas.debug);
  44. Check.typeOf.object("terrainProviderPromise", terrainProviderPromise);
  45. //>>includeEnd('debug');
  46. this._ready = false;
  47. this._provider = undefined;
  48. this._errorEvent = new Event();
  49. this._readyEvent = new Event();
  50. handlePromise(this, terrainProviderPromise);
  51. }
  52. Object.defineProperties(Terrain.prototype, {
  53. /**
  54. * Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing
  55. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  56. * are passed an instance of the thrown error.
  57. * @memberof Terrain.prototype
  58. * @type {Event<Terrain.ErrorEventCallback>}
  59. * @readonly
  60. */
  61. errorEvent: {
  62. get: function () {
  63. return this._errorEvent;
  64. },
  65. },
  66. /**
  67. * Gets an event that is raised when the terrain provider has been successfully created. Event listeners
  68. * are passed the created instance of {@link TerrainProvider}.
  69. * @memberof Terrain.prototype
  70. * @type {Event<Terrain.ReadyEventCallback>}
  71. * @readonly
  72. */
  73. readyEvent: {
  74. get: function () {
  75. return this._readyEvent;
  76. },
  77. },
  78. /**
  79. * Returns true when the terrain provider has been successfully created. Otherwise, returns false.
  80. * @memberof Terrain.prototype
  81. *
  82. * @type {boolean}
  83. * @readonly
  84. */
  85. ready: {
  86. get: function () {
  87. return this._ready;
  88. },
  89. },
  90. /**
  91. * The terrain provider providing surface geometry to a globe. Do not use until {@link Terrain.readyEvent} is raised.
  92. * @memberof Terrain.prototype
  93. *
  94. * @type {TerrainProvider}
  95. * @readonly
  96. */
  97. provider: {
  98. get: function () {
  99. return this._provider;
  100. },
  101. },
  102. });
  103. /**
  104. * Creates a {@link Terrain} instance for {@link https://cesium.com/content/#cesium-world-terrain|Cesium World Terrain}.
  105. *
  106. * @function
  107. *
  108. * @param {object} [options] Object with the following properties:
  109. * @param {boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server if available.
  110. * @param {boolean} [options.requestWaterMask=false] Flag that indicates if the client should request per tile water masks from the server if available.
  111. * @returns {Terrain} An asynchronous helper object for a CesiumTerrainProvider
  112. *
  113. * @see Ion
  114. * @see createWorldTerrainAsync
  115. *
  116. * @example
  117. * // Create Cesium World Terrain with default settings
  118. * const viewer = new Cesium.Viewer("cesiumContainer", {
  119. * terrain: Cesium.Terrain.fromWorldTerrain()
  120. * });
  121. *
  122. * @example
  123. * // Create Cesium World Terrain with water and normals.
  124. * const viewer1 = new Cesium.Viewer("cesiumContainer", {
  125. * terrain: Cesium.Terrain.fromWorldTerrain({
  126. * requestWaterMask: true,
  127. * requestVertexNormals: true
  128. * });
  129. * });
  130. *
  131. * @example
  132. * // Handle loading events
  133. * const terrain = Cesium.Terrain.fromWorldTerrain();
  134. *
  135. * scene.setTerrain(terrain);
  136. *
  137. * terrain.readyEvent.addEventListener(provider => {
  138. * scene.globe.enableLighting = true;
  139. *
  140. * terrain.provider.errorEvent.addEventListener(error => {
  141. * alert(`Encountered an error while loading terrain tiles! ${error}`);
  142. * });
  143. * });
  144. *
  145. * terrain.errorEvent.addEventListener(error => {
  146. * alert(`Encountered an error while creating terrain! ${error}`);
  147. * });
  148. */
  149. Terrain.fromWorldTerrain = function (options) {
  150. return new Terrain(createWorldTerrainAsync(options));
  151. };
  152. /**
  153. * Creates a {@link Terrain} instance for {@link https://cesium.com/content/#cesium-world-bathymetry|Cesium World Bathymetry}.
  154. *
  155. * @function
  156. *
  157. * @param {object} [options] Object with the following properties:
  158. * @param {boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server if available.
  159. * @returns {Terrain} An asynchronous helper object for a CesiumTerrainProvider
  160. *
  161. * @see Ion
  162. * @see createWorldBathymetryAsync
  163. *
  164. * @example
  165. * // Create Cesium World Bathymetry with default settings
  166. * const viewer = new Cesium.Viewer("cesiumContainer", {
  167. * terrain: Cesium.Terrain.fromWorldBathymetry)
  168. * });
  169. *
  170. * @example
  171. * // Create Cesium World Terrain with normals.
  172. * const viewer1 = new Cesium.Viewer("cesiumContainer", {
  173. * terrain: Cesium.Terrain.fromWorldBathymetry({
  174. * requestVertexNormals: true
  175. * });
  176. * });
  177. *
  178. * @example
  179. * // Handle loading events
  180. * const bathymetry = Cesium.Terrain.fromWorldBathymetry();
  181. *
  182. * scene.setTerrain(bathymetry);
  183. *
  184. * bathymetry.readyEvent.addEventListener(provider => {
  185. * scene.globe.enableLighting = true;
  186. *
  187. * bathymetry.provider.errorEvent.addEventListener(error => {
  188. * alert(`Encountered an error while loading bathymetric terrain tiles! ${error}`);
  189. * });
  190. * });
  191. *
  192. * bathymetry.errorEvent.addEventListener(error => {
  193. * alert(`Encountered an error while creating bathymetric terrain! ${error}`);
  194. * });
  195. */
  196. Terrain.fromWorldBathymetry = function (options) {
  197. return new Terrain(createWorldBathymetryAsync(options));
  198. };
  199. function handleError(errorEvent, error) {
  200. if (errorEvent.numberOfListeners > 0) {
  201. errorEvent.raiseEvent(error);
  202. } else {
  203. // Default handler is to log to the console
  204. console.error(error);
  205. }
  206. }
  207. async function handlePromise(instance, promise) {
  208. let provider;
  209. try {
  210. provider = await Promise.resolve(promise);
  211. instance._provider = provider;
  212. instance._ready = true;
  213. instance._readyEvent.raiseEvent(provider);
  214. } catch (error) {
  215. handleError(instance._errorEvent, error);
  216. }
  217. }
  218. export default Terrain;
  219. /**
  220. * A function that is called when an error occurs.
  221. * @callback Terrain.ErrorEventCallback
  222. *
  223. * @this Terrain
  224. * @param {Error} err An object holding details about the error that occurred.
  225. */
  226. /**
  227. * A function that is called when the provider has been created
  228. * @callback Terrain.ReadyEventCallback
  229. *
  230. * @this Terrain
  231. * @param {TerrainProvider} provider The created terrain provider.
  232. */