Skip to content

Commit

Permalink
Merge pull request #1765 from rafavalpa/avoid-base-layer-change-opacity
Browse files Browse the repository at this point in the history
Avoid base layer opacity to be changed
  • Loading branch information
ivmartel authored Oct 3, 2024
2 parents 853d155 + d5ddabf commit fd5b242
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/gui/layerGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export class LayerGroup {
return this.#baseScale;
}


/**
* Get the added scale: the scale added to the base scale.
*
Expand Down Expand Up @@ -439,11 +440,20 @@ export class LayerGroup {
* @returns {ViewLayer|undefined} The layer.
*/
getBaseViewLayer() {
let layer;
if (this.#layers[0] instanceof ViewLayer) {
layer = this.#layers[0];
// use first layer as base for calculating position and
// line sizes
let baseLayer;
for (const layer of this.#layers) {
if (layer instanceof ViewLayer) {
baseLayer = layer;
break;
}
}
return layer;
if (typeof baseLayer === 'undefined') {
logger.warn('No layer found');
return;
}
return baseLayer;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/gui/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ export class OpacityBinder {
if (typeof event.dataid === 'undefined') {
return;
}
// propagate to first view layer
// propagate to first view layer if it is not base layer
const viewLayers = layerGroup.getViewLayersByDataId(event.dataid);
if (viewLayers.length !== 0) {
const baseLayer = layerGroup.getBaseViewLayer();
if (viewLayers.length !== 0 && baseLayer !== viewLayers[0]) {
viewLayers[0].setOpacity(event.value);
viewLayers[0].draw();
}
Expand Down

0 comments on commit fd5b242

Please sign in to comment.