Skip to content

Commit

Permalink
#8998: Fix - Layers with visibility scale limits do not print if useF…
Browse files Browse the repository at this point in the history
…ixedScales configured (#9138) (#9178)
  • Loading branch information
dsuren1 authored May 17, 2023
1 parent 15c0793 commit 25aeef4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
13 changes: 4 additions & 9 deletions web/client/plugins/Print.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down
44 changes: 40 additions & 4 deletions web/client/plugins/__tests__/Print-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(<Plugin
pluginCfg={{
onPrint: actions.onPrint
}}
useFixedScales
defaultBackground={["osm", "empty"]}
/>, 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);
}
});
});
});

0 comments on commit 25aeef4

Please sign in to comment.