From f5abb45de0f206f67b692325584e27383a7ac663 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Thu, 21 Mar 2019 09:52:33 +0100 Subject: [PATCH 1/4] 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; } } From 2bf217207e37a82f4547dd9522db72f087b69744 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Thu, 21 Mar 2019 11:51:42 +0100 Subject: [PATCH 2/4] Test renderer behavior for Zoomify zDirection The zDirection addition to the Zoomify tile source only takes effect through the renderer, so these two renderer cases are added to test the behavior. zoomify-no-zdirection expects the default behavior. zoomify-zdirection expects the tiles for the next better resolution. --- .../cases/zoomify-no-zdirection/expected.png | Bin 0 -> 778 bytes rendering/cases/zoomify-no-zdirection/main.js | 25 +++++++++++++++++ .../cases/zoomify-zdirection/expected.png | Bin 0 -> 801 bytes rendering/cases/zoomify-zdirection/main.js | 26 ++++++++++++++++++ .../data/tiles/zoomify/TileGroup0/0-0-0.jpg | Bin 0 -> 733 bytes .../data/tiles/zoomify/TileGroup0/1-0-0.jpg | Bin 0 -> 670 bytes .../data/tiles/zoomify/TileGroup0/1-0-1.jpg | Bin 0 -> 734 bytes .../data/tiles/zoomify/TileGroup0/1-1-0.jpg | Bin 0 -> 670 bytes .../data/tiles/zoomify/TileGroup0/1-1-1.jpg | Bin 0 -> 669 bytes 9 files changed, 51 insertions(+) create mode 100644 rendering/cases/zoomify-no-zdirection/expected.png create mode 100644 rendering/cases/zoomify-no-zdirection/main.js create mode 100644 rendering/cases/zoomify-zdirection/expected.png create mode 100644 rendering/cases/zoomify-zdirection/main.js create mode 100644 rendering/data/tiles/zoomify/TileGroup0/0-0-0.jpg create mode 100644 rendering/data/tiles/zoomify/TileGroup0/1-0-0.jpg create mode 100644 rendering/data/tiles/zoomify/TileGroup0/1-0-1.jpg create mode 100644 rendering/data/tiles/zoomify/TileGroup0/1-1-0.jpg create mode 100644 rendering/data/tiles/zoomify/TileGroup0/1-1-1.jpg diff --git a/rendering/cases/zoomify-no-zdirection/expected.png b/rendering/cases/zoomify-no-zdirection/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..599dd1ea74d9a9729a16e3e16ce6edb1fd5c4e27 GIT binary patch literal 778 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6&6GJC5?=1xi$!3N`lsM<-=BDPA0J#hd&PAz- zC8;S2<(VZJ3hti10V#T^>J@=W@1YU|t6?>E*?`#*u3ijDz$in{)D0ESc#RYQzCNB%e- jBFVgCaKxSf!-G)%U`g(u&jepZ4u$WME?8U{GLa0Q!d-3<^#9ur&AX z;{7@Ho|l#^Q()+>JX8GhY5e3f^PYTA3}N{5e|m{Tn>lrZ5fmL1#mu>x+f3OCn5h=8 ikn}-rQfZj~i@`ftymp$p>O5f5W$<+Mb6Mw<&;$U1G;fOl literal 0 HcmV?d00001 diff --git a/rendering/cases/zoomify-zdirection/main.js b/rendering/cases/zoomify-zdirection/main.js new file mode 100644 index 0000000000..9a854dae6a --- /dev/null +++ b/rendering/cases/zoomify-zdirection/main.js @@ -0,0 +1,26 @@ +import Map from '../../../src/ol/Map.js'; +import View from '../../../src/ol/View.js'; +import TileLayer from '../../../src/ol/layer/Tile.js'; +import Zoomify from '../../../src/ol/source/Zoomify.js'; + +const layer = new TileLayer({ + source: new Zoomify({ + url: '/data/tiles/zoomify/', + size: [200, 200], + tileSize: 100, + zDirection: -1 + }) +}); + +new Map({ + layers: [layer], + target: 'map', + view: new View({ + resolutions: [2, 1], + extent: [0, -200, 200, 0], + center: [100, -100], + zoom: 0.4 + }) +}); + +render(); diff --git a/rendering/data/tiles/zoomify/TileGroup0/0-0-0.jpg b/rendering/data/tiles/zoomify/TileGroup0/0-0-0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..384ca04dca7a11935e12ec16803293468e8f2b10 GIT binary patch literal 733 zcmc(bO-{ow5QX2^ag)Yzuv@!yS(ZIT7L^J`LgETYsRTQODzW5D9Doht5d3U731+Mc zq#zp96>nx^`?H_l#OL@9d%9dLK}0y=Lj1sZakIYItlQb`)#h?`ygECNZ&*MIk(!lp zt3s(PQ)QkHimI$CU21LWku|lewYC%M#y*5l9UM+4eme5Or$X*;FrDvz(IBtckd0eUd^-SfRyckJWsPn&DDDcGEpm?yyf r4oISg`T+3_?6ep(TZ^3lHAnNW)Q}v|M*MU2PsIK;kuA^@n1Pp1gyW2B literal 0 HcmV?d00001 diff --git a/rendering/data/tiles/zoomify/TileGroup0/1-0-0.jpg b/rendering/data/tiles/zoomify/TileGroup0/1-0-0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..70c233194ac7571978b52b4fb404b5b0a5a13bb5 GIT binary patch literal 670 zcmbu4O-chn5QSfLPft42J!5y$GiGO8<`lCCL?Z;ef-nKyi3B`?SMV4fLBvD&v+*Rh zH3WqOlMwQ{HeGyGuU>qMUvL+b=>$ZCbAE{5=#TH_SBrTwyuVpo56`Bv%lL^gq!4Yf z5-z2cN)nZII;pmqwI(wrFM2L7d|`~MobQLSEbYz wiBSvq{{cx<(>6f-0UIsSdTFr{p!#(5n;Meyaqxq5vLlh(m1qfUIhcX>ADoCyrvLx| literal 0 HcmV?d00001 diff --git a/rendering/data/tiles/zoomify/TileGroup0/1-0-1.jpg b/rendering/data/tiles/zoomify/TileGroup0/1-0-1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bf9daae993fc1b607d73d8a03449e40520bed4ce GIT binary patch literal 734 zcmc(b!AiqG5QhKR%_eC!Nq5`b*ke8RDRL;ZRw(!iLJE2lDfk+md?4{5)LuOL6s{AB zLW_;`)S0>L@Xh@DPk0R^+^%oN^TqNiY%qlsqAiYy zOQlLhk;;-JPV+3!b*6Pu4op$nQfpHgJ9OUryni;T+-TsuYnPDZnMn1N>bXJ}?&t{5 zuqhfek}QNJX(_zG^Z&6M3AZbDwbzf+@Qz#(gpmfIr_asf?%=VnJ_|XsCxbhdNm-nf vn6!ZX8<0dbbphfRI4BXt0|3i literal 0 HcmV?d00001 diff --git a/rendering/data/tiles/zoomify/TileGroup0/1-1-0.jpg b/rendering/data/tiles/zoomify/TileGroup0/1-1-0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..dad6e34193b99929c3523d9c64b622fb21e63f54 GIT binary patch literal 670 zcmbu4QAz_b5QhIrHrsTwyC!Y2_OU+p6#G!9RuH^`umyb(L<*k5b9e$hfOrVC4|)>g zEJdNkwiN%&ONMXepFh6FPuSDRbOIv62|vUy^vAcei}|b>-d)WvhsV>i^SHnmQi!%# z3767JC5g&9omA&po}0{=qU_nCbfq!2vaat#2>HR`pz?#B558SOl4latRjTU?Q~13V zpW!qbG?E;IBk3r4aouR;`-@7^|2$7-IZtwY&n>Lw{ObAcb5PF literal 0 HcmV?d00001 diff --git a/rendering/data/tiles/zoomify/TileGroup0/1-1-1.jpg b/rendering/data/tiles/zoomify/TileGroup0/1-1-1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..948eaec38b5ebc00843aa014341aa16cca9cee64 GIT binary patch literal 669 zcmbu4K}rKL6o%hRCNtAXW_)Rr+GSn#6tgI_wovd2!W48Nh!k9U6mKD}Mequ0H=e}! zLQxp8EyX|oCdrrl?+>rx186>(O#l($loy0g=#6id=c{EiyuDmq45zcjSy;muq!7`p zgspO=l0+3*mgc4~Mi*L_RhP=jR$5b^Y|nY`&C&6o?*?7xUHk+kze!X_sg5gk=?+$S z0-HkvjYJE=qO=&E!SnpkRvM3EtG2T64n`sfk_3SFk1y@}gLgIOIQkuP%`rKLqY|SC v*uMdZSmQ20`~X`c(s~oI6~Ovr^xYaH7o@9)^?!V~rxERIv;lSu%)r|hz*u)= literal 0 HcmV?d00001 From 085c60af49f17751476ee42b51ca72d0ace6efa3 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Thu, 21 Mar 2019 14:47:09 +0100 Subject: [PATCH 3/4] Remove tile source zDirection getter The renderer now accesses the zDirection member directly if it exists. This also has the advantage of not advertising any object methods that hav no use for most tile sources. --- src/ol/renderer/canvas/TileLayer.js | 2 +- src/ol/source/Tile.js | 12 ------------ src/ol/source/Zoomify.js | 8 -------- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/ol/renderer/canvas/TileLayer.js b/src/ol/renderer/canvas/TileLayer.js index 9c8c0b8692..1fda4b016f 100644 --- a/src/ol/renderer/canvas/TileLayer.js +++ b/src/ol/renderer/canvas/TileLayer.js @@ -143,7 +143,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer { const tileSource = tileLayer.getSource(); const sourceRevision = tileSource.getRevision(); const tileGrid = tileSource.getTileGridForProjection(projection); - const zDirection = tileSource.getZDirection() === undefined ? this.zDirection : tileSource.getZDirection(); + const zDirection = tileSource.zDirection === undefined ? this.zDirection : tileSource.zDirection; 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 0d2438ed06..024a94ac46 100644 --- a/src/ol/source/Tile.js +++ b/src/ol/source/Tile.js @@ -326,18 +326,6 @@ 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 8d7c400729..a3a997062e 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -258,20 +258,12 @@ class Zoomify extends TileImage { }); /** - * @protected * @type {number|undefined} */ this.zDirection = options.zDirection; } - /** - * @inheritDoc - */ - getZDirection() { - return this.zDirection; - } - } export default Zoomify; From 681c3169c12d5a072457d10565d771cbe14414a3 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 21 Mar 2019 18:50:03 +0100 Subject: [PATCH 4/4] Add zDirection memeber to the baes class, for type checking --- src/ol/source/Tile.js | 8 ++++++++ src/ol/source/Zoomify.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ol/source/Tile.js b/src/ol/source/Tile.js index 024a94ac46..0d66af54b8 100644 --- a/src/ol/source/Tile.js +++ b/src/ol/source/Tile.js @@ -105,6 +105,14 @@ class TileSource extends Source { */ this.tileOptions = {transition: options.transition}; + /** + * zDirection hint, read by the renderer. Indicates 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. + * @type {number=} + */ + this.zDirection; } /** diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index a3a997062e..4baefa3bba 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -258,7 +258,7 @@ class Zoomify extends TileImage { }); /** - * @type {number|undefined} + * @inheritDoc */ this.zDirection = options.zDirection;