-
Notifications
You must be signed in to change notification settings - Fork 86
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 print layers when opacity background layer is a layer group #4041
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import googAsserts from 'goog/asserts.js'; | ||
import * as olArray from 'ol/array.js'; | ||
import olFormatWMTSCapabilities from 'ol/format/WMTSCapabilities.js'; | ||
import olLayerGroup from 'ol/layer/Group.js'; | ||
import OlLayerGroup from 'ol/layer/Group.js'; | ||
import olLayerImage from 'ol/layer/Image.js'; | ||
import olLayerTile from 'ol/layer/Tile.js'; | ||
import * as olObj from 'ol/obj.js'; | ||
|
@@ -241,7 +241,7 @@ exports.prototype.createWMTSLayerFromCapabilititesObj = function( | |
* @export | ||
*/ | ||
exports.prototype.createBasicGroup = function(opt_layers) { | ||
const group = new olLayerGroup(); | ||
const group = new OlLayerGroup(); | ||
if (opt_layers) { | ||
group.setLayers(opt_layers); | ||
} | ||
|
@@ -287,26 +287,44 @@ exports.prototype.getGroupFromMap = function(map, groupName) { | |
* @export | ||
*/ | ||
exports.prototype.getFlatLayers = function(layer) { | ||
return this.getFlatLayers_(layer, []); | ||
if (layer instanceof OlLayerGroup) { | ||
const sublayers = layer.getLayers().getArray(); | ||
const hasGroupLayer = sublayers.some(sublayer => sublayer instanceof OlLayerGroup); | ||
if (!hasGroupLayer) { | ||
return sublayers.slice(); | ||
} | ||
} | ||
return this.getFlatLayers_(layer, [], undefined); | ||
}; | ||
|
||
|
||
/** | ||
* Get an array of all layers in a group. The group can contain multiple levels | ||
* of others groups. | ||
* of others groups. When we flatten a group, we get the child layers. | ||
* If opacity is defined on the group, this value is lost. | ||
* Computed opacity is a custom 'back-up' value that contains | ||
* the calculated value of all ancestors and the given layer. | ||
* @param {ol.layer.Base} layer The base layer, mostly a group of layers. | ||
* @param {Array.<ol.layer.Base>} array An array to add layers. | ||
* @param {number|undefined} computedOpacity Opacity inherited from ancestor layer groups. | ||
* @return {Array.<ol.layer.Layer>} Layers. | ||
* @private | ||
*/ | ||
exports.prototype.getFlatLayers_ = function(layer, array) { | ||
if (layer instanceof olLayerGroup) { | ||
exports.prototype.getFlatLayers_ = function(layer, array, computedOpacity) { | ||
const opacity = layer.getOpacity(); | ||
if (computedOpacity !== undefined) { | ||
computedOpacity *= opacity; | ||
} else { | ||
computedOpacity = opacity; | ||
} | ||
if (layer instanceof OlLayerGroup) { | ||
const sublayers = layer.getLayers(); | ||
sublayers.forEach((l) => { | ||
this.getFlatLayers_(l, array); | ||
this.getFlatLayers_(l, array, computedOpacity); | ||
}); | ||
} else { | ||
if (array.indexOf(layer) < 0) { | ||
layer.set('inheritedOpacity', computedOpacity, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check in our code if there is a way to indicate (document) that this opacity and should be used ? |
||
array.push(layer); | ||
} | ||
} | ||
|
@@ -326,7 +344,7 @@ exports.prototype.getFlatLayers_ = function(layer, array) { | |
exports.prototype.getLayerByName = function(layerName, layers) { | ||
let found = null; | ||
layers.some((layer) => { | ||
if (layer instanceof olLayerGroup) { | ||
if (layer instanceof OlLayerGroup) { | ||
const sublayers = layer.getLayers().getArray(); | ||
found = this.getLayerByName(layerName, sublayers); | ||
} else if (layer.get('layerNodeName') === layerName) { | ||
|
@@ -440,7 +458,7 @@ exports.prototype.refreshWMSLayer = function(layer) { | |
* @param {number} ZIndex The ZIndex for children element. | ||
*/ | ||
exports.prototype.setZIndexToFirstLevelChildren = function(element, ZIndex) { | ||
if (!(element instanceof olLayerGroup)) { | ||
if (!(element instanceof OlLayerGroup)) { | ||
return; | ||
} | ||
const innerGroupLayers = element.getLayers(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use an optional arguments for "computedOpacity" instead of calling this function with "undefined" at line 297 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion with @gberaudo, we prefer that it is explicit that the value is called as 'undefined' instead of skipping the last argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay