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

goTo proposal (in ViewControls) #7

Open
bpioge opened this issue Jul 16, 2021 · 1 comment
Open

goTo proposal (in ViewControls) #7

bpioge opened this issue Jul 16, 2021 · 1 comment

Comments

@bpioge
Copy link
Contributor

bpioge commented Jul 16, 2021

/**
 * 
 * Center the view on the point [targetX, targetY]. Apply a zoom if provided
 * 
 * @param targetX 
 * @param targetY 
 * @param zoom 
 * @param normalized 
 */
goTo(targetX: number, targetY: number, zoom : number, normalized = true) {
    if (!normalized)
      var { x, y } = this.viewer.normalize({ x, y });
    else {
      var { x, y } = { x: targetX, y: targetY };
    }

    if(zoom){
      this.viewer.s = zoom;
      this.viewer.stage.scale.set(this.viewer.s * this.viewer.rw / this.viewer.imageWidth,
        this.viewer.s * this.viewer.rh / this.viewer.imageHeight);
    }

    let centerXOffset = (this.viewer.canvasWidth) / 2 / this.viewer.s;
    let centerYOffset = (this.viewer.canvasHeight) / 2 / this.viewer.s;


    this.viewer.rx = centerXOffset + (((x * this.viewer.rw * this.viewer.s) + this.viewer.sx) / this.viewer.s * (-1));
    this.viewer.ry = centerYOffset + (((y * this.viewer.rh * this.viewer.s) + this.viewer.sy) / this.viewer.s * (-1));

    this.viewer.stage.position.set(this.viewer.rx * this.viewer.s + this.viewer.sx, this.viewer.ry * this.viewer.s + this.viewer.sy);

    this.triggerOnZoom();
    this.computeHitArea();
  }
@bpioge
Copy link
Contributor Author

bpioge commented Jul 16, 2021

/**

  • Return the denormalized position relative to the current view (zoom and pan)
  • @param vertice
    */
    public getViewPosition(vertice: [number, number]) : [number, number]{
    const globalPoint = this.renderer.stage.toGlobal({
    x : this.renderer.denormalizeX(vertice[0]),
    y : this.renderer.denormalizeY(vertice[1])
    });
    const boudingOffset = (this.renderer.view.parentNode as HTMLDivElement).getBoundingClientRect();
return [
  Math.round(globalPoint.x + boudingOffset.left),
  Math.round(globalPoint.y + boudingOffset.top)
];

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant