Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9823: Fix - [Annotations] Disabled annotations are printed #9837

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion web/client/plugins/Print.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,17 @@ 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);

const filtered = layers.filter((layer) =>
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) {
Expand Down
37 changes: 37 additions & 0 deletions web/client/plugins/__tests__/Print-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Plugin printingService={printingService}/>, 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);
}
});
});
});
Loading