-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
[Exploration] Keep rotation center when note or form is open #3122
Conversation
fun getLatLonThatCentersLatLonAfterRotation(position: LatLon, padding: RectF, zoom: Float = cameraPosition.zoom): LatLon? { | ||
val view = glViewHolder?.view ?: return null | ||
val w = view.width | ||
val h = view.height | ||
if (w == 0 || h == 0) return null | ||
|
||
val screenCenter = screenPositionToLatLon(PointF(w / 2f, h / 2f)) ?: return null | ||
val offsetScreenCenter = screenPositionToLatLon( | ||
PointF( | ||
padding.left + (w - padding.left - padding.right) / 2, | ||
padding.top + (h - padding.top - padding.bottom) / 2 | ||
) | ||
) ?: return null | ||
|
||
val zoomDelta = zoom.toDouble() - cameraPosition.zoom | ||
val distance = offsetScreenCenter.distanceTo(screenCenter) | ||
val angle = 0.0 | ||
val distanceAfterZoom = distance * (2.0).pow(-zoomDelta) | ||
return position.translate(-distanceAfterZoom, angle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure at the beginning how much of getLatLonThatCentersLatLon
I'd have to change to get the desired behavior, so I opted to add a copy of it to modify instead of trying to add a flag, and figure out what the right interface ought to be, afterward.
In the end, all I ended up changing was the angle (offset from north) and negating distanceAfterZoom
on the final line (which I probably wouldn't even need if I chose the correct angle).
In addition to the janky code, this is also janky behavior: It doesn't rotate smoothly around the point. Instead, the map does a little boomerang where it zooms away from the point, then quickly returns. It's a little jarring, but I don't think it's worth fixing, unless someone more experienced with camera manipulation knows the right way to do it; better to request "rotate around a point" from Tangram. That said, even with the awkward transition, it's an improvement over the previous behavior, since at least you end up with the same point centered, rather than some random location. |
Well, as said in #3101 (comment) , I don't really want to incorporate even more workarounds for missing functionality in tangram-es. If you want to explore, what would be more helpful would be to try out maplibre and see if it have all the features we need. |
Hm. What if I refactored this to push all the workarounds behind the wrapper? In other words, the wrapper would expose the interface we'd like tangrom to expose, and if they implement this functionality, we'd replace the workarounds with a direct call. This seems like it would limit the maintenance burden and especially it would not make migrating off of tangram (#3123) any more difficult, since the workaround code would just be thrown away in that case. |
This was the reason why the wrapper was created in the first place. But I'd stay with my opinion. |
This is a quite messy fix for #3101. I don't expect it to be merged as-is; the point is to find out whether @westnordost thinks it's reasonable to clean this up and merge it at all.