Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

off-centered accuracy ring #4929

Closed
Closed

Description

@cammace

Tilting the mapview while myLocationEnabled will result in the accuracy ring becoming off-centered around the user dot.

screenshot_20160502-124843

cc: @tobrun

Activity

  1. added
    Android
    on May 3, 2016
  2. added this to the android-v4.1.0 milestone on May 3, 2016
  3. tobrun commented on May 4, 2016

    @tobrun
    Member

    Refs #4897

  4. tobrun commented on May 4, 2016

    @tobrun
    Member

    I'm currently using the following method to draw the circle:

     canvas.drawCircle(foregroundBounds.centerX(), foregroundBounds.centerY(), accuracyPixels <= maxRadius ? accuracyPixels : maxRadius, accuracyPaint);
    

    I need to look into which bounds I should be using instead of the foregroundBounds.

  5. tobrun commented on May 4, 2016

    @tobrun
    Member

    It seems the solution is not as easy as I initially thought above.
    See this screenshot were I added a color to the background.

    device-2016-05-04-134801

  6. tobrun commented on May 4, 2016

    @tobrun
    Member

    After some debugging I'm noticing that bounds are not changed when applying rotationX

  7. bleege commented on May 27, 2016

    @bleege
    Contributor

    Just testing this out with the latest code from the release-android-v4.1.0 branch and seeing that the problem still exists.

    device-2016-05-27-141006

  8. tobrun commented on May 30, 2016

    @tobrun
    Member

    This issue comes from the following line:

    canvas.drawCircle(foregroundBounds.centerX(), foregroundBounds.centerY(),....);

    When not transformed. The above statement is working as designed. The problem originates if we apply setRotationX on the whole View (rotation over the x-axis). This transformation changes how the dot will be drawn but doesn't change anything to the calculations for drawing the circle. The foregroundBounds.centerY() resembles the non transformed y-coordinate.

  9. tobrun commented on May 30, 2016

    @tobrun
    Member

    Instead of drawing the circle ourselves, I created a drawable for it. Now you can see the rotationX is applied when tilted.

    screen shot 2016-05-30 at 11 17 11

    While a fixed size drawable does the trick, but it seems we are back at square one. We need to be able to scale the drawable based on the accuracy value returned by the GPS. Scaling on a canvas depends on topleft of a View or a provided coordinate. The latter one's are the same coordinates required for a correct drawCircle implementation from above.

  10. tobrun commented on May 30, 2016

    @tobrun
    Member

    If have been trying different approaches to solve this issue. From using Camera, transformation matrices to calculating the offset manually. After almost a day of not making progress I'm going to punt on this and will revisit this later.

  11. tobrun commented on May 30, 2016

    @tobrun
    Member

    This SO-post talks about the ability to set the Android SDK Camera distance.This distance passed in will be used to calculate the transformation. I'm thinking that this will be the missing piece to calculate the correct x,y coordinate using that Camera API. I'm currently not sure how I would convert our current z value (zoom level) to pixels.

  12. tobrun commented on May 30, 2016

    @tobrun
    Member

    With above in place I'm seeing the behaviour I was expecting, only the value for camera distance is not correct which results in a too large y translation.

    @1ec5 would it be possible to convert a zoom level to an camera distance?

  13. 1ec5 commented on May 30, 2016

    @1ec5
    Contributor

    The iOS and OS X SDKs have some code to convert between zoom levels and altitudes. At the time I wrote it, I avoided putting it in mbgl because I didn’t realize the Android SDK needed it too. The calculation matches MapKit but is technically inconsistent with mbgl (but still “good enough” for most purposes). Feel free to move the logic to mbgl, but we should probably try harder to match the math in mbgl::TransformState::getProjMatrix() in that case.

    Note that the iOS SDK doesn’t use these conversion routines for positioning or sizing the user dot or its accuracy ring. For that, we size the ring based on the current meters per point, then rotate both elements together based on the degrees of pitch.

  14. tobrun commented on May 31, 2016

    @tobrun
    Member

    @1ec5 thank you for linking that. I tried porting it first to java and see if it resolved the issue. At this point I'm not able to get calculate the correct value. I don't think it related to the linked code but the way I'm setting up the Android SDK Camera object and retrieving the transformation matrix from it.

    Note that the iOS SDK doesn’t use these conversion routines for positioning or sizing the user dot or its accuracy ring.

    That was my initial idea as well. I'm now thinking of rewriting the onDraw logic so we also don't need to explicitly calculate that position. This will be a big lift but I feel it's better to put time into that than try working around the issue. It's cleaner and will be performant because it doesn't require the extra calculations.

  15. tobrun commented on May 31, 2016

    @tobrun
    Member

    I have rewritten the way we setup and draw the content:

    ezgif com-video-to-gif 26

    Instead of leveraging setRotationX, I'm using an own created Android SDK Camera object and performing the rotation over the x axis myself.

  16. added a commit that references this issue on May 31, 2016
  17. self-assigned this
    on May 31, 2016
  18. added a commit that references this issue on Jun 1, 2016
  19. tobrun commented on Jun 1, 2016

    @tobrun
    Member

    While looking into merging the related PR, I noticed that current proposed implementation introduced regressions when it comes to location updates. When not receiving a location update everything is working as designed but when a location update occurs the View location doesn't match the update and breaks showing the location completely. Currently looking into resolving this but not able to give an eta when it will be resolved.

  20. tobrun commented on Jun 1, 2016

    @tobrun
    Member

    I was finally able to pinpoint the issue to rotation. The rotation animation we are applying now impacts the viewport of MyLocationView and combining this with Android SDK camera object results in a wrong perspective. Next steps is to integrate rotation inside of the camera approach and fixup the remaining items in the PR #5192 (comment)

  21. added 2 commits that reference this issue on Jun 1, 2016
  22. added 4 commits that reference this issue on Jun 2, 2016
  23. bleege commented on Jun 2, 2016

    @bleege
    Contributor

    Rebased and Merged into release-android-v4.1.0. Great job @tobrun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Android

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions