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

Added missing camera methods to Snapshotter #386

Merged
merged 4 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Mapbox welcomes participation and contributions from everyone.

## main

### Features ✨ and improvements 🏁

- Added `Snapshotter.coordinateBounds(for:)` and `Snapshotter.camera(for:padding:bearing:pitch:)`. ([#386](https://github.com/mapbox/mapbox-maps-ios/pull/386))

## 10.0.0-beta.20 - May 20, 2021

### Breaking changes ⚠️
Expand Down
30 changes: 30 additions & 0 deletions Sources/MapboxMaps/Snapshot/Snapshotter.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import CoreLocation

#if canImport(MapboxMapsFoundation)
julianrex marked this conversation as resolved.
Show resolved Hide resolved
import MapboxMapsFoundation
Expand Down Expand Up @@ -202,6 +203,35 @@ public class Snapshotter {

return compositeImage
}

// MARK: - Camera

/// Returns the coordinate bounds corresponding to a given `CameraOptions`
///
/// - Parameter camera: The camera for which the coordinate bounds will be returned.
/// - Returns: `CoordinateBounds` for the given `CameraOptions`
public func coordinateBounds(for camera: CameraOptions) -> CoordinateBounds {
return mapSnapshotter.coordinateBoundsForCamera(forCamera: MapboxCoreMaps.CameraOptions(camera))
}

/// Calculates a `CameraOptions` to fit a list of coordinates.
///
/// - Parameters:
/// - coordinates: Array of coordinates that should fit within the new viewport.
/// - padding: The new padding to be used by the camera.
/// - bearing: The new bearing to be used by the camera.
/// - pitch: The new pitch to be used by the camera.
/// - Returns: A `CameraOptions` that fits the provided constraints
public func camera(for coordinates: [CLLocationCoordinate2D],
padding: UIEdgeInsets,
bearing: Double?,
pitch: Double?) -> CameraOptions {
return CameraOptions(mapSnapshotter.cameraForCoordinates(
forCoordinates: coordinates.map(\.location),
padding: padding.toMBXEdgeInsetsValue(),
bearing: bearing?.NSNumber,
pitch: pitch?.NSNumber))
}
}

extension Snapshotter: ObservableProtocol {
Expand Down