You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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.
Instead of drawing the circle ourselves, I created a drawable for it. Now you can see the rotationX is applied when tilted.
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.
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.
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.
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?
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.
@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.
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.
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)
Activity
tobrun commentedon May 4, 2016
Refs #4897
tobrun commentedon May 4, 2016
I'm currently using the following method to draw the circle:
I need to look into which bounds I should be using instead of the foregroundBounds.
tobrun commentedon May 4, 2016
It seems the solution is not as easy as I initially thought above.
See this screenshot were I added a color to the background.
tobrun commentedon May 4, 2016
After some debugging I'm noticing that bounds are not changed when applying rotationX
bleege commentedon May 27, 2016
Just testing this out with the latest code from the
release-android-v4.1.0branch and seeing that the problem still exists.tobrun commentedon May 30, 2016
This issue comes from the following line:
When not transformed. The above statement is working as designed. The problem originates if we apply
setRotationXon 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. TheforegroundBounds.centerY()resembles the non transformed y-coordinate.tobrun commentedon May 30, 2016
Instead of drawing the circle ourselves, I created a drawable for it. Now you can see the rotationX is applied when tilted.
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
drawCircleimplementation from above.tobrun commentedon May 30, 2016
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.tobrun commentedon May 30, 2016
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.
tobrun commentedon May 30, 2016
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?
1ec5 commentedon May 30, 2016
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.
tobrun commentedon May 31, 2016
@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.
That was my initial idea as well. I'm now thinking of rewriting the
onDrawlogic 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.tobrun commentedon May 31, 2016
I have rewritten the way we setup and draw the content:
Instead of leveraging
setRotationX, I'm using an own created Android SDK Camera object and performing the rotation over the x axis myself.[android] #4929 - rewrite MyLocationView with camera and transformati…
[android] #4929 - MyLocationView now requires less drawables to confi…
tobrun commentedon Jun 1, 2016
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.
tobrun commentedon Jun 1, 2016
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)
[android] #4929 - final fixes for refactor MyLocationView
[android] #4929 - fix unit tests MyLocationSettings
[android] #4929 - rewrite MyLocationView with camera and transformati…
[android] #4929 - MyLocationView now requires less drawables to confi…
[android] #4929 - final fixes for refactor MyLocationView
[android] #4929 - fix unit tests MyLocationSettings
bleege commentedon Jun 2, 2016
Rebased and Merged into
release-android-v4.1.0. Great job @tobrun!