EllipsoidTerrainProvider.js 7.8 KB

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