mapbox / MapboxStatic.swift

Static map snapshots with overlays in Swift or Objective-C on iOS, macOS, tvOS, and watchOS
https://www.mapbox.com/api-documentation/?language=Swift#static
Other
188 stars 31 forks source link

Convert MapView camera zoom to SnapshotCamera zoomLevel #120

Closed trunghvbk closed 9 months ago

trunghvbk commented 1 year ago

I have a mapView implemented and I want to snapshot this mapView I read the document and create a SnapshotOption like this:

let center = mapView.cameraState.center
let zoom = mapView.cameraState.zoom
let snapshotCamera = SnapshotCamera(lookingAtCenter: center, zoomLevel: zoom > 20 ? 20 : zoom)
let options = SnapshotOptions(
    styleURL: styleURL,
    camera: snapshotCamera,
    size: mapView.bounds.size)
let snapshot = Snapshot(
    options: options,
    accessToken: "<accessToken>"
)
let image = snapshot.image

But it seems like the zoomLevel of SnapshotCamera is not the same with zoom level of MapView camera so the UIImage I received is zoomed more than I expected. My question is how to convert MapView camera zoom to SnapshotCamera zoomLevel? Thanks!