From f5abb45de0f206f67b692325584e27383a7ac663 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Thu, 21 Mar 2019 09:52:33 +0100 Subject: [PATCH] Add a zDirection option for Zoomify Via zDirection, the renderer's selection of a tile source's resolution can be controlled if the view's resolution does not match any tile source resolution. Currently the zDirection option is only available for Zoomify. The comment https://github.com/openlayers/openlayers/issues/9343#issuecomment-474341033 describes why caution is advised when using zDirection for other sources. ol/source/Tile~TileSource#getZDirection has been added to avoid having the getZDirection method solely in the Zoomify source - just to document the possibility. --- src/ol/renderer/canvas/TileLayer.js | 3 ++- src/ol/source/Tile.js | 12 ++++++++++++ src/ol/source/Zoomify.js | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ol/renderer/canvas/TileLayer.js b/src/ol/renderer/canvas/TileLayer.js index cddca15d24..9c8c0b8692 100644 --- a/src/ol/renderer/canvas/TileLayer.js +++ b/src/ol/renderer/canvas/TileLayer.js @@ -143,7 +143,8 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer { const tileSource = tileLayer.getSource(); const sourceRevision = tileSource.getRevision(); const tileGrid = tileSource.getTileGridForProjection(projection); - const z = tileGrid.getZForResolution(viewResolution, this.zDirection); + const zDirection = tileSource.getZDirection() === undefined ? this.zDirection : tileSource.getZDirection(); + const z = tileGrid.getZForResolution(viewResolution, zDirection); const tileResolution = tileGrid.getResolution(z); let extent = frameState.extent; diff --git a/src/ol/source/Tile.js b/src/ol/source/Tile.js index 024a94ac46..0d2438ed06 100644 --- a/src/ol/source/Tile.js +++ b/src/ol/source/Tile.js @@ -326,6 +326,18 @@ class TileSource extends Source { */ useTile(z, x, y, projection) {} + /** + * Indicate which resolution should be used by a renderer if the views resolution + * does not match any resolution of the tile source. + * If 0, the nearest resolution will be used. If 1, the nearest lower resolution + * will be used. If -1, the nearest higher resolution will be used. If undefined, + * the decision is left to the renderer. + * @return {number|undefined} Prefered zDirection for source resolution selection. + */ + getZDirection() { + return undefined; + } + } diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index c4abdcc9f4..8d7c400729 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -111,6 +111,10 @@ export class CustomTile extends ImageTile { * @property {number} [transition] Duration of the opacity transition for rendering. * To disable the opacity transition, pass `transition: 0`. * @property {number} [tileSize=256] Tile size. Same tile size is used for all zoom levels. + * @property {number} [zDirection] Indicate which resolution should be used + * by a renderer if the views resolution does not match any resolution of the tile source. + * If 0, the nearest resolution will be used. If 1, the nearest lower resolution + * will be used. If -1, the nearest higher resolution will be used. */ @@ -253,6 +257,19 @@ class Zoomify extends TileImage { transition: options.transition }); + /** + * @protected + * @type {number|undefined} + */ + this.zDirection = options.zDirection; + + } + + /** + * @inheritDoc + */ + getZDirection() { + return this.zDirection; } }