mapbox / mapbox/mapbox-maps-android

[Compose] Make cameraForCoordinates accessible into MapViewportState()

Open
#2,341 15 comments 6 reactions 1 assignee View on GitHub

@pengdev is already working on this.

Since Apr 12, 2024.

auto-triaged compose feature :green_apple:
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

New Feature

When you configure your map composable you can only

mapViewportState = MapViewportState().apply {
    setCameraOptions {
        zoom(9.5)
        center(state.polygonCenter.getCenter().let { Point.fromLngLat(it.long, it.lat) })
    }
}

Therefore, you need to then add something like that

MapEffect(state.polygonCenter) {
    val padding = 32.dp.value.toDouble()
    it.camera.flyTo(it.mapboxMap.cameraForCoordinates(path, EdgeInsets(padding, padding, padding, padding)))
}

The idea would be to be able to do something like

mapViewportState = MapViewportState().apply {
    val padding = 32.dp.value.toDouble()
    setCameraOptions(cameraForCoordinates(path, EdgeInsets(padding, padding, padding, padding)))
}

And therefore no to have to add a MapEffect to recenter the camera

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.