diff --git a/map/src/map/layers/PoiLayer.js b/map/src/map/layers/PoiLayer.js index 312a016d5..0abcf63c6 100644 --- a/map/src/map/layers/PoiLayer.js +++ b/map/src/map/layers/PoiLayer.js @@ -467,7 +467,6 @@ export default function PoiLayer() { const getPoiTask = async ({ controller, - ignore, poiList, showPoiCategories, poiIconCache, @@ -508,6 +507,7 @@ export default function PoiLayer() { map, zoom, }); + if (reqId !== reqIdRef.current || ignore) return; const nextState = { layer: newLayer, listFeatures, info: res.info ?? poiList?.info }; updateLayerOnMap(nextState); setPoiList(nextState); @@ -532,40 +532,40 @@ export default function PoiLayer() { hideMarkersNearPin(map, ctx); async function getPoiList() { + if (isEmpty(ctx.showPoiCategories)) { + // if categories are cleared, then clear the list and related states + reqIdRef.current += 1; + setPrevCategories(null); + if (poiList) { + clearPoiList(); + } + return; + } const isTypeChange = typesChanged(); const categoriesChanged = !prevCategories || JSON.stringify(prevCategories.map((c) => c.category).sort()) !== JSON.stringify(ctx.showPoiCategories.map((c) => c.category).sort()); - if ((!isEmpty(ctx.showPoiCategories) && zoom !== prevZoom) || move || isTypeChange) { + if (zoom !== prevZoom || move || isTypeChange) { if (prevController) { prevController.abort(); } setPrevController(controller); setPrevZoom(zoom); - if (ctx.showPoiCategories.length > 0) { - if (categoriesChanged) { - setPrevCategories(null); - } - reqIdRef.current += 1; - const runGetPoi = categoriesChanged || isTypeChange ? getPoiTask : debouncedGetPoi; - runGetPoi({ - controller, - ignore, - poiList: categoriesChanged ? null : poiList, - showPoiCategories: ctx.showPoiCategories, - poiIconCache: ctx.poiIconCache, - zoom, - reqId: reqIdRef.current, - visibleBboxInfo: getVisibleBboxInfo(ctx, map), - }); - } - } else if (isEmpty(ctx.showPoiCategories)) { - // if categories are cleared, then clear the list and related states - setPrevCategories(null); - if (poiList) { - clearPoiList(); + if (categoriesChanged) { + setPrevCategories(null); } + reqIdRef.current += 1; + const runGetPoi = categoriesChanged || isTypeChange ? getPoiTask : debouncedGetPoi; + runGetPoi({ + controller, + poiList: categoriesChanged ? null : poiList, + showPoiCategories: ctx.showPoiCategories, + poiIconCache: ctx.poiIconCache, + zoom, + reqId: reqIdRef.current, + visibleBboxInfo: getVisibleBboxInfo(ctx, map), + }); } else if (poiList?.listFeatures?.features?.length > 0) { // same categories, no zoom/move change: re-render the existing pois without a new request const newLayer = await createPoiLayer({ diff --git a/tests/selenium/src/tests/search/91-poi-markers-test.mjs b/tests/selenium/src/tests/search/91-poi-markers-test.mjs index fbbac277e..ceeab4821 100644 --- a/tests/selenium/src/tests/search/91-poi-markers-test.mjs +++ b/tests/selenium/src/tests/search/91-poi-markers-test.mjs @@ -19,7 +19,19 @@ export default async function test() { await clickBy(By.id('se-show-menu-configuremap')); await waitBy(By.id('se-configure-map-menu-name')); - // open POI categories + // enable POI overlay + await togglePoiCategory(category); + await actionCheckPoi({ iconWpt, name: poiName }); + + // disable POI overlay: markers must disappear without page reload + await togglePoiCategory(category); + await actionCheckPoi({ iconWpt, name: poiName, hidden: true }); + + await actionFinish(); +} + +// open POI categories from the opened configure map, switch the category over and apply +async function togglePoiCategory(category) { await waitBy(By.id('se-configure-map-menu-poi-categories')); await clickBy(By.id('se-configure-map-menu-poi-categories')); @@ -27,7 +39,5 @@ export default async function test() { await clickBy(By.id(`se-poi-category-${category}`)); await clickBy(By.id('se-select-categories')); - await actionCheckPoi({ iconWpt, name: poiName }); - - await actionFinish(); + await waitBy(By.id('se-configure-map-menu-name')); }