Skip to content

Commit 04e8784

Browse files
authored
Fix geosolutions-it#10513 Print preview state is not aligned with TOC (geosolutions-it#10517)
1 parent 7b1e9b4 commit 04e8784

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

web/client/plugins/Print.jsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import Dialog from '../components/misc/Dialog';
2525
import printReducers from '../reducers/print';
2626
import printEpics from '../epics/print';
2727
import { printSpecificationSelector } from "../selectors/print";
28-
import { layersSelector } from '../selectors/layers';
28+
import { layersSelector, rawGroupsSelector } from '../selectors/layers';
2929
import { currentLocaleSelector } from '../selectors/locale';
3030
import { mapSelector, scalesSelector } from '../selectors/map';
3131
import { mapTypeSelector } from '../selectors/maptype';
3232
import { normalizeSRS, convertDegreesToRadian } from '../utils/CoordinatesUtils';
3333
import { getMessageById } from '../utils/LocaleUtils';
3434
import { defaultGetZoomForExtent, getResolutions, mapUpdated, dpi2dpu, DEFAULT_SCREEN_DPI, getScales, reprojectZoom } from '../utils/MapUtils';
35-
import { isInsideResolutionsLimits } from '../utils/LayersUtils';
35+
import { getDerivedLayersVisibility, isInsideResolutionsLimits } from '../utils/LayersUtils';
3636
import { has, includes } from 'lodash';
3737
import {additionalLayersSelector} from "../selectors/additionallayers";
3838
import { MapLibraries } from '../utils/MapTypeUtils';
@@ -629,16 +629,17 @@ export default {
629629
(state) => state.browser && (!state.browser.ie || state.browser.ie11),
630630
currentLocaleSelector,
631631
mapTypeSelector,
632-
(state) => state.print.map
633-
], (open, capabilities, printSpec, pdfUrl, error, map, layers, additionalLayers, scales, usePreview, currentLocale, mapType, printMap) => ({
632+
(state) => state.print.map,
633+
rawGroupsSelector
634+
], (open, capabilities, printSpec, pdfUrl, error, map, layers, additionalLayers, scales, usePreview, currentLocale, mapType, printMap, groups) => ({
634635
open,
635636
capabilities,
636637
printSpec,
637638
pdfUrl,
638639
error,
639640
map,
640641
layers: [
641-
...layers.filter(filterLayer),
642+
...getDerivedLayersVisibility(layers, groups).filter(filterLayer),
642643
...(printSpec?.additionalLayers ? additionalLayers.map(l => l.options).filter(
643644
l => {
644645
const isVector = l.type === 'vector';

web/client/plugins/__tests__/Print-test.jsx

+88
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,92 @@ describe('Print Plugin', () => {
569569
}
570570
});
571571
});
572+
it("test removing visible layers with invisible group", (done) => {
573+
const actions = {
574+
onPrint: () => {}
575+
};
576+
let spy = expect.spyOn(actions, "onPrint");
577+
getPrintPlugin({
578+
layers:
579+
{
580+
flat: [
581+
{
582+
id: 'test:Linea_costa__38262060-608e-11ef-b6d2-f1ba404475c4',
583+
format: 'image/png',
584+
group: 'Default.34a0a320-608e-11ef-b6d2-f1ba404475c4',
585+
search: {
586+
url: '/geoserver/wfs',
587+
type: 'wfs'
588+
},
589+
name: 'test:Linea_costa',
590+
description: '',
591+
title: 'Linea_costa',
592+
type: 'wms',
593+
url: '/geoserver/wms',
594+
visibility: true
595+
},
596+
{
597+
type: 'wms',
598+
format: 'image/png',
599+
featureInfo: null,
600+
url: '/geoserver/wms',
601+
visibility: true,
602+
dimensions: [],
603+
name: 'test:areeverdiPolygon',
604+
title: 'areeverdiPolygon',
605+
id: 'test:areeverdiPolygon__722d7920-608e-11ef-8123-43293ce7e0e8'
606+
}
607+
],
608+
groups: [
609+
{
610+
id: 'Default',
611+
title: 'Default',
612+
name: 'Default',
613+
nodes: [
614+
'test:areeverdiPolygon__722d7920-608e-11ef-8123-43293ce7e0e8',
615+
{
616+
id: 'Default.34a0a320-608e-11ef-b6d2-f1ba404475c4',
617+
title: 'g1',
618+
name: '34a0a320-608e-11ef-b6d2-f1ba404475c4',
619+
nodes: [
620+
'test:Linea_costa__38262060-608e-11ef-b6d2-f1ba404475c4'
621+
],
622+
visibility: false
623+
}
624+
],
625+
visibility: true
626+
}
627+
]
628+
},
629+
projection: "EPSG:4326",
630+
state: {
631+
...initialState,
632+
map: {
633+
...initialState.map,
634+
zoom: 5.1
635+
}
636+
}
637+
}).then(({ Plugin }) => {
638+
try {
639+
ReactDOM.render(<Plugin
640+
pluginCfg={{
641+
onPrint: actions.onPrint
642+
}}
643+
defaultBackground={["osm", "empty"]}
644+
/>, document.getElementById("container"));
645+
const submit = document.getElementsByClassName("print-submit").item(0);
646+
expect(submit).toExist();
647+
ReactTestUtils.Simulate.click(submit);
648+
649+
setTimeout(() => {
650+
expect(spy.calls.length).toBe(1);
651+
expect(spy.calls[0].arguments[1].layers.length).toBe(1);
652+
expect(spy.calls[0].arguments[1].layers[0].layers).toEqual(['test:areeverdiPolygon']);
653+
done();
654+
}, 0);
655+
} catch (ex) {
656+
done(ex);
657+
}
658+
});
659+
});
572660
});

0 commit comments

Comments
 (0)