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

Fix #10734 Fix print tms layers with 4326 #10738

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 3 additions & 12 deletions web/client/plugins/Print.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import { getMessageById } from '../utils/LocaleUtils';
import { defaultGetZoomForExtent, getResolutions, mapUpdated, dpi2dpu, DEFAULT_SCREEN_DPI, getScales, reprojectZoom } from '../utils/MapUtils';
import { getDerivedLayersVisibility, isInsideResolutionsLimits } from '../utils/LayersUtils';
import { has, includes } from 'lodash';

Check failure on line 36 in web/client/plugins/Print.jsx

View workflow job for this annotation

GitHub Actions / test-front-end

'has' is defined but never used

Check failure on line 36 in web/client/plugins/Print.jsx

View workflow job for this annotation

GitHub Actions / test-front-end

'includes' is defined but never used
import {additionalLayersSelector} from "../selectors/additionallayers";
import { MapLibraries } from '../utils/MapTypeUtils';

Expand Down Expand Up @@ -246,7 +246,8 @@
getDefaultPrintingService,
getLayoutName,
getPrintScales,
getNearestZoom
getNearestZoom,
isCompatibleWithSRS
} = utilsMod;
class Print extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -527,19 +528,9 @@
addParameter = (name, value) => {
this.props.addPrintParameter("params." + name, value);
};
isCompatibleWithSRS = (projection, layer) => {
return projection === "EPSG:3857" || includes([
"wms",
"wfs",
"vector",
"graticule",
"empty",
"arcgis"
], layer.type) || layer.type === "wmts" && has(layer.allowedSRS, projection);
};
isAllowed = (layer, projection) => {
return this.props.ignoreLayers.indexOf(layer.type) === -1 &&
this.isCompatibleWithSRS(normalizeSRS(projection), layer);
isCompatibleWithSRS(normalizeSRS(projection), layer);
};

isBackgroundIgnored = (layers, projection) => {
Expand Down
25 changes: 24 additions & 1 deletion web/client/utils/PrintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import isNil from "lodash/isNil";
import get from "lodash/get";
import min from "lodash/min";
import trimEnd from 'lodash/trimEnd';
import includes from 'lodash/includes';
import has from 'lodash/has';

import { getGridGeoJson } from "./grids/MapGridsUtils";
import { isImageServerUrl } from './ArcGISUtils';
Expand Down Expand Up @@ -1173,6 +1175,26 @@ export const getOlDefaultStyle = (layer, styleType) => {
}
}
};
/**
* check compatibility between layer options and print projection
* @param {string} projection the projection code, e.g. EPSG:3857
* @param {object} layer the layer options
* @returns {boolean} if layer is compatible with CRS selected for printing
*/
export const isCompatibleWithSRS = (projection, layer) => {
const isProjectionCompatible = projection === "EPSG:3857";
const isValidType = includes([
"tms", // #10734 added tms among valid types to be printed
"wms",
"wfs",
"vector",
"graticule",
"empty",
"arcgis"
], layer?.type);
const isValidWMTS = layer?.type === "wmts" && has(layer.allowedSRS, projection);
return isProjectionCompatible || isValidType || isValidWMTS;
};


PrintUtils = {
Expand All @@ -1184,5 +1206,6 @@ PrintUtils = {
toOpenLayers2Style,
toOpenLayers2TextStyle,
getWMTSMatrixIds,
getOlDefaultStyle
getOlDefaultStyle,
isCompatibleWithSRS
};
85 changes: 85 additions & 0 deletions web/client/utils/__tests__/PrintUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getNearestZoom,
getMapfishPrintSpecification,
rgbaTorgb,
isCompatibleWithSRS,
specCreators,
addTransformer,
addMapTransformer,
Expand Down Expand Up @@ -1052,5 +1053,89 @@ describe('PrintUtils', () => {
expect(reqLayersCreditTxt).toEqual('OSM Simple Light Rendering GeoSolutions Data © OpenStreetMap contributors, ODbL | Attribution layer 02 | Attribution layer 03 @ polygon layer');
});
});
it("test isCompatibleWithSRS", () => {
const prj3857 = "EPSG:3857";
const prj4326 = "EPSG:4326";
const tests = [{
args: {
projection: prj3857,
layer: undefined
},
result: true
},
{
args: {
projection: undefined,
layer: {type: "wms"}
},
result: true
},
{
args: {
projection: undefined,
layer: {type: "wfs"}
},
result: true
},
{
args: {
projection: undefined,
layer: {type: "vector"}
},
result: true
},
{
args: {
projection: undefined,
layer: {type: "graticule"}
},
result: true
},
{
args: {
projection: undefined,
layer: {type: "empty"}
},
result: true
},
{
args: {
projection: undefined,
layer: {type: "arcgis"}
},
result: true
},
{
args: {
projection: prj4326,
layer: {type: "tms"}
},
result: true
},
{
args: {
projection: prj4326,
layer: {type: "incompatible"}
},
result: false
},
{
args: {
projection: prj4326,
layer: {type: "wmts"}
},
result: false
}, {
args: {
projection: prj4326,
layer: {type: "wmts", allowedSRS: {"EPSG:4326": {}}}
},
result: true
}];
tests.forEach(({args, result}) => {
let res = isCompatibleWithSRS(args.projection, args.layer);
expect(res).toBe(result);
});
});
});
});
Loading