From 792e15124d7503a7d212c58911dd99d776dbcdc5 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sun, 23 Aug 2020 12:37:52 +0200 Subject: [PATCH 1/2] VectorTile source projection has to match the view projection --- doc/errors/index.md | 6 +++++- src/ol/renderer/canvas/VectorTileLayer.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/errors/index.md b/doc/errors/index.md index e45f47bd3b..58c85f79ff 100644 --- a/doc/errors/index.md +++ b/doc/errors/index.md @@ -248,4 +248,8 @@ This is done by providing adequate shaders using the `hitVertexShader` and `hitF ### 67 -A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both. \ No newline at end of file +A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both. + +### 68 + +A VectorTile source can only be rendered if it has a projection compatible with the view projection. \ No newline at end of file diff --git a/src/ol/renderer/canvas/VectorTileLayer.js b/src/ol/renderer/canvas/VectorTileLayer.js index 80d88dfc0c..ab53ca17c5 100644 --- a/src/ol/renderer/canvas/VectorTileLayer.js +++ b/src/ol/renderer/canvas/VectorTileLayer.js @@ -20,6 +20,7 @@ import { scale as scaleTransform, translate as translateTransform, } from '../../transform.js'; +import {assert} from '../../asserts.js'; import { buffer, containsCoordinate, @@ -34,6 +35,7 @@ import { createHitDetectionImageData, hitDetect, } from '../../render/canvas/hitdetect.js'; +import {equivalent} from '../../proj.js'; import { getSquaredTolerance as getSquaredRenderTolerance, renderFeature, @@ -230,7 +232,15 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer { * @return {boolean} Layer is ready to be rendered. */ prepareFrame(frameState) { - const layerRevision = this.getLayer().getRevision(); + const layer = this.getLayer(); + assert( + equivalent( + layer.getSource().getProjection(), + frameState.viewState.projection + ), + 68 // A VectorTile source can only be rendered if it has a projection compatible with the view projection. + ); + const layerRevision = layer.getRevision(); if (this.renderedLayerRevision_ != layerRevision) { this.renderedTiles.length = 0; } From 6f0eec632f65a53e455ea249191c4c0f5c483894 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sun, 23 Aug 2020 18:20:10 +0200 Subject: [PATCH 2/2] Use existing check for assertion --- doc/errors/index.md | 2 +- src/ol/renderer/canvas/VectorTileLayer.js | 12 +----------- src/ol/source/Tile.js | 12 ++++++------ 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/doc/errors/index.md b/doc/errors/index.md index 58c85f79ff..646a6a33b5 100644 --- a/doc/errors/index.md +++ b/doc/errors/index.md @@ -252,4 +252,4 @@ A layer can only be added to the map once. Use either `layer.setMap()` or `map.a ### 68 -A VectorTile source can only be rendered if it has a projection compatible with the view projection. \ No newline at end of file +Data from this source can only be rendered if it has a projection compatible with the view projection. \ No newline at end of file diff --git a/src/ol/renderer/canvas/VectorTileLayer.js b/src/ol/renderer/canvas/VectorTileLayer.js index ab53ca17c5..80d88dfc0c 100644 --- a/src/ol/renderer/canvas/VectorTileLayer.js +++ b/src/ol/renderer/canvas/VectorTileLayer.js @@ -20,7 +20,6 @@ import { scale as scaleTransform, translate as translateTransform, } from '../../transform.js'; -import {assert} from '../../asserts.js'; import { buffer, containsCoordinate, @@ -35,7 +34,6 @@ import { createHitDetectionImageData, hitDetect, } from '../../render/canvas/hitdetect.js'; -import {equivalent} from '../../proj.js'; import { getSquaredTolerance as getSquaredRenderTolerance, renderFeature, @@ -232,15 +230,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer { * @return {boolean} Layer is ready to be rendered. */ prepareFrame(frameState) { - const layer = this.getLayer(); - assert( - equivalent( - layer.getSource().getProjection(), - frameState.viewState.projection - ), - 68 // A VectorTile source can only be rendered if it has a projection compatible with the view projection. - ); - const layerRevision = layer.getRevision(); + const layerRevision = this.getLayer().getRevision(); if (this.renderedLayerRevision_ != layerRevision) { this.renderedTiles.length = 0; } diff --git a/src/ol/source/Tile.js b/src/ol/source/Tile.js index 6f21a948cb..36d0080f8e 100644 --- a/src/ol/source/Tile.js +++ b/src/ol/source/Tile.js @@ -6,6 +6,7 @@ import Source from './Source.js'; import TileCache from '../TileCache.js'; import TileState from '../TileState.js'; import {abstract} from '../util.js'; +import {assert} from '../asserts.js'; import {equivalent} from '../proj.js'; import {getKeyZXY, withinExtentAndZ} from '../tilecoord.js'; import { @@ -250,12 +251,11 @@ class TileSource extends Source { * @protected */ getTileCacheForProjection(projection) { - const thisProj = this.getProjection(); - if (thisProj && !equivalent(thisProj, projection)) { - return null; - } else { - return this.tileCache; - } + assert( + equivalent(this.getProjection(), projection), + 68 // A VectorTile source can only be rendered if it has a projection compatible with the view projection. + ); + return this.tileCache; } /**