From 15186518677735894841c075743bf4c8314de385 Mon Sep 17 00:00:00 2001 From: Suren Date: Mon, 8 Jan 2024 19:21:47 +0530 Subject: [PATCH] #9823: Fix - [Annotations] Disabled annotations are printed (#9837) --- web/client/plugins/Print.jsx | 5 ++- web/client/plugins/__tests__/Print-test.jsx | 37 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/web/client/plugins/Print.jsx b/web/client/plugins/Print.jsx index 937c75c5c4..08e96b629d 100644 --- a/web/client/plugins/Print.jsx +++ b/web/client/plugins/Print.jsx @@ -544,6 +544,9 @@ export default { .filter(layer => layer.group === "background" && layer.visibility && this.isAllowed(layer, projection))); return !background; }; + filterAnnotationFeaturesByVisibility = (layer) => { + return {...layer, ...(!isNil(layer.features) ? {features: layer.features?.filter(ft => ft?.properties?.visibility)} : {})}; + } filterLayers = (layers, zoom, projection) => { const resolution = this.getPreviewResolution(zoom, projection); @@ -551,7 +554,7 @@ export default { layer.visibility && isInsideResolutionsLimits(layer, resolution) && this.isAllowed(layer, projection) - ); + ).map(this.filterAnnotationFeaturesByVisibility); if (this.isBackgroundIgnored(layers, projection) && this.props.defaultBackground && this.props.printSpec.defaultBackground) { const defaultBackground = this.getAlternativeBackground(layers, this.props.defaultBackground); if (defaultBackground) { diff --git a/web/client/plugins/__tests__/Print-test.jsx b/web/client/plugins/__tests__/Print-test.jsx index 64453b0f14..caaa77e98d 100644 --- a/web/client/plugins/__tests__/Print-test.jsx +++ b/web/client/plugins/__tests__/Print-test.jsx @@ -483,4 +483,41 @@ describe('Print Plugin', () => { } }); }); + it("print only annotation features that are visible", (done) => { + const layers = [{ + features: [ + {type: "FeatureCollection", properties: {id: "1", visibility: true}}, + {type: "FeatureCollection", properties: {id: "2", visibility: false}} + ], + disableResolutionLimits: true, + visibility: true, + type: "vector" + }]; + const printingService = { + print() {}, + getMapConfiguration() { + return { + layers + }; + }, + validate() { return {};} + }; + const spy = expect.spyOn(printingService, "print"); + getPrintPlugin().then(({ Plugin }) => { + try { + ReactDOM.render(, document.getElementById("container")); + const submit = document.getElementsByClassName("print-submit").item(0); + expect(submit).toExist(); + submit.click(); + setTimeout(() => { + expect(spy.calls.length).toBe(1); + expect(spy.calls[0].arguments[0].layers.length).toBe(1); + expect(spy.calls[0].arguments[0].layers[0].features.length).toBe(1); + done(); + }, 0); + } catch (ex) { + done(ex); + } + }); + }); });