From 4297d51c26186385755c7dab5331a97a0889e878 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 16 Apr 2018 15:43:27 -0400 Subject: [PATCH] add `handleWrapJump` tests (fixup) --- test/unit/source/source_cache.test.js | 26 +++++++++++++++++++++ test/unit/symbol/cross_tile_symbol_index.js | 21 +++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/test/unit/source/source_cache.test.js b/test/unit/source/source_cache.test.js index f35cdfa7c95..02c297dbcca 100644 --- a/test/unit/source/source_cache.test.js +++ b/test/unit/source/source_cache.test.js @@ -706,6 +706,32 @@ test('SourceCache#update', (t) => { sourceCache.onAdd(); }); + t.test('reassigns tiles for large jumps in longitude', (t) => { + + const transform = new Transform(); + transform.resize(511, 511); + transform.zoom = 0; + + const sourceCache = createSourceCache({}); + sourceCache.on('data', (e) => { + if (e.sourceDataType === 'metadata') { + transform.center = new LngLat(360, 0); + const tileID = new OverscaledTileID(0, 1, 0, 0, 0); + sourceCache.update(transform); + t.deepEqual(sourceCache.getIds(), [tileID.key]); + const tile = sourceCache.getTile(tileID); + + transform.center = new LngLat(0, 0); + const wrappedTileID = new OverscaledTileID(0, 0, 0, 0, 0); + sourceCache.update(transform); + t.deepEqual(sourceCache.getIds(), [wrappedTileID.key]); + t.equal(sourceCache.getTile(wrappedTileID), tile); + t.end(); + } + }); + sourceCache.onAdd(); + }); + t.end(); }); diff --git a/test/unit/symbol/cross_tile_symbol_index.js b/test/unit/symbol/cross_tile_symbol_index.js index 7876bdadab9..429e77dac10 100644 --- a/test/unit/symbol/cross_tile_symbol_index.js +++ b/test/unit/symbol/cross_tile_symbol_index.js @@ -192,6 +192,27 @@ test('CrossTileSymbolIndex.addLayer', (t) => { t.end(); }); + t.test('reuses indexes when longitude is wrapped', (t) => { + const index = new CrossTileSymbolIndex(); + const longitude = 370; + + const tileID = new OverscaledTileID(6, 1, 6, 8, 8); + const firstInstances = [ + makeSymbolInstance(1000, 1000, ""), // A + ]; + const tile = makeTile(tileID, firstInstances); + + index.addLayer(styleLayer, [tile], longitude); + t.equal(firstInstances[0].crossTileID, 1); // A + + tile.tileID = tileID.wrapped(); + + index.addLayer(styleLayer, [tile], longitude % 360); + t.equal(firstInstances[0].crossTileID, 1); + t.end(); + + }); + t.end(); });