From ebb68d610e5a8c7e35e5e56a6fe2b9637b1e1b7c Mon Sep 17 00:00:00 2001 From: Mattia Pezzotti <45800507+mattiapezzotti@users.noreply.github.com> Date: Sat, 3 Aug 2024 21:08:57 +0200 Subject: [PATCH] Fix panoramax non existing inaccurate sequence (#10375) fixes #10365 --- modules/services/panoramax.js | 23 ++++++++++++++--------- modules/svg/panoramax_images.js | 2 +- test/spec/services/panoramax.js | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/services/panoramax.js b/modules/services/panoramax.js index 59d437185..b4457d7fa 100644 --- a/modules/services/panoramax.js +++ b/modules/services/panoramax.js @@ -74,18 +74,18 @@ function searchLimited(limit, projection, rtree) { } // Load all data for the specified type from Panoramax vector tiles -function loadTiles(which, url, maxZoom, projection) { +function loadTiles(which, url, maxZoom, projection, zoom) { const tiler = utilTiler().zoomExtent([minZoom, maxZoom]).skipNullIsland(true); const tiles = tiler.getTiles(projection); tiles.forEach(function(tile) { - loadTile(which, url, tile); + loadTile(which, url, tile, zoom); }); } // Load all data for the specified type from one vector tile -function loadTile(which, url, tile) { +function loadTile(which, url, tile, zoom) { const cache = _cache.requests; const tileId = `${tile.id}-${which}`; if (cache.loaded[tileId] || cache.inflight[tileId]) return; @@ -109,7 +109,7 @@ function loadTile(which, url, tile) { throw new Error('No Data'); } - loadTileDataToCache(data, tile, which); + loadTileDataToCache(data, tile, zoom); if (which === 'images') { dispatch.call('loadedImages'); @@ -126,7 +126,7 @@ function loadTile(which, url, tile) { }); } -function loadTileDataToCache(data, tile) { +function loadTileDataToCache(data, tile, zoom) { const vectorTile = new VectorTile(new Protobuf(data)); let features, @@ -177,7 +177,11 @@ function loadTileDataToCache(data, tile) { } if (vectorTile.layers.hasOwnProperty(sequenceLayer)) { + cache = _cache.sequences; + + if (zoom >= lineMinZoom && zoom < imageMinZoom) cache = _cache.mockSequences; + layer = vectorTile.layers[sequenceLayer]; for (i = 0; i < layer.length; i++) { @@ -238,6 +242,7 @@ export default { _cache = { images: { rtree: new RBush(), forImageId: {} }, sequences: { rtree: new RBush(), lineString: {} }, + mockSequences: { rtree: new RBush(), lineString: {} }, requests: { loaded: {}, inflight: {} } }; @@ -261,8 +266,8 @@ export default { }, // Load line in the visible area - loadLines: function(projection) { - loadTiles('line', tileUrl, lineMinZoom, projection); + loadLines: function(projection, zoom) { + loadTiles('line', tileUrl, lineMinZoom, projection, zoom); }, getUserIds: async function(usernames) { @@ -308,8 +313,8 @@ export default { return lineStrings; } if (zoom >= lineMinZoom){ - Object.keys(_cache.sequences.lineString).forEach(function(sequenceId) { - lineStrings = lineStrings.concat(_cache.sequences.lineString[sequenceId]); + Object.keys(_cache.mockSequences.lineString).forEach(function(sequenceId) { + lineStrings = lineStrings.concat(_cache.mockSequences.lineString[sequenceId]); }); } return lineStrings; diff --git a/modules/svg/panoramax_images.js b/modules/svg/panoramax_images.js index 56313ff1a..7ef876210 100644 --- a/modules/svg/panoramax_images.js +++ b/modules/svg/panoramax_images.js @@ -345,7 +345,7 @@ export function svgPanoramaxImages(projection, context, dispatch) { } else if (zoom >= lineMinZoom) { editOn(); update(); - service.loadLines(projection); + service.loadLines(projection, zoom); } else { editOff(); } diff --git a/test/spec/services/panoramax.js b/test/spec/services/panoramax.js index 24c7176f2..e41850904 100644 --- a/test/spec/services/panoramax.js +++ b/test/spec/services/panoramax.js @@ -96,7 +96,7 @@ describe('iD.servicePanoramax', function() { panoramax.cache().images.rtree.load(features); panoramax.cache().sequences.lineString['100'] = { rotation: 0, images: [ features[0].data, features[1].data, features[2].data ] }; - var res = panoramax.sequences(context.projection, 14); + var res = panoramax.sequences(context.projection, 15); expect(res).to.deep.eql([{ rotation: 0, images: [features[0].data, features[1].data, features[2].data] }]);