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

MinimumScaleMode.Fit and coordinates #338

Closed
krabo0om opened this issue Aug 21, 2016 · 23 comments
Closed

MinimumScaleMode.Fit and coordinates #338

krabo0om opened this issue Aug 21, 2016 · 23 comments

Comments

@krabo0om
Copy link

Hey,
thanks to @tsuijten and @peterLaurence PR #318 introduced the MinimumScaleMode.Fit mode adding whitespaces when totally zoomed out.
However, this broke the coordinates of tap events. A short example:
Lets say I have an image of 1000 width * 500 height and set MinimumScaleMode.FIT. Zoomed totally in at 1.0 and tapping the lower right I get x,y of 1000,500. Fine.
Zooming out it adds the whitespaces and centres the image, also fine. However, if I tap the lower right now I get x,y of something like 1000,2500 because the added whitespace.

This offset is calculated in ZoomPanLayout.onLayout() with translateX and translateY and should be used to offset the MotionEvent the onTouchEvent() gets.

p-lr added a commit to p-lr/TileView that referenced this issue Aug 21, 2016
@p-lr
Copy link
Collaborator

p-lr commented Aug 21, 2016

I can confirm this. I tested the changes suggested and it fixes the issue, although i'm not yet sure this is the correct way to fix this nor this won't have side effects. Nevertheless, the changes can be seen on my fork, banch fix#338.
It can now be checked with the RealMapTileView demo.

@moagrius you can check the changes, and if you agree i can PR. FYI, i logged the values of translateX and translateY during layout change. They were equal to 0 except when i zoomed out enough to see white spaces.

@moagrius
Copy link
Owner

i commented your fork peter

@moagrius
Copy link
Owner

@krabo0om this should be fixed in ad43318 - can you grab the latest master and confirm? if it works, i'll publish a release

@peterLaurence i skipped a PR (no real reason just rushing i guess) - does this look sane to you?

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

@moagrius it looks ok for me. It fixes the markers part. One last thing is the HotSpots (aka Regions) are not offset, so it looks to me that the modified touch event position can lead to wrong HotSpot match.

@krabo0om
Copy link
Author

@moagrius looks good to me, too.
My callout view is not chopped any more and my hot spots are all working.

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

@krabo0om your HotSpots are working even when you have white spaces (in FIT mode)?

@krabo0om
Copy link
Author

@peterLaurence yeah they do 😄

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

Ok i must be missing something. Good news anyway.

@krabo0om
Copy link
Author

there might be a new bug with callouts and clipChildren=true:
disappearing callout
So when I show the callout I pull data from a server, the progress bar shows that. After that's done I set the visibility of the progress bar to View.GONE resulting in a new layout phase. The view itself stays visible and it's position isn't changed, however, it disappears (after the progress bar is gone) when it's not inside the MarkerLayout any longer.
I guess that the systems hides the view because it left the parent.

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

Try to set the visibility of the marker to View.VISIBLE right after you set View.GONE on the progressbar?

@krabo0om
Copy link
Author

the view's visibility is not affected it's always View.VISIBLE, I used a View.OnLayoutChangeListener (fired when the progress bar is gone) and a OnAttachStateChangeListener (fired when the callout is removed because of a tap on the image) to confirm this. The disappearing view behaves the same as a view inside the MarkerLayout

@krabo0om
Copy link
Author

I could not get the CalloutLayout's moveMarker working to move it back inside the MarkerLayout to confirm that the system just ignores the callout during the render phase.

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

I can't reproduce on my side. Callouts stay visible even when outside and when a child view's visibility is set to View.GONE.

[EDIT] I could reproduce by playing with the anchorY parameter of TileView.addCallout( View view, double x, double y, Float anchorX, Float anchorY ). I set a value so the callout goes outside the TileView. And right after this callout shows up, it disappears (no need to set a child view's vivisibility to GONE).

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

So as a workaround, you can adjust the anchorY value for that disappearing callout, so it gets at least partially inside the visible tiles.

@krabo0om
Copy link
Author

this works for now (I used View.offsetTopAndBottom).
I'll try to reproduce it with the demo app.

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

I found the fix. setClipChildren( false ); has to be added in MarkerLayout constructor too.
In that particular case, the MarkerLayout was clipping its child view.

@krabo0om
Copy link
Author

I can confirm it's working with setClipChildren( false ) in the MarkerLayout

@krabo0om
Copy link
Author

krabo0om commented Aug 23, 2016

okay I hope this is the last thing: Callouts won't be closed when tapping in the whitespace.
This should solve it (in TileView):

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    mCalloutLayout.removeAllViews();
    return super.onTouchEvent( event );
  }

@moagrius
Copy link
Owner

the time difference is a killer!

anyways, IIUC i need to add 2 things:

  1. setClipChildren in MarkerLayout
  2. pass touch event to the CalloutLayout

i'll post those, let me know if i missed anything, otherwise i'll generate a release tomorrow

thanks guys

@moagrius
Copy link
Owner

ok it's up

@p-lr
Copy link
Collaborator

p-lr commented Aug 23, 2016

Looks good to me. Though i noticed that a touch inside a SampleCallout causes it to disappear, while it seems to me that it didn't before. I don't know if it's a problem anyway.

@moagrius
Copy link
Owner

it will unless the callout view consumes the event (e.g., with a click listener)

thanks peter, i'll bump versions and generate a release

i appreciate all your help, as always

@moagrius
Copy link
Owner

2.2.1 is out

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

3 participants