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

Support Rotation of image with library #41

Open
hartbert95 opened this issue Sep 13, 2019 · 4 comments
Open

Support Rotation of image with library #41

hartbert95 opened this issue Sep 13, 2019 · 4 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@hartbert95
Copy link

Cases:

  1. The Zooming is working fine for the 0 deg rotation rendered image
  2. Once i rotate the image, the lens location is still stick to the same

Problem:

  1. How to integrate library with the rotated image?
@wittlock
Copy link
Owner

Could you perhaps post a small example that is showing the odd behavior that I can experiment with to find a solution? I'm not quite sure I understand what it is you're asking for, but if I can run it and see it for myself that would help.

@wittlock wittlock added bug Something isn't working enhancement New feature or request labels Nov 14, 2019
@rendlp
Copy link

rendlp commented Jan 29, 2020

I believe what OP means is that when a image is rotated, the calculation which calculates the cursor location is off. This messes up the lens + cursor relationship (I am facing a similar issue).

For example, if I rotate a image 180 degrees, the function which calculates the cursor position is now flipped. So if I zoom in on a 180 degree rotated image and move my cursor to the top right, the lens will move to the bottom left instead.

I'm not 100% sure, but I believe this issue is related to setZoomPosition().

@rendlp
Copy link

rendlp commented Feb 25, 2020

For image rotation I took a vanilla JS approach.

Here is the CSS code example:

public rotateImage180(rotate180: any) {
    rotate180 = document.querySelectorAll('#image-div');
    let i: any = null;
    for (i = 0; i < rotate180.length; i++) {
      rotate180[i].style = `
        transform: rotateY(0deg) rotate(180deg);
        transition: ease-in .3s;
        transform-origin: center center;
        padding: 8px;`;
    }
  }

And another:

public rotateImageRight(rightRotate: any) {
    rightRotate = document.querySelectorAll('#image-div');
    let i: any = null;
    for (i = 0; i < rightRotate.length; i++) {
      rightRotate[i].style = `
        transform: rotateY(0deg) rotate(90deg);
        transition: ease-in .3s;
        transform-origin: center center;
        margin-left: 170px;
        margin-right: 150px;
        padding: 6px;`;
    }
  }

@rendlp
Copy link

rendlp commented Apr 14, 2020

I believe I have narrowed the issue down to the following chunk of code:

private calculateImageAndLensPosition() {
        let lensLeftMod = 0;
        let lensTopMod = 0;

        if (this.enableLens) {
            lensLeftMod = this.lensLeft = this.latestMouseLeft - this.lensWidth / 2;
            lensTopMod = this.lensTop = this.latestMouseTop - this.lensHeight / 2;
        }

        this.fullImageLeft = (this.latestMouseLeft * -this.xRatio) - lensLeftMod;
        this.fullImageTop = (this.latestMouseTop * -this.yRatio) - lensTopMod;
    }

When calculateImageAndLensPosition() is called, the following section will execute if the zoom lens has been enabled:

 if (this.enableLens) {
            lensLeftMod = this.lensLeft = this.latestMouseLeft - this.lensWidth / 2;
            lensTopMod = this.lensTop = this.latestMouseTop - this.lensHeight / 2;
        }

This will calculate the top and left position of the user's mouse if the zoom lens has been enabled. However, if the image and/or image container has been rotated by any degree, the calculation parameters will not adjust for this change and will inversely calculate the user's mouse position.

I have created a temporary fix/hack by implementing the following changes to my own code:

public rotateImage180(rotateLens180: any, rotateImg180: any) {
    rotateLens180 = document.querySelectorAll('.ngxImageZoomFull');
    rotateImg180 = document.querySelectorAll('.ngxImageZoomThumbnail');
    let i: any = null;
    for (i = 0; i < rotateImg180.length; i++) {
      rotateLens180[i].style = `
        transform: rotateY(0deg) rotate(-180deg);`;
      rotateImg180[i].style = `
        transform: rotateY(0deg) rotate(-180deg);
        transition: ease-in .3s;
        transform-origin: center center;`;
    }
  }

I do not think this is a good long-term solution so I will continue researching other possibilities in the meantime. If you have any recommendations they would be much appreciated!

Thanks

EDIT: Grammar fixes + code clean up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants