EllipsoidTerrainProvider.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import when from "../ThirdParty/when.js";
  2. import defaultValue from "./defaultValue.js";
  3. import defined from "./defined.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._readyPromise = when.resolve(true);
  43. }
  44. Object.defineProperties(EllipsoidTerrainProvider.prototype, {
  45. /**
  46. * Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing
  47. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  48. * are passed an instance of {@link TileProviderError}.
  49. * @memberof EllipsoidTerrainProvider.prototype
  50. * @type {Event}
  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. */
  63. credit: {
  64. get: function () {
  65. return undefined;
  66. },
  67. },
  68. /**
  69. * Gets the tiling scheme used by this provider. This function should
  70. * not be called before {@link EllipsoidTerrainProvider#ready} returns true.
  71. * @memberof EllipsoidTerrainProvider.prototype
  72. * @type {GeographicTilingScheme}
  73. */
  74. tilingScheme: {
  75. get: function () {
  76. return this._tilingScheme;
  77. },
  78. },
  79. /**
  80. * Gets a value indicating whether or not the provider is ready for use.
  81. * @memberof EllipsoidTerrainProvider.prototype
  82. * @type {Boolean}
  83. */
  84. ready: {
  85. get: function () {
  86. return true;
  87. },
  88. },
  89. /**
  90. * Gets a promise that resolves to true when the provider is ready for use.
  91. * @memberof EllipsoidTerrainProvider.prototype
  92. * @type {Promise.<Boolean>}
  93. * @readonly
  94. */
  95. readyPromise: {
  96. get: function () {
  97. return this._readyPromise;
  98. },
  99. },
  100. /**
  101. * Gets a value indicating whether or not the provider includes a water mask. The water mask
  102. * indicates which areas of the globe are water rather than land, so they can be rendered
  103. * as a reflective surface with animated waves. This function should not be
  104. * called before {@link EllipsoidTerrainProvider#ready} returns true.
  105. * @memberof EllipsoidTerrainProvider.prototype
  106. * @type {Boolean}
  107. */
  108. hasWaterMask: {
  109. get: function () {
  110. return false;
  111. },
  112. },
  113. /**
  114. * Gets a value indicating whether or not the requested tiles include vertex normals.
  115. * This function should not be called before {@link EllipsoidTerrainProvider#ready} returns true.
  116. * @memberof EllipsoidTerrainProvider.prototype
  117. * @type {Boolean}
  118. */
  119. hasVertexNormals: {
  120. get: function () {
  121. return false;
  122. },
  123. },
  124. /**
  125. * Gets an object that can be used to determine availability of terrain from this provider, such as
  126. * at points and in rectangles. This function should not be called before
  127. * {@link TerrainProvider#ready} returns true. This property may be undefined if availability
  128. * information is not available.
  129. * @memberof EllipsoidTerrainProvider.prototype
  130. * @type {TileAvailability}
  131. */
  132. availability: {
  133. get: function () {
  134. return undefined;
  135. },
  136. },
  137. });
  138. /**
  139. * Requests the geometry for a given tile. This function should not be called before
  140. * {@link TerrainProvider#ready} returns true. The result includes terrain
  141. * data and indicates that all child tiles are available.
  142. *
  143. * @param {Number} x The X coordinate of the tile for which to request geometry.
  144. * @param {Number} y The Y coordinate of the tile for which to request geometry.
  145. * @param {Number} level The level of the tile for which to request geometry.
  146. * @param {Request} [request] The request object. Intended for internal use only.
  147. *
  148. * @returns {Promise.<TerrainData>|undefined} A promise for the requested geometry. If this method
  149. * returns undefined instead of a promise, it is an indication that too many requests are already
  150. * pending and the request will be retried later.
  151. */
  152. EllipsoidTerrainProvider.prototype.requestTileGeometry = function (
  153. x,
  154. y,
  155. level,
  156. request
  157. ) {
  158. var width = 16;
  159. var height = 16;
  160. return when.resolve(
  161. new HeightmapTerrainData({
  162. buffer: new Uint8Array(width * height),
  163. width: width,
  164. height: height,
  165. })
  166. );
  167. };
  168. /**
  169. * Gets the maximum geometric error allowed in a tile at a given level.
  170. *
  171. * @param {Number} level The tile level for which to get the maximum geometric error.
  172. * @returns {Number} The maximum geometric error.
  173. */
  174. EllipsoidTerrainProvider.prototype.getLevelMaximumGeometricError = function (
  175. level
  176. ) {
  177. return this._levelZeroMaximumGeometricError / (1 << level);
  178. };
  179. /**
  180. * Determines whether data for a tile is available to be loaded.
  181. *
  182. * @param {Number} x The X coordinate of the tile for which to request geometry.
  183. * @param {Number} y The Y coordinate of the tile for which to request geometry.
  184. * @param {Number} level The level of the tile for which to request geometry.
  185. * @returns {Boolean} Undefined if not supported, otherwise true or false.
  186. */
  187. EllipsoidTerrainProvider.prototype.getTileDataAvailable = function (
  188. x,
  189. y,
  190. level
  191. ) {
  192. return undefined;
  193. };
  194. /**
  195. * Makes sure we load availability data for a tile
  196. *
  197. * @param {Number} x The X coordinate of the tile for which to request geometry.
  198. * @param {Number} y The Y coordinate of the tile for which to request geometry.
  199. * @param {Number} level The level of the tile for which to request geometry.
  200. * @returns {undefined|Promise<void>} Undefined if nothing need to be loaded or a Promise that resolves when all required tiles are loaded
  201. */
  202. EllipsoidTerrainProvider.prototype.loadTileDataAvailability = function (
  203. x,
  204. y,
  205. level
  206. ) {
  207. return undefined;
  208. };
  209. export default EllipsoidTerrainProvider;