diff --git a/assets/src/index.js b/assets/src/index.js index 51e354442b..4994b81ac1 100644 --- a/assets/src/index.js +++ b/assets/src/index.js @@ -275,7 +275,9 @@ const initLizmapApp = () => { } // end waiting, does not depend on ongoing asynchronous actions - lizMap.waitEnd(startupConfigurations?.getFeatureInfo); + // startupFeatures is passed so highlights are re-applied after displayGetFeatureInfo clears them, + // even when the call is deferred until popup is initialized + lizMap.waitEnd(startupConfigurations?.getFeatureInfo, startupConfigurations?.startupFeatures); return; }, 'lizmap.class.loaded'); diff --git a/assets/src/legacy/map.js b/assets/src/legacy/map.js index 749868ab92..fcf69d5ea6 100644 --- a/assets/src/legacy/map.js +++ b/assets/src/legacy/map.js @@ -3651,19 +3651,32 @@ window.lizMap = function() { * Wait end leads to interface modifications * Removes waiter and display getFeatureInfo, if requested * @param {Object} getFeatureInfo + * @param {Object} [startupFeatures] - GeoJSON startup features to re-highlight after popup display * @returns {void} */ - waitEnd: (getFeatureInfo)=>{ + waitEnd: (getFeatureInfo, startupFeatures)=>{ $('body').css('cursor', 'auto'); $('#loading').dialog('close'); // Display getFeatureInfo if requested if(getFeatureInfo){ - displayGetFeatureInfo(getFeatureInfo, - { - x: map.size.w / 2, - y: map.size.h / 2 - }); + const showGetFeatureInfo = () => { + displayGetFeatureInfo(getFeatureInfo, + { + x: map.size.w / 2, + y: map.size.h / 2 + }); + // Re-apply startup highlights cleared by popup display + if (startupFeatures) { + lizMap.mainLizmap.map.setHighlightFeatures(startupFeatures, "geojson"); + } + }; + // popup is initialized after layers load — defer if not ready yet + if (lizMap.mainLizmap?.popup) { + showGetFeatureInfo(); + } else { + lizMap.mainEventDispatcher.subscribe(showGetFeatureInfo, 'lizmap.modules.initialized'); + } } }, /** diff --git a/tests/end2end/playwright/startup.spec.js b/tests/end2end/playwright/startup.spec.js index b1e68fb92d..90aefb0c3a 100644 --- a/tests/end2end/playwright/startup.spec.js +++ b/tests/end2end/playwright/startup.spec.js @@ -41,6 +41,27 @@ test.describe('Startup', () => { await expect(page.locator('#lizmap-startup-features-error-message')).toHaveCount(1); }); + test('Zoom to features extent and show popup with popup=true', async ({ page }) => { + const project = new ProjectPage(page, 'startup'); + const getFeatureInfoPromise = project.waitForGetFeatureInfoRequest(); + await project.openWithExtraParams({ + 'layer': 'sousquartiers', + 'filter': '"quartmno" = \'PA\' OR "quartmno" = \'HO\'', + 'popup': 'true', + }); + + // Wait for the GetFeatureInfo request triggered by popup=true + const getFeatureInfoRequest = await getFeatureInfoPromise; + const postData = getFeatureInfoRequest.postData() ?? ''; + expect(postData).toContain('GetFeatureInfo'); + expect(postData).toContain('sousquartiers'); + + // The popup dock must be visible with feature content + await expect(project.popupContent).toBeVisible(); + const singleFeatures = await project.getPopupSingleFeatures(); + await expect(singleFeatures).not.toHaveCount(0); + }); + test('Projects with dot or space can load', async ({ page }) => { let project = new ProjectPage(page, 'base_layers with space'); await project.open();