EllipsoidTerrainProvider.js 7.3 KB

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