Skip to content

Commit

Permalink
Fix Print tool with vendor param (CQL_FILTER) (#4006)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 authored and Tobia Di Pisa committed Jul 25, 2019
1 parent 9bb1c8d commit 03c6aa4
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web/client/utils/PrintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const CoordinatesUtils = require('./CoordinatesUtils');
const SecurityUtils = require('./SecurityUtils');
const MapUtils = require('./MapUtils');
const {optionsToVendorParams} = require('./VendorParamsUtils');
const AnnotationsUtils = require("./AnnotationsUtils");
const {colorToHexStr} = require("./ColorUtils");

Expand Down Expand Up @@ -202,8 +203,14 @@ const PrintUtils = {
"TILED": true,
"EXCEPTIONS": "application/vnd.ogc.se_inimage",
"scaleMethod": "accurate"
}, layer.baseParams || {}, layer.params || {}))
}),
}, layer.baseParams || {}, layer.params || {}, {
...optionsToVendorParams({
nativeCrs: layer.nativeCrs,
layerFilter: layer.layerFilter,
filterObj: layer.filterObj
})
}
))}),
legend: (layer, spec) => ({
"name": layer.title || layer.name,
"classes": [
Expand Down
96 changes: 96 additions & 0 deletions web/client/utils/__tests__/PrintUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,71 @@ const layer = {
type: "wms",
params: {myparam: "myvalue"}
};

const layerSottoPasso = {
id: 'DBT:SOTTOPASSO__6',
type: 'wms',
url: 'http://localhost:8081/geoserver-test/wms',
nativeCrs: 'EPSG:3003'
};

const layerFilterSottoPasso = {
groupFields: [
{
id: 1,
logic: 'OR',
index: 0
}
],
filterFields: [
{
rowId: 1563970241851,
groupId: 1,
attribute: 'TIPO',
operator: '=',
value: 2,
type: 'number',
fieldOptions: {
valuesCount: 0,
currentPage: 1
},
exception: null
}
],
spatialField: {
method: null,
operation: 'INTERSECTS',
geometry: null,
attribute: 'GEOMETRY'
}
};
const filterObjSottoPasso = {
featureTypeName: 'DBT:SOTTOPASSO',
filterType: 'OGC',
ogcVersion: '1.1.0',
pagination: {
startIndex: 0,
maxFeatures: 20
},
groupFields: [
{
id: 1,
logic: 'AND',
index: 0
}
],
filterFields: [
{
attribute: 'ID_OGGETTO',
rowId: 1563970257711,
type: 'number',
groupId: 1,
operator: '<',
value: 44
}
]
};

const featurePoint = {
"type": "Feature",
"geometry": {
Expand Down Expand Up @@ -208,6 +273,37 @@ describe('PrintUtils', () => {
expect(specs[0].customParams.authkey).toExist();
expect(specs[0].customParams.authkey).toBe("mykey");
});
it('custom params include layerFilter and filterObj', () => {
const specs = PrintUtils.getMapfishLayersSpecification([{
...layerSottoPasso,
layerFilter: layerFilterSottoPasso,
filterObj: filterObjSottoPasso
}], {}, 'map');
expect(specs).toExist();
expect(specs.length).toBe(1);
expect(specs[0].customParams.CQL_FILTER).toExist();
expect(specs[0].customParams.CQL_FILTER).toBe(`(("TIPO" = '2')) AND (("ID_OGGETTO" < '44'))`);
});
it('custom params include cql_filter', () => {
const specs = PrintUtils.getMapfishLayersSpecification([{
...layerSottoPasso,
filterObj: filterObjSottoPasso
}], {}, 'map');
expect(specs).toExist();
expect(specs.length).toBe(1);
expect(specs[0].customParams.CQL_FILTER).toExist();
expect(specs[0].customParams.CQL_FILTER).toBe(`("ID_OGGETTO" < '44')`);
});
it('custom params include layerFilter', () => {
const specs = PrintUtils.getMapfishLayersSpecification([{
...layerSottoPasso,
layerFilter: layerFilterSottoPasso
}], {}, 'map');
expect(specs).toExist();
expect(specs.length).toBe(1);
expect(specs[0].customParams.CQL_FILTER).toExist();
expect(specs[0].customParams.CQL_FILTER).toBe(`("TIPO" = '2')`);
});
it('wms layer generation for legend includes scale', () => {
const specs = PrintUtils.getMapfishLayersSpecification([layer], testSpec, 'legend');
expect(specs).toExist();
Expand Down

0 comments on commit 03c6aa4

Please sign in to comment.