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

Unexpected zooming and panning #4

Open
cfbeard opened this issue Nov 16, 2023 · 3 comments
Open

Unexpected zooming and panning #4

cfbeard opened this issue Nov 16, 2023 · 3 comments

Comments

@cfbeard
Copy link

cfbeard commented Nov 16, 2023

The lines attached below seem to be causing some unexpected zoom and panning issues. When zooming in, the camera will automatically zoom back out or pan in a random direction.

update = {
it.controller.animateTo(
cameraState.geoPoint,
cameraState.zoom,
cameraState.speed
)

@sepehrpg
Copy link

I also have this problem‌ "When zooming in, the camera will automatically zoom back out or pan in a random direction."

@cvetyshayasiren
Copy link

I encountered this issue and after many attempts, found a temporary working solution.

Instead of:

val cameraState = rememberCameraState {
    geoPoint = GeoPoint(60.0, 30.0)
    zoom = 14.0
}

Use:

var cameraState by remember { 
    mutableStateOf(
        CameraState(
            CameraProperty(
                geoPoint = GeoPoint(60.0, 30.0), 
                zoom = 14.0
            )
        )
    )
}

LaunchedEffect(cameraState.zoom) {
    val zoom = cameraState.zoom
    val geoPoint = cameraState.geoPoint
    cameraState = CameraState(
        CameraProperty(
            geoPoint = geoPoint,
            zoom = zoom
        )
    )
}

The key is to catch the zoom change event and "recreate" the cameraState before this random drift occurs.

@rdietrichberlin
Copy link

Instead of recreate to CameraState (which loose to map: OsmMapView property connection) i recommend to update the zoom level on motion events:
MapViewUpdater.kt:23

  factory = {
            MapPropertiesNode(mapViewComposed, mapListeners, cameraState, overlayManagerState).also {
                mapViewComposed.setOnTouchListener { _, motionEvent: MotionEvent ->
                    if (motionEvent.action == MotionEvent.ACTION_UP) {
                        cameraState.geoPoint = GeoPoint(mapViewComposed.mapCenter.latitude, mapViewComposed.mapCenter.longitude)
                        cameraState.zoom = mapViewComposed.zoomLevelDouble
                    }
                    false
                }
            }
        }

This updates the zoom level correctly on pinch zoom.

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

4 participants