From d7b3ce7ecf4693c8ea222ad7a39be50dd26ebb79 Mon Sep 17 00:00:00 2001 From: Petra Schanz Date: Wed, 11 Dec 2024 17:24:45 +0100 Subject: [PATCH] Bugfix: Link for shared maps without context If you use the share functionality in a map, that is not created out of a context, the shared link will not show the correct center and zoom, as long as the /config part in the URL is missing. As the documentations states in https://docs.mapstore.geosolutionsgroup.com/en/latest/developer-guide/map-query-parameters/#center-zoom and in https://docs.mapstore.geosolutionsgroup.com/en/latest/developer-guide/map-query-parameters/#marker-zoom that such a /config part should be part of configured URLs, this fix adds the /config part Test is adapted to the new solution. Bugfix on behalf of DB Systel GmbH --- .../resources/enhancers/__tests__/withShareTool-test.js | 6 +++--- web/client/components/share/SharePanel.jsx | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/web/client/components/resources/enhancers/__tests__/withShareTool-test.js b/web/client/components/resources/enhancers/__tests__/withShareTool-test.js index d8409f93b6..540b1c87ed 100644 --- a/web/client/components/resources/enhancers/__tests__/withShareTool-test.js +++ b/web/client/components/resources/enhancers/__tests__/withShareTool-test.js @@ -49,7 +49,7 @@ describe('withShareTool enhancer', () => { expect(sharePanel).toExist('Share panel doesn\'t exist'); const directLink = sharePanel.querySelector('#sharePanel-tabs-pane-1 .input-link input'); expect(directLink).toExist('directLink doesn\'t exist'); - expect(directLink.value).toBe(window.location.origin + window.location.pathname + "#/" + FAKE_RESOURCE_PATH); + expect(directLink.value).toBe(window.location.origin + window.location.pathname + "#/" + FAKE_RESOURCE_PATH + '/config'); }); it('URL is generated using application path', () => { const Sink = addSharePanel(createSink(() => {})); @@ -67,8 +67,8 @@ describe('withShareTool enhancer', () => { expect(sharePanel).toExist('Share panel doesn\'t exist'); const directLink = sharePanel.querySelector('#sharePanel-tabs-pane-1 .input-link input'); expect(directLink).toExist('directLink doesn\'t exist'); - expect(directLink.value).toBe(FAKE_RESOURCE_URL); - expect(directLink.value).toBe("http://some-location/mapstore/#/FAKE_RESOURCE_PATH"); // double check + expect(directLink.value).toBe(FAKE_RESOURCE_URL + '/config'); + expect(directLink.value).toBe("http://some-location/mapstore/#/FAKE_RESOURCE_PATH/config"); // double check document.getElementById('sharePanel-tabs-tab-3').click(); const codeBlock = document.getElementsByTagName('code')[0]; expect(codeBlock).toExist(); diff --git a/web/client/components/share/SharePanel.jsx b/web/client/components/share/SharePanel.jsx index 962faefefa..ef6cf25b50 100644 --- a/web/client/components/share/SharePanel.jsx +++ b/web/client/components/share/SharePanel.jsx @@ -214,6 +214,7 @@ class SharePanel extends React.Component { const { settings, advancedSettings, mapType, viewerOptions } = this.props; const shouldRemoveSectionId = !settings.showSectionId && advancedSettings && advancedSettings.sectionId; let shareUrl = getSharedGeostoryUrl(removeQueryFromUrl(this.props.shareUrl), shouldRemoveSectionId); + if (!shareUrl.endsWith('config')) shareUrl += `${!shareUrl.endsWith('/') ? '/' : ''}config`; if (settings.bboxEnabled && advancedSettings && advancedSettings.bbox && this.state.bbox) shareUrl = `${shareUrl}?bbox=${this.state.bbox}`; if (settings.showHome && advancedSettings && advancedSettings.homeButton) shareUrl = `${shareUrl}?showHome=true`; if (settings.centerAndZoomEnabled && advancedSettings && advancedSettings.centerAndZoom) {