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