Skip to content

Commit

Permalink
#5292: Fixed opacity issues in printing (#5972) (#5974)
Browse files Browse the repository at this point in the history
* #5292: Fixed opacity issues in printing

* Unified opacity exract system in printutils
  • Loading branch information
offtherailz authored Oct 6, 2020
1 parent 443def2 commit 2c84525
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
28 changes: 18 additions & 10 deletions web/client/utils/PrintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const getGeomType = function(layer) {
const isAnnotationLayer = (layer) => {
return layer.id === "annotations" || layer.name === "Measurements";
};

/**
* Extracts the correct opacity from layer. if Undefined, the opacity is `1`.
* @ignore
* @param {object} layer the MapStore layer
*/
const getOpacity = layer => layer.opacity || (layer.opacity === 0 ? 0 : 1.0);

/**
* Utilities for Print
* @memberof utils
Expand Down Expand Up @@ -243,7 +251,7 @@ const PrintUtils = {
wms: {
map: (layer, spec) => ({
"baseURL": PrintUtils.normalizeUrl(layer.url) + '?',
"opacity": layer.opacity || 1.0,
"opacity": getOpacity(layer),
"singleTile": false,
"type": "WMS",
"layers": [
Expand Down Expand Up @@ -300,7 +308,7 @@ const PrintUtils = {
map: (layer, spec) => ({
type: 'Vector',
name: layer.name,
"opacity": layer.opacity || 1.0,
"opacity": getOpacity(layer),
styleProperty: "ms_style",
styles: {
1: PrintUtils.toOpenLayers2Style(layer, layer.style),
Expand All @@ -323,7 +331,7 @@ const PrintUtils = {
map: (layer) => ({
type: 'Vector',
name: layer.name,
"opacity": layer.opacity || 1.0,
"opacity": getOpacity(layer),
styleProperty: "ms_style",
styles: {
1: PrintUtils.toOpenLayers2Style(layer, layer.style),
Expand All @@ -341,9 +349,9 @@ const PrintUtils = {
)
},
osm: {
map: () => ({
map: (layer = {}) => ({
"baseURL": "http://a.tile.openstreetmap.org/",
"opacity": 1,
"opacity": getOpacity(layer),
"singleTile": false,
"type": "OSM",
"maxExtent": [
Expand Down Expand Up @@ -381,9 +389,9 @@ const PrintUtils = {
})
},
mapquest: {
map: () => ({
map: (layer = {}) => ({
"baseURL": "http://otile1.mqcdn.com/tiles/1.0.0/map/",
"opacity": 1,
"opacity": getOpacity(layer),
"singleTile": false,
"type": "OSM",
"maxExtent": [
Expand Down Expand Up @@ -458,7 +466,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": getOpacity(layer),
"version": layer.version || "1.0.0"
};
}
Expand All @@ -485,7 +493,7 @@ const PrintUtils = {
path_format: pathFormat,
"type": 'xyz',
"extension": validURL.split('.').pop() || "png",
"opacity": layer.opacity || layer.opacity === 0 ? 0 : 1.0,
"opacity": getOpacity(layer),
"tileSize": [256, 256],
"maxExtent": [-20037508.3392, -20037508.3392, 20037508.3392, 20037508.3392],
"resolutions": MapUtils.getResolutions()
Expand All @@ -501,7 +509,7 @@ const PrintUtils = {
const layerName = layer.tileMapUrl.split(layer.tileMapService + "/")[1];
return {
type: 'tms',
opacity: layer.opacity || layer.opacity === 0 ? 0 : 1.0,
opacity: getOpacity(layer),
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

0 comments on commit 2c84525

Please sign in to comment.