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

#5292: Fixed opacity issues in printing #5972

Merged
merged 2 commits into from
Oct 6, 2020
Merged
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
20 changes: 10 additions & 10 deletions web/client/utils/PrintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const PrintUtils = {
wms: {
map: (layer, spec) => ({
"baseURL": PrintUtils.normalizeUrl(layer.url) + '?',
"opacity": layer.opacity || 1.0,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can extract a function for this repeated check?

"singleTile": false,
"type": "WMS",
"layers": [
Expand Down Expand Up @@ -300,7 +300,7 @@ const PrintUtils = {
map: (layer, spec) => ({
type: 'Vector',
name: layer.name,
"opacity": layer.opacity || 1.0,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
styleProperty: "ms_style",
styles: {
1: PrintUtils.toOpenLayers2Style(layer, layer.style),
Expand All @@ -323,7 +323,7 @@ const PrintUtils = {
map: (layer) => ({
type: 'Vector',
name: layer.name,
"opacity": layer.opacity || 1.0,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
styleProperty: "ms_style",
styles: {
1: PrintUtils.toOpenLayers2Style(layer, layer.style),
Expand All @@ -341,9 +341,9 @@ const PrintUtils = {
)
},
osm: {
map: () => ({
map: (layer = {}) => ({
"baseURL": "http://a.tile.openstreetmap.org/",
"opacity": 1,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
"singleTile": false,
"type": "OSM",
"maxExtent": [
Expand Down Expand Up @@ -381,9 +381,9 @@ const PrintUtils = {
})
},
mapquest: {
map: () => ({
map: (layer = {}) => ({
"baseURL": "http://otile1.mqcdn.com/tiles/1.0.0/map/",
"opacity": 1,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
"singleTile": false,
"type": "OSM",
"maxExtent": [
Expand Down Expand Up @@ -458,7 +458,7 @@ const PrintUtils = {
"style": layer.style,
"name": layer.name,
"requestEncoding": layer.requestEncoding === "RESTful" ? "REST" : layer.requestEncoding,
"opacity": layer.opacity || layer.opacity === 0 ? 0 : 1.0,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
"version": layer.version || "1.0.0"
};
}
Expand All @@ -485,7 +485,7 @@ const PrintUtils = {
path_format: pathFormat,
"type": 'xyz',
"extension": validURL.split('.').pop() || "png",
"opacity": layer.opacity || layer.opacity === 0 ? 0 : 1.0,
"opacity": layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
"tileSize": [256, 256],
"maxExtent": [-20037508.3392, -20037508.3392, 20037508.3392, 20037508.3392],
"resolutions": MapUtils.getResolutions()
Expand All @@ -501,7 +501,7 @@ const PrintUtils = {
const layerName = layer.tileMapUrl.split(layer.tileMapService + "/")[1];
return {
type: 'tms',
opacity: layer.opacity || layer.opacity === 0 ? 0 : 1.0,
opacity: layer.opacity || (layer.opacity === 0 ? 0 : 1.0),
layer: layerName,
// baseURL for mapfish print required to remove the version
baseURL: layer.tileMapService.substring(0, layer.tileMapService.lastIndexOf("/1.0.0")),
Expand Down
32 changes: 32 additions & 0 deletions web/client/utils/__tests__/PrintUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,38 @@ describe('PrintUtils', () => {
expect(rgb).toBe("rgb(255, 255, 255)");
});
describe('specCreators', () => {
describe('opacity', () => {
const testBase = {
wms: layer,
wmts: KVP1,
vector: vectorLayer,
tms: TMS110_1,
tileprovider: BasemapAT,
osm: {
"group": "background",
"source": "osm",
"name": "mapnik",
"title": "Open Street Map",
"type": "osm",
"visibility": true,
"singleTile": false,
"dimensions": [],
"id": "mapnik__0",
"loading": false,
"loadingError": false
}
};
it('check opacity for all layers to be 1 for undefined, therwise its value', () => {
Object.keys(PrintUtils.specCreators).map( k => {
const fun = PrintUtils.specCreators[k].map;
// 0 must remain
expect(fun({ ...(testBase[k] || {}), opacity: 0 }, { projection: "EPSG:900913" }).opacity).toEqual(0);
expect(fun({ ...(testBase[k] || {}), opacity: 0.5 }, { projection: "EPSG:900913" }).opacity).toEqual(0.5);
expect(fun({ ...(testBase[k] || {}), opacity: undefined }, { projection: "EPSG:900913" }).opacity).toEqual(1);

} );
});
});
describe('WMTS', () => {
const checkMatrixIds = (layerSpec, tileMatrixSet) => layerSpec.matrixIds.map((mid, index) => {
const tileMatrixEntry = tileMatrixSet.TileMatrix[index];
Expand Down