Zoomlayout: Get drawable coordinates

Created on 15 Feb 2019  ·  10Comments  ·  Source: natario1/ZoomLayout

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.

question stale

Most helpful comment

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.

All 10 comments

You can get the coordinates using getPanX and getPanY.

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?

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

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.

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).

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]"

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.

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

@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

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.

Was this page helpful?
0 / 5 - 0 ratings