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

Get drawable coordinates #89

Closed
aouledissa opened this issue Feb 15, 2019 · 10 comments
Closed

Get drawable coordinates #89

aouledissa opened this issue Feb 15, 2019 · 10 comments

Comments

@aouledissa
Copy link

Hi,

Thank you very much for putting hard work into this amazing library. I am pretty satisfied with the result and the API, However, I would like to get the X and Y coordinates of the drawable inside the ZoomImageView cuz i drawing some circles on top of the ZoomImageView and i would like them to move along with the drawable (after zoom as well). Think about the problem as you have a map (ZoomImageView) and on top of it you have some pins that they have to keep the same relative position when the user zoom in/out or pan the view. Any help would be very appreciated.

Thank you.

@natario1
Copy link
Owner

You can get the coordinates using getPanX and getPanY.

@aouledissa
Copy link
Author

You can get the coordinates using getPanX and getPanY.

this would work but getting the pan doesn't consider the zoom scale factor. I believe coordinates system gets amplified when zoom in. Is there any other way to do it with respect to zoom and scale factor?

@markusressel
Copy link
Collaborator

I think you can just multiply it with the zoom property.

@aouledissa
Copy link
Author

I think you can just multiply it with the zoom property.

Not accurate as get the zoom and doing the multiplication will not consider the zoom center pivot (where the pinch is happening) so this would linear translate all coordinates based on the default position of the pivot. I tried resetting the pivot X and Y on the pinch position but i got no luck.

@markusressel
Copy link
Collaborator

Why is the pivot point of the pinch important when the views on top of the zoom layout have a fixed position relative to it? Shouldn't it be sufficient to move the views on top just like the zoom layout pan but in reverse? When the zoom layout is zoomed in (i.e. zoom > 1) the translation of the views on top would then need to be less than the original pixel size because as you said the zoom layout coordinates will be amplified (off the top of my head I would think you just need to divide the pan by the zoom factor).

@aouledissa
Copy link
Author

Why is the pivot point of the pinch important when the views on top of the zoom layout have a fixed position relative to it? Shouldn't it be sufficient to move the views on top just like the zoom layout pan but in reverse? When the zoom layout is zoomed in (i.e. zoom > 1) the translation of the views on top would then need to be less than the original pixel size because as you said the zoom layout coordinates will be amplified (off the top of my head I would think you just need to divide the pan by the zoom factor).

When using the pan and the zoom the pins of the superposed layout (on top of the zoomLayout) are transposed on the diagonal as linear transpose. What i want to say here is that some times you pinch on a position where the pin is located, therefore this latter should not transpose at all but in my case whether multipliying or dividing it just travels on the diagonal. Besides all that I think this library needs couple of callbacks to be added such as "onZoomUpdate -> zoom: Float" and "onViewPanUpdate -> float[x,y]"

@natario1
Copy link
Owner

Markus is right, but instead of zoom you should use realZoom to be safe.

So either you need panX or panX * realZoom (or minus this, depending on your computations). It depends on how you are drawing these.

Also depending on how you are drawing, you might have to take other things into account, like the screen size / container size. In the end, it is purely a math problem, just make sure to understand what panX and panY are.

You can also use engine.addListener() to receive callbacks.

@aouledissa
Copy link
Author

Markus is right, but instead of zoom you should use realZoom to be safe.

So either you need panX or panX * realZoom (or minus this, depending on your computations). It depends on how you are drawing these.

Also depending on how you are drawing, you might have to take other things into account, like the screen size / container size. In the end, it is purely a math problem, just make sure to understand what panX and panY are.

You can also use engine.addListener() to receive callbacks.

Sounds good i'll give it a try. Thanks a lot

@RayyanTahir
Copy link
Contributor

@andromedcodes were you able to get the correct drawable coordinates inside ZoomImageView?

Here's what I've tried:

ZoomImageView imgScreen;
Matrix m = new Matrix(imgScreen.getImageMatrix());
        Drawable d = imgScreen.getDrawable();
        RectF drawableRect = new RectF(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        RectF viewRect = new RectF(0, 0, imgScreen.getWidth(), imgScreen.getHeight());
        m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
        m.invert(m);

        // Convert the points inside the image
        float[] points = new float[2];
        points[0] = event.getX(); //holds x coordinate of drawable
        points[1] = event.getY(); //holds y coordinate of drawable
        m.mapPoints(points);

But I don't understand how to adjust the pan and zoom values in there. Any help would be appreciated. Thanks

@stale
Copy link

stale bot commented Mar 4, 2020

This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the status:stale label Mar 4, 2020
@stale stale bot closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants