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

Map rotates/zooms/moves to an inadequate position after opening the quest form #3346

Closed
cyclingcat opened this issue Oct 6, 2021 · 2 comments
Assignees
Labels

Comments

@cyclingcat
Copy link

cyclingcat commented Oct 6, 2021

Hi there,

this one looks like a bug that must have been introduced many versions ago, but since the introduction of quests for longer OSM ways in v35.0 its impact has become more adverse.

If I click on a quest icon concerning a way, the quest form appears and the map rotates/zooms/moves. If I remember correctly, the zoom was calculated in a way that the whole way was completely visible on the displayed map section (which makes sense in order to show the way in its context). But sometimes the zoom/movement/rotation of the displayed map isn't really helpful, because the affected way is either not visible in its entirety or, even worse, not visible at all. For me it looks like some miscalculation takes place under certain cirumstances yet unknown to me.

I didn't succeed in reproducing the issue step by step, but I face it quite often. If I close the quest form, zoom/pan/rotate the map manually and click on the same quest again, the displayed map section often also changes, making things sometimes better, sometimes worse.

See these screenshots:

A road surface quest...

Quest

... after the click on it, the map zooms and pans, but the zoom factor is much too high and the affected road is displayed near the upper border of the screen:

After_click

During the next time I will try to narrow down this effect a little bit.

The cycling cat

@cyclingcat cyclingcat added the bug label Oct 6, 2021
@westnordost
Copy link
Member

westnordost commented Oct 6, 2021

Yes, I know. I believe this must be a tangram-bug but I have been too lazy to investigate if this is true. For anyone wanting to give it a shot, the code is in

fun getEnclosingCameraPosition(bounds: BoundingBox, padding: RectF): CameraPosition? {
val zoom = getMaxZoomThatContainsBounds(bounds, padding) ?: return null
val boundsCenter = listOf(bounds.min, bounds.max).centerPointOfPolyline()
val pos = getLatLonThatCentersLatLon(boundsCenter, padding, zoom) ?: return null
val camera = cameraPosition
return CameraPosition(pos, camera.rotation, camera.tilt, zoom)
}
private fun getMaxZoomThatContainsBounds(bounds: BoundingBox, padding: RectF): Float? {
val screenBounds: BoundingBox
val currentZoom: Float
synchronized(c) {
screenBounds = screenAreaToBoundingBox(padding) ?: return null
currentZoom = cameraPosition.zoom
}
val screenWidth = normalizeLongitude(screenBounds.max.longitude - screenBounds.min.longitude)
val screenHeight = screenBounds.max.latitude - screenBounds.min.latitude
val objectWidth = normalizeLongitude(bounds.max.longitude - bounds.min.longitude)
val objectHeight = bounds.max.latitude - bounds.min.latitude
val zoomDeltaX = log10(screenWidth / objectWidth) / log10(2.0)
val zoomDeltaY = log10(screenHeight / objectHeight) / log10(2.0)
val zoomDelta = min(zoomDeltaX, zoomDeltaY)
return max( 1.0, min(currentZoom + zoomDelta, 21.0)).toFloat()
}
fun getLatLonThatCentersLatLon(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 = offsetScreenCenter.initialBearingTo(screenCenter)
val distanceAfterZoom = distance * (2.0).pow(-zoomDelta)
return position.translate(distanceAfterZoom, angle)
}

@cyclingcat cyclingcat changed the title Map shows Map rotates/zooms/moves to an inadequate position after opening the quest form Oct 6, 2021
@westnordost westnordost added the needs PR accepted suggestion, but only if a contributor implements it label Oct 15, 2021
@westnordost westnordost self-assigned this Apr 15, 2024
@westnordost westnordost removed the needs PR accepted suggestion, but only if a contributor implements it label Apr 15, 2024
@westnordost
Copy link
Member

Will be solved with #3123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants