Skip to content

Commit

Permalink
Set draw layer offset and init scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Sep 4, 2024
1 parent 5f061d3 commit adb84b2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ export class App {
// sync layer groups
this.#stage.fitToContainer();

// view layer offset (done before scale)
// layer offset (done before scale)
viewLayer.setOffset(layerGroup.getOffset());

// get and apply flip flags
Expand Down Expand Up @@ -2006,13 +2006,28 @@ export class App {
// sync layer groups
this.#stage.fitToContainer();

// layer offset (done before scale)
drawLayer.setOffset(layerGroup.getOffset());

// get and apply flip flags
const flipFlags = this.#getViewFlipFlags(
imageGeometry.getOrientation(),
viewConfig.orientation);
this.#applyFlipFlags(flipFlags, drawLayer);

drawLayer.setScale(layerGroup.getScale());
// do we have more than one layer
const noViewLayers = layerGroup.getNumberOfViewLayers() === 0;
// layer scale (done after possible flip)
if (!noViewLayers) {
// use zoom offset of base layer
const baseViewLayer = layerGroup.getBaseViewLayer();
drawLayer.initScale(
layerGroup.getScale(),
baseViewLayer.getAbsoluteZoomOffset()
);
} else {
drawLayer.setScale(layerGroup.getScale());
}

// add possible existing data
drawLayer.setAnnotationGroup(
Expand Down
30 changes: 30 additions & 0 deletions src/gui/drawLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,36 @@ export class DrawLayer {
this.#updateLabelScale(finalNewScale);
}

/**
* Initialise the layer scale.
*
* @param {Scalar3D} newScale The scale as {x,y,z}.
* @param {Scalar2D} absoluteZoomOffset The zoom offset as {x,y}
* without the fit scale (as provided by getAbsoluteZoomOffset).
*/
initScale(newScale, absoluteZoomOffset) {
const orientedNewScale = this.#planeHelper.getTargetOrientedPositiveXYZ({
x: newScale.x * this.#flipScale.x,
y: newScale.y * this.#flipScale.y,
z: newScale.z * this.#flipScale.z,
});
const finalNewScale = {
x: this.#fitScale.x * orientedNewScale.x,
y: this.#fitScale.y * orientedNewScale.y
};
this.#konvaStage.scale(finalNewScale);

this.#zoomOffset = {
x: absoluteZoomOffset.x / this.#fitScale.x,
y: absoluteZoomOffset.y / this.#fitScale.y
};
const offset = this.#konvaStage.offset();
this.#konvaStage.offset({
x: offset.x + this.#zoomOffset.x,
y: offset.y + this.#zoomOffset.y
});
}

/**
* Set the layer offset.
*
Expand Down

0 comments on commit adb84b2

Please sign in to comment.