From d4f7a27cf042a3b96a82e3031e7c33039af3cf75 Mon Sep 17 00:00:00 2001 From: Frauke Fritz <42568257+FraukeF@users.noreply.github.com> Date: Thu, 9 Jul 2020 15:48:31 +0200 Subject: [PATCH] (HARP-11087): Evaluate Tiles from removed DataSources as not visible (#1676) Signed-off-by: Frauke Fritz --- @here/harp-mapview/lib/Tile.ts | 10 +++++++++- @here/harp-mapview/test/TileTest.ts | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/@here/harp-mapview/lib/Tile.ts b/@here/harp-mapview/lib/Tile.ts index 312adfb0d5..f1d2a4abd7 100644 --- a/@here/harp-mapview/lib/Tile.ts +++ b/@here/harp-mapview/lib/Tile.ts @@ -367,7 +367,15 @@ export class Tile implements CachedResource { // This happens in order to prevent that, during VisibleTileSet visibility evaluation, // visible tiles that haven't yet been evaluated for the current frame are preemptively // removed from [[DataSourceCache]]. - return this.frameNumLastRequested >= this.dataSource.mapView.frameNumber - 1; + // There is cases when a tile was already removed from the MapView, i.e. the PolaCaps + // Datasource might get remove on a change of projection, in this case + // this.dataSource.mapView will throw an error + try { + return this.frameNumLastRequested >= this.dataSource.mapView.frameNumber - 1; + } catch (error) { + logger.debug(error); + return false; + } } set isVisible(visible: boolean) { diff --git a/@here/harp-mapview/test/TileTest.ts b/@here/harp-mapview/test/TileTest.ts index f79f170959..11642979fe 100644 --- a/@here/harp-mapview/test/TileTest.ts +++ b/@here/harp-mapview/test/TileTest.ts @@ -41,7 +41,10 @@ function createFakeTextElement(): TextElement { describe("Tile", function() { const tileKey = TileKey.fromRowColumnLevel(0, 0, 0); const stubDataSource = new TileTestStubDataSource({ name: "test-data-source" }); - const mapView = { projection: mercatorProjection }; + const mapView = { + projection: mercatorProjection, + frameNumber: 0 + }; stubDataSource.attach(mapView as MapView); it("set empty decoded tile forces hasGeometry to be true", function() { @@ -256,4 +259,15 @@ describe("Tile", function() { expect(tile.geoBox).deep.equals(expectedGeoBox); expect(tile.boundingBox).deep.equals(expectedBBox); }); + + it("doesnt throw on isVisble if not attached to a MapView", function() { + const tile = new Tile(stubDataSource, tileKey); + mapView.frameNumber = 2; + tile.frameNumLastRequested = 2; + expect(tile.isVisible).not.throw; + expect(tile.isVisible).is.true; + stubDataSource.detach(mapView as MapView); + expect(tile.isVisible).not.throw; + expect(tile.isVisible).is.false; + }); });