From ee9f36af4525205930c5d576c5b8db32d26f1385 Mon Sep 17 00:00:00 2001 From: Suren Date: Wed, 17 May 2023 17:10:16 +0530 Subject: [PATCH] #8998: Fix - Layers with visibility scale limits do not print if useFixedScales configured (#9138) --- web/client/plugins/Print.jsx | 13 ++---- web/client/plugins/__tests__/Print-test.jsx | 44 +++++++++++++++++++-- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/web/client/plugins/Print.jsx b/web/client/plugins/Print.jsx index 264dd19242..54397645f9 100644 --- a/web/client/plugins/Print.jsx +++ b/web/client/plugins/Print.jsx @@ -379,7 +379,7 @@ export default { const map = this.props.printingService.getMapConfiguration(); return { ...map, - layers: this.filterLayers(map.layers, map.zoom, map.projection) + layers: this.filterLayers(map.layers, this.props.useFixedScales ? map.scaleZoom : map.zoom, map.projection) }; }; getMapSize = (layout) => { @@ -389,16 +389,11 @@ export default { height: currentLayout && currentLayout.map.height / currentLayout.map.width * this.props.mapWidth || 270 }; }; - getPreviewZoom = (mapZoom) => { - if (this.props.useFixedScales) { - const scales = getPrintScales(this.props.capabilities); - return getNearestZoom(mapZoom, scales); - } - return mapZoom; - }; getPreviewResolution = (zoom, projection) => { const dpu = dpi2dpu(DEFAULT_SCREEN_DPI, projection); - const scale = this.props.scales[this.getPreviewZoom(zoom)]; + const scale = this.props.useFixedScales + ? getPrintScales(this.props.capabilities)[zoom] + : this.props.scales[zoom]; return scale / dpu; }; getLayout = (props) => { diff --git a/web/client/plugins/__tests__/Print-test.jsx b/web/client/plugins/__tests__/Print-test.jsx index 7e8096f51d..6d4c1d829c 100644 --- a/web/client/plugins/__tests__/Print-test.jsx +++ b/web/client/plugins/__tests__/Print-test.jsx @@ -88,20 +88,20 @@ function expectDefaultItems() { expect(document.getElementById("mapstore-print-preview-panel")).toNotExist(); } -function getPrintPlugin({items = [], layers = [], preview = false, projection = "EPSG:3857"} = {}) { +function getPrintPlugin({items = [], layers = [], preview = false, projection = "EPSG:3857", state = initialState} = {}) { return getLazyPluginForTest({ plugin: Print, storeState: { - ...initialState, + ...state, browser: "good", layers, map: { - ...initialState.map, + ...state.map, projection }, print: { pdfUrl: preview ? "http://fakepreview" : undefined, - ...initialState.print, + ...state.print, map: { projection, center: {x: 0, y: 0}, @@ -405,4 +405,40 @@ describe('Print Plugin', () => { } }); }); + it("test configuration with useFixedScales and visibility limits on layer", (done) => { + const actions = { + onPrint: () => {} + }; + let spy = expect.spyOn(actions, "onPrint"); + getPrintPlugin({ + layers: [{visibility: true, type: "osm"}, {id: "test", url: "/test", name: "test", type: "wms", visibility: true, maxResolution: 500000}], + projection: "EPSG:4326", + state: {...initialState, + print: {...initialState.print, + capabilities: {...initialState.print.capabilities, + scales: [1000000, 500000, 100000].map(value => ({name: value, value}))} + }} + }).then(({ Plugin }) => { + try { + ReactDOM.render(, document.getElementById("container")); + const submit = document.getElementsByClassName("print-submit").item(0); + expect(submit).toExist(); + ReactTestUtils.Simulate.click(submit); + setTimeout(() => { + expect(spy.calls.length).toBe(1); + expect(spy.calls[0].arguments[1].layers.length).toBe(1); + expect(spy.calls[0].arguments[1].layers[0].layers).toEqual(["test"]); + done(); + }, 0); + } catch (ex) { + done(ex); + } + }); + }); });