Skip to content

Commit

Permalink
Merge pull request #8616 from AnalyticalGraphicsInc/web-mercator-terr…
Browse files Browse the repository at this point in the history
…ain-tiling-scheme

In-repo version of jtfell's #8563
  • Loading branch information
kring authored Feb 18, 2020
2 parents e71d5b9 + 4dd1b5d commit ef95027
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change Log
* Added `Entity.tileset` for loading a 3D Tiles tileset via the Entity API using the new `Cesium3DTilesetGraphics` class.
* Added `tileset.uri`, `tileset.show`, and `tileset.maximumScreenSpaceError` properties to CZML processing for loading 3D Tiles.
* Added `Color.lerp` for linearly interpolating between two RGB colors. [#8607](https://github.com/AnalyticalGraphicsInc/cesium/pull/8607)
* `CesiumTerrainProvider` now supports terrain tiles using a `WebMercatorTilingScheme` by specifying `"projection": "EPSG:3857"` in `layer.json`. It also now supports numbering tiles from the North instead of the South by specifying `"scheme": "slippyMap"` in `layer.json`. [#8563](https://github.com/AnalyticalGraphicsInc/cesium/pull/8563)

##### Fixes :wrench:

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [André Borud](https://github.com/andreborud)
* [Nathan Schulte](https://github.com/nmschulte)
* [Jan Wąsak](https://github.com/jhnwsk)
* [Julian Fell](https://github.com/jtfell)
66 changes: 49 additions & 17 deletions Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import defineProperties from './defineProperties.js';
import DeveloperError from './DeveloperError.js';
import Event from './Event.js';
import GeographicTilingScheme from './GeographicTilingScheme.js';
import WebMercatorTilingScheme from './WebMercatorTilingScheme.js';
import getStringFromTypedArray from './getStringFromTypedArray.js';
import HeightmapTerrainData from './HeightmapTerrainData.js';
import IndexDatatype from './IndexDatatype.js';
Expand Down Expand Up @@ -72,18 +73,11 @@ import TileProviderError from './TileProviderError.js';
}
//>>includeEnd('debug');

this._tilingScheme = new GeographicTilingScheme({
numberOfLevelZeroTilesX : 2,
numberOfLevelZeroTilesY : 1,
ellipsoid : options.ellipsoid
});

this._heightmapWidth = 65;
this._levelZeroMaximumGeometricError = TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(this._tilingScheme.ellipsoid, this._heightmapWidth, this._tilingScheme.getNumberOfXTilesAtLevel(0));

this._heightmapStructure = undefined;
this._hasWaterMask = false;
this._hasVertexNormals = false;
this._ellipsoid = options.ellipsoid;

/**
* Boolean flag that indicates if the client should request vertex normals from the server.
Expand Down Expand Up @@ -198,6 +192,38 @@ import TileProviderError from './TileProviderError.js';
var maxZoom = data.maxzoom;
overallMaxZoom = Math.max(overallMaxZoom, maxZoom);
// Keeps track of which of the availablity containing tiles have been loaded

if (!data.projection || data.projection === 'EPSG:4326') {
that._tilingScheme = new GeographicTilingScheme({
numberOfLevelZeroTilesX : 2,
numberOfLevelZeroTilesY : 1,
ellipsoid : that._ellipsoid
});
} else if (data.projection === 'EPSG:3857') {
that._tilingScheme = new WebMercatorTilingScheme({
numberOfLevelZeroTilesX : 1,
numberOfLevelZeroTilesY : 1,
ellipsoid : that._ellipsoid
});
} else {
message = 'The projection "' + data.projection + '" is invalid or not supported.';
metadataError = TileProviderError.handleError(metadataError, that, that._errorEvent, message, undefined, undefined, undefined, requestLayerJson);
return;
}

that._levelZeroMaximumGeometricError = TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(
that._tilingScheme.ellipsoid,
that._heightmapWidth,
that._tilingScheme.getNumberOfXTilesAtLevel(0)
);
if (!data.scheme || data.scheme === 'tms' || data.scheme === 'slippyMap') {
that._scheme = data.scheme;
} else {
message = 'The scheme "' + data.scheme + '" is invalid or not supported.';
metadataError = TileProviderError.handleError(metadataError, that, that._errorEvent, message, undefined, undefined, undefined, requestLayerJson);
return;
}

var availabilityTilesLoaded;

// The vertex normals defined in the 'octvertexnormals' extension is identical to the original
Expand Down Expand Up @@ -402,7 +428,7 @@ import TileProviderError from './TileProviderError.js';
};
}

function createHeightmapTerrainData(provider, buffer, level, x, y, tmsY) {
function createHeightmapTerrainData(provider, buffer, level, x, y) {
var heightBuffer = new Uint16Array(buffer, 0, provider._heightmapWidth * provider._heightmapWidth);
return new HeightmapTerrainData({
buffer : heightBuffer,
Expand All @@ -415,7 +441,7 @@ import TileProviderError from './TileProviderError.js';
});
}

function createQuantizedMeshTerrainData(provider, buffer, level, x, y, tmsY, layer) {
function createQuantizedMeshTerrainData(provider, buffer, level, x, y, layer) {
var littleEndianExtensionSize = layer.littleEndianExtensionSize;
var pos = 0;
var cartesian3Elements = 3;
Expand Down Expand Up @@ -633,9 +659,14 @@ import TileProviderError from './TileProviderError.js';
return undefined;
}

var yTiles = provider._tilingScheme.getNumberOfYTilesAtLevel(level);

var tmsY = (yTiles - y - 1);
// The TileMapService scheme counts from the bottom left
var terrainY;
if (!provider._scheme || provider._scheme === 'tms') {
var yTiles = provider._tilingScheme.getNumberOfYTilesAtLevel(level);
terrainY = (yTiles - y - 1);
} else {
terrainY = y;
}

var extensionList = [];
if (provider._requestVertexNormals && layerToUse.hasVertexNormals) {
Expand All @@ -650,7 +681,8 @@ import TileProviderError from './TileProviderError.js';

var headers;
var query;
var url = urlTemplates[(x + tmsY + level) % urlTemplates.length];
var url = urlTemplates[(x + terrainY + level) % urlTemplates.length];

var resource = layerToUse.resource;
if (defined(resource._ionEndpoint) && !defined(resource._ionEndpoint.externalType)) {
// ion uses query paremeters to request extensions
Expand All @@ -669,7 +701,7 @@ import TileProviderError from './TileProviderError.js';
version: layerToUse.version,
z: level,
x: x,
y: tmsY
y: terrainY
},
queryParameters: query,
headers: headers,
Expand All @@ -682,9 +714,9 @@ import TileProviderError from './TileProviderError.js';

return promise.then(function (buffer) {
if (defined(provider._heightmapStructure)) {
return createHeightmapTerrainData(provider, buffer, level, x, y, tmsY);
return createHeightmapTerrainData(provider, buffer, level, x, y);
}
return createQuantizedMeshTerrainData(provider, buffer, level, x, y, tmsY, layerToUse);
return createQuantizedMeshTerrainData(provider, buffer, level, x, y, layerToUse);
});
}

Expand Down
12 changes: 9 additions & 3 deletions Specs/Core/CesiumTerrainProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,19 @@ describe('Core/CesiumTerrainProvider', function() {
});

it('returns reasonable geometric error for various levels', function() {
returnQuantizedMeshTileJson();

var provider = new CesiumTerrainProvider({
url : 'made/up/url'
});

expect(provider.getLevelMaximumGeometricError(0)).toBeGreaterThan(0.0);
expect(provider.getLevelMaximumGeometricError(0)).toEqualEpsilon(provider.getLevelMaximumGeometricError(1) * 2.0, CesiumMath.EPSILON10);
expect(provider.getLevelMaximumGeometricError(1)).toEqualEpsilon(provider.getLevelMaximumGeometricError(2) * 2.0, CesiumMath.EPSILON10);
return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.getLevelMaximumGeometricError(0)).toBeGreaterThan(0.0);
expect(provider.getLevelMaximumGeometricError(0)).toEqualEpsilon(provider.getLevelMaximumGeometricError(1) * 2.0, CesiumMath.EPSILON10);
expect(provider.getLevelMaximumGeometricError(1)).toEqualEpsilon(provider.getLevelMaximumGeometricError(2) * 2.0, CesiumMath.EPSILON10);
});
});

it('logo is undefined if credit is not provided', function() {
Expand Down

0 comments on commit ef95027

Please sign in to comment.