Additional types for WebGL renderer, sources, and tiles

This commit is contained in:
Tim Schaub
2021-10-30 12:06:22 -06:00
parent 71020bb5e4
commit f336cf30b0
8 changed files with 69 additions and 28 deletions

View File

@@ -185,7 +185,11 @@ class Tile extends EventTarget {
}
let tile = this.interimTile;
let prev = /** @type {Tile} */ (this);
/**
* @type {Tile}
*/
let prev = this;
do {
if (tile.getState() == TileState.LOADED) {

View File

@@ -14,6 +14,10 @@ import {
} from '../style/expressions.js';
import {assign} from '../obj.js';
/**
* @typedef {import("../source/DataTile.js").default|import("../source/TileImage.js").default} SourceType
*/
/**
* @typedef {Object} Style
* Translates tile data to rendered pixels.
@@ -57,7 +61,7 @@ import {assign} from '../obj.js';
* be visible.
* @property {number} [preload=0] Preload. Load low-resolution tiles up to `preload` levels. `0`
* means no preloading.
* @property {import("../source/Tile.js").default} [source] Source for this layer.
* @property {SourceType} [source] Source for this layer.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
@@ -255,7 +259,7 @@ function parseStyle(style, bandCount) {
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @extends BaseTileLayer<import("../source/DataTile.js").default|import("../source/TileImage.js").default>
* @extends BaseTileLayer<SourceType>
* @api
*/
class WebGLTileLayer extends BaseTileLayer {

View File

@@ -51,6 +51,7 @@ export const WebGLWorkerMessageType = {
* Base WebGL renderer class.
* Holds all logic related to data manipulation & some common rendering logic
* @template {import("../../layer/Layer.js").default} LayerType
* @extends {LayerRenderer<LayerType>}
*/
class WebGLLayerRenderer extends LayerRenderer {
/**

View File

@@ -56,6 +56,9 @@ const attributeDescriptions = [
},
];
/**
* @type {Object<string, boolean>}
*/
const empty = {};
/**
@@ -69,7 +72,7 @@ function depthForZ(z) {
/**
* Add a tile texture to the lookup.
* @param {Object<string, Array<import("../../webgl/TileTexture.js").default>>} tileTexturesByZ Lookup of
* @param {Object<number, Array<import("../../webgl/TileTexture.js").default>>} tileTexturesByZ Lookup of
* tile textures by zoom level.
* @param {import("../../webgl/TileTexture.js").default} tileTexture A tile texture.
* @param {number} z The zoom level.
@@ -106,14 +109,19 @@ function getRenderExtent(frameState, extent) {
* @property {number} [cacheSize=512] The texture cache size.
*/
/**
* @typedef {import("../../layer/WebGLTile.js").default} LayerType
*/
/**
* @classdesc
* WebGL renderer for tile layers.
* @extends {WebGLLayerRenderer<LayerType>}
* @api
*/
class WebGLTileLayerRenderer extends WebGLLayerRenderer {
/**
* @param {import("../../layer/WebGLTile.js").default} tileLayer Tile layer.
* @param {LayerType} tileLayer Tile layer.
* @param {Options} options Options.
*/
constructor(tileLayer, options) {
@@ -207,11 +215,11 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
}
/**
* @protected
* @param {import("../../Tile.js").default} tile Tile.
* @param {import("../../webgl/TileTexture").TileType} tile Tile.
* @return {boolean} Tile is drawable.
* @private
*/
isDrawableTile(tile) {
isDrawableTile_(tile) {
const tileLayer = this.getLayer();
const tileState = tile.getState();
const useInterimTilesOnError = tileLayer.getUseInterimTilesOnError();
@@ -238,6 +246,12 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
return source.getState() === State.READY;
}
/**
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
* @param {import("../../extent.js").Extent} extent The extent.
* @param {number} z The zoom level.
* @param {Object<number, Array<TileTexture>>} tileTexturesByZ The zoom level.
*/
enqueueTiles(frameState, extent, z, tileTexturesByZ) {
const viewState = frameState.viewState;
const tileLayer = this.getLayer();
@@ -260,7 +274,16 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
const tileCoord = createTileCoord(z, x, y, this.tempTileCoord_);
const tileCoordKey = getTileCoordKey(tileCoord);
let tileTexture, tile;
/**
* @type {TileTexture}
*/
let tileTexture;
/**
* @type {import("../../webgl/TileTexture").TileType}
*/
let tile;
if (tileTextureCache.containsKey(tileCoordKey)) {
tileTexture = tileTextureCache.get(tileCoordKey);
tile = tileTexture.tile;
@@ -277,9 +300,15 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
tileTexture = new TileTexture(tile, tileGrid, this.helper);
tileTextureCache.set(tileCoordKey, tileTexture);
} else {
tileTexture.setTile(
this.isDrawableTile(tile) ? tile : tile.getInterimTile()
);
if (this.isDrawableTile_(tile)) {
tileTexture.setTile(tile);
} else {
const interimTile =
/** @type {import("../../webgl/TileTexture").TileType} */ (
tile.getInterimTile()
);
tileTexture.setTile(interimTile);
}
}
}
@@ -322,7 +351,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
);
/**
* @type {Object<string, Array<import("../../webgl/TileTexture.js").default>>}
* @type {Object<number, Array<import("../../webgl/TileTexture.js").default>>}
*/
const tileTexturesByZ = {};
@@ -381,7 +410,8 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
}
// next look for parent tiles
for (let parentZ = z - 1; parentZ >= tileGrid.minZoom; --parentZ) {
const minZoom = tileGrid.getMinZoom();
for (let parentZ = z - 1; parentZ >= minZoom; --parentZ) {
const coveredByParent = this.findAltTiles_(
tileGrid,
tileCoord,
@@ -527,7 +557,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
* @param {import("../../tilegrid/TileGrid.js").default} tileGrid The tile grid.
* @param {import("../../tilecoord.js").TileCoord} tileCoord The target tile coordinate.
* @param {number} altZ The alternate zoom level.
* @param {Object<string, Array<import("../../webgl/TileTexture.js").default>>} tileTexturesByZ Lookup of
* @param {Object<number, Array<import("../../webgl/TileTexture.js").default>>} tileTexturesByZ Lookup of
* tile textures by zoom level.
* @return {boolean} The tile coordinate is covered by loaded tiles at the alternate zoom level.
* @private

View File

@@ -202,7 +202,6 @@ class TileSource extends Source {
/**
* Return the key to be used for all tiles in the source.
* @return {string} The key for all tiles.
* @protected
*/
getKey() {
return this.key_;

View File

@@ -210,7 +210,6 @@ class TileImage extends UrlTile {
/**
* Return the key to be used for all tiles in the source.
* @return {string} The key for all tiles.
* @protected
*/
getKey() {
return (
@@ -286,7 +285,7 @@ class TileImage extends UrlTile {
* @param {number} pixelRatio Pixel ratio.
* @param {import("../proj/Projection.js").default} projection Projection.
* @param {string} key The key set on the tile.
* @return {!import("../Tile.js").default} Tile.
* @return {!ImageTile} Tile.
* @private
*/
createTile_(z, x, y, pixelRatio, projection, key) {
@@ -317,7 +316,7 @@ class TileImage extends UrlTile {
* @param {number} y Tile coordinate y.
* @param {number} pixelRatio Pixel ratio.
* @param {import("../proj/Projection.js").default} projection Projection.
* @return {!import("../Tile.js").default} Tile.
* @return {!(ImageTile|ReprojTile)} Tile.
*/
getTile(z, x, y, pixelRatio, projection) {
const sourceProjection = this.getProjection();
@@ -388,7 +387,7 @@ class TileImage extends UrlTile {
* @param {number} y Tile coordinate y.
* @param {number} pixelRatio Pixel ratio.
* @param {!import("../proj/Projection.js").default} projection Projection.
* @return {!import("../Tile.js").default} Tile.
* @return {!(ImageTile|ReprojTile)} Tile.
* @protected
*/
getTileInternal(z, x, y, pixelRatio, projection) {

View File

@@ -86,9 +86,13 @@ function uploadDataTexture(helper, texture, data, size, bandCount) {
);
}
/**
* @typedef {import("../DataTile.js").default|ImageTile|ReprojTile} TileType
*/
class TileTexture extends EventTarget {
/**
* @param {import("../DataTile.js").default|import("../ImageTile.js").default} tile The tile.
* @param {TileType} tile The tile.
* @param {import("../tilegrid/TileGrid.js").default} grid Tile grid.
* @param {import("../webgl/Helper.js").default} helper WebGL helper.
*/
@@ -96,7 +100,7 @@ class TileTexture extends EventTarget {
super();
/**
* @type {import("../DataTile.js").default|import("../ImageTile.js").default}
* @type {TileType}
*/
this.tile;
@@ -130,7 +134,7 @@ class TileTexture extends EventTarget {
}
/**
* @param {import("../DataTile.js").default|import("../ImageTile.js").default} tile Tile.
* @param {TileType} tile Tile.
*/
setTile(tile) {
if (tile !== this.tile) {

View File

@@ -85,19 +85,19 @@ describe('ol/renderer/webgl/TileLayer', function () {
expect(renderer.tileTextureCache_.count_).to.be(1);
});
it('#isDrawableTile()', function (done) {
it('#isDrawableTile_()', function (done) {
const tile = tileLayer.getSource().getTile(0, 0, 0);
expect(renderer.isDrawableTile(tile)).to.be(false);
expect(renderer.isDrawableTile_(tile)).to.be(false);
tileLayer.getSource().on('tileloadend', () => {
expect(renderer.isDrawableTile(tile)).to.be(true);
expect(renderer.isDrawableTile_(tile)).to.be(true);
done();
});
tile.load();
const errorTile = tileLayer.getSource().getTile(1, 0, 1);
errorTile.setState(TileState.ERROR);
tileLayer.setUseInterimTilesOnError(false);
expect(renderer.isDrawableTile(errorTile)).to.be(true);
expect(renderer.isDrawableTile_(errorTile)).to.be(true);
tileLayer.setUseInterimTilesOnError(true);
expect(renderer.isDrawableTile(errorTile)).to.be(false);
expect(renderer.isDrawableTile_(errorTile)).to.be(false);
});
});