EllipsoidTerrainProvider.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import defaultValue from "./defaultValue.js";
  2. import defined from "./defined.js";
  3. import deprecationWarning from "./deprecationWarning.js";
  4. import Ellipsoid from "./Ellipsoid.js";
  5. import Event from "./Event.js";
  6. import GeographicTilingScheme from "./GeographicTilingScheme.js";
  7. import HeightmapTerrainData from "./HeightmapTerrainData.js";
  8. import TerrainProvider from "./TerrainProvider.js";
  9. /**
  10. * A very simple {@link TerrainProvider} that produces geometry by tessellating an ellipsoidal
  11. * surface.
  12. *
  13. * @alias EllipsoidTerrainProvider
  14. * @constructor
  15. *
  16. * @param {object} [options] Object with the following properties:
  17. * @param {TilingScheme} [options.tilingScheme] The tiling scheme specifying how the ellipsoidal
  18. * surface is broken into tiles. If this parameter is not provided, a {@link GeographicTilingScheme}
  19. * is used.
  20. * @param {Ellipsoid} [options.ellipsoid] The ellipsoid. If the tilingScheme is specified,
  21. * this parameter is ignored and the tiling scheme's ellipsoid is used instead. If neither
  22. * parameter is specified, the WGS84 ellipsoid is used.
  23. *
  24. * @see TerrainProvider
  25. */
  26. function EllipsoidTerrainProvider(options) {
  27. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  28. this._tilingScheme = options.tilingScheme;
  29. if (!defined(this._tilingScheme)) {
  30. this._tilingScheme = new GeographicTilingScheme({
  31. ellipsoid: defaultValue(options.ellipsoid, Ellipsoid.WGS84),
  32. });
  33. }
  34. // Note: the 64 below does NOT need to match the actual vertex dimensions, because
  35. // the ellipsoid is significantly smoother than actual terrain.
  36. this._levelZeroMaximumGeometricError = TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(
  37. this._tilingScheme.ellipsoid,
  38. 64,
  39. this._tilingScheme.getNumberOfXTilesAtLevel(0)
  40. );
  41. this._errorEvent = new Event();
  42. this._ready = true;
  43. this._readyPromise = Promise.resolve(true);
  44. }
  45. Object.defineProperties(EllipsoidTerrainProvider.prototype, {
  46. /**
  47. * Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing
  48. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  49. * are passed an instance of {@link TileProviderError}.
  50. * @memberof EllipsoidTerrainProvider.prototype
  51. * @type {Event}
  52. * @readonly
  53. */
  54. errorEvent: {
  55. get: function () {
  56. return this._errorEvent;
  57. },
  58. },
  59. /**
  60. * Gets the credit to display when this terrain provider is active. Typically this is used to credit
  61. * the source of the terrain.
  62. * @memberof EllipsoidTerrainProvider.prototype
  63. * @type {Credit}
  64. * @readonly
  65. */
  66. credit: {
  67. get: function () {
  68. return undefined;
  69. },
  70. },
  71. /**
  72. * Gets the tiling scheme used by this provider.
  73. * @memberof EllipsoidTerrainProvider.prototype
  74. * @type {GeographicTilingScheme}
  75. * @readonly
  76. */
  77. tilingScheme: {
  78. get: function () {
  79. return this._tilingScheme;
  80. },
  81. },
  82. /**
  83. * Gets a value indicating whether or not the provider is ready for use.
  84. * @memberof EllipsoidTerrainProvider.prototype
  85. * @type {boolean}
  86. * @readonly
  87. * @deprecated
  88. */
  89. ready: {
  90. get: function () {
  91. deprecationWarning(
  92. "EllipsoidTerrainProvider.ready",
  93. "EllipsoidTerrainProvider.ready was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107."
  94. );
  95. return true;
  96. },
  97. },
  98. /**
  99. * Gets a promise that resolves to true when the provider is ready for use.
  100. * @memberof EllipsoidTerrainProvider.prototype
  101. * @type {Promise<boolean>}
  102. * @readonly
  103. * @deprecated
  104. */
  105. readyPromise: {
  106. get: function () {
  107. deprecationWarning(
  108. "EllipsoidTerrainProvider.readyPromise",
  109. "EllipsoidTerrainProvider.readyPromise was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107."
  110. );
  111. return this._readyPromise;
  112. },
  113. },
  114. /**
  115. * Gets a value indicating whether or not the provider includes a water mask. The water mask
  116. * indicates which areas of the globe are water rather than land, so they can be rendered
  117. * as a reflective surface with animated waves.
  118. * @memberof EllipsoidTerrainProvider.prototype
  119. * @type {boolean}
  120. * @readonly
  121. */
  122. hasWaterMask: {
  123. get: function () {
  124. return false;
  125. },
  126. },
  127. /**
  128. * Gets a value indicating whether or not the requested tiles include vertex normals.
  129. * @memberof EllipsoidTerrainProvider.prototype
  130. * @type {boolean}
  131. * @readonly
  132. */
  133. hasVertexNormals: {
  134. get: function () {
  135. return false;
  136. },
  137. },
  138. /**
  139. * Gets an object that can be used to determine availability of terrain from this provider, such as
  140. * at points and in rectangles. This property may be undefined if availability
  141. * information is not available.
  142. * @memberof EllipsoidTerrainProvider.prototype
  143. * @type {TileAvailability}
  144. * @readonly
  145. */
  146. availability: {
  147. get: function () {
  148. return undefined;
  149. },
  150. },
  151. });
  152. /**
  153. * Requests the geometry for a given tile. The result includes terrain
  154. * data and indicates that all child tiles are available.
  155. *
  156. * @param {number} x The X coordinate of the tile for which to request geometry.
  157. * @param {number} y The Y coordinate of the tile for which to request geometry.
  158. * @param {number} level The level of the tile for which to request geometry.
  159. * @param {Request} [request] The request object. Intended for internal use only.
  160. *
  161. * @returns {Promise<TerrainData>|undefined} A promise for the requested geometry. If this method
  162. * returns undefined instead of a promise, it is an indication that too many requests are already
  163. * pending and the request will be retried later.
  164. */
  165. EllipsoidTerrainProvider.prototype.requestTileGeometry = function (
  166. x,
  167. y,
  168. level,
  169. request
  170. ) {
  171. const width = 16;
  172. const height = 16;
  173. return Promise.resolve(
  174. new HeightmapTerrainData({
  175. buffer: new Uint8Array(width * height),
  176. width: width,
  177. height: height,
  178. })
  179. );
  180. };
  181. /**
  182. * Gets the maximum geometric error allowed in a tile at a given level.
  183. *
  184. * @param {number} level The tile level for which to get the maximum geometric error.
  185. * @returns {number} The maximum geometric error.
  186. */
  187. EllipsoidTerrainProvider.prototype.getLevelMaximumGeometricError = function (
  188. level
  189. ) {
  190. return this._levelZeroMaximumGeometricError / (1 << level);
  191. };
  192. /**
  193. * Determines whether data for a tile is available to be loaded.
  194. *
  195. * @param {number} x The X coordinate of the tile for which to request geometry.
  196. * @param {number} y The Y coordinate of the tile for which to request geometry.
  197. * @param {number} level The level of the tile for which to request geometry.
  198. * @returns {boolean|undefined} Undefined if not supported, otherwise true or false.
  199. */
  200. EllipsoidTerrainProvider.prototype.getTileDataAvailable = function (
  201. x,
  202. y,
  203. level
  204. ) {
  205. return undefined;
  206. };
  207. /**
  208. * Makes sure we load availability data for a tile
  209. *
  210. * @param {number} x The X coordinate of the tile for which to request geometry.
  211. * @param {number} y The Y coordinate of the tile for which to request geometry.
  212. * @param {number} level The level of the tile for which to request geometry.
  213. * @returns {undefined} This provider does not support loading availability.
  214. */
  215. EllipsoidTerrainProvider.prototype.loadTileDataAvailability = function (
  216. x,
  217. y,
  218. level
  219. ) {
  220. return undefined;
  221. };
  222. export default EllipsoidTerrainProvider;