Skip to content

Commit

Permalink
Merge pull request #35 from Rallista/feat/change-reason-on-view-port
Browse files Browse the repository at this point in the history
feat: added change reason to view port update
  • Loading branch information
ianthetechie authored Apr 18, 2024
2 parents ac4f4d8 + 8f3689c commit 3170249
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ extension MapViewCoordinator: MLNMapViewDelegate {
// FIXME: CI complains about MainActor.assumeIsolated being unavailable before iOS 17, despite building on iOS 17.2... This is an epic hack to fix it for now. I can only assume this is an issue with Xcode pre-15.3
// TODO: We could put this in regionIsChangingWith if we calculate significant change/debounce.
Task { @MainActor in
updateViewPort(mapView: mapView)
updateViewPort(mapView: mapView, reason: reason)
}

guard !suppressCameraUpdatePropagation else {
Expand All @@ -275,12 +275,13 @@ extension MapViewCoordinator: MLNMapViewDelegate {

// MARK: MapViewPort

@MainActor private func updateViewPort(mapView: MLNMapView) {
@MainActor private func updateViewPort(mapView: MLNMapView, reason: MLNCameraChangeReason) {
// Calculate the Raw "ViewPort"
let calculatedViewPort = MapViewPort(
center: mapView.centerCoordinate,
zoom: mapView.zoomLevel,
direction: mapView.direction
direction: mapView.direction,
lastReasonForChange: CameraChangeReason(reason)
)

onViewPortChanged(calculatedViewPort)
Expand Down
13 changes: 11 additions & 2 deletions Sources/MapLibreSwiftUI/Models/MapViewPort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ public struct MapViewPort: Hashable, Equatable {
/// The current compass direction of the MapView
public let direction: CLLocationDirection

public init(center: CLLocationCoordinate2D, zoom: Double, direction: CLLocationDirection) {
/// The reason the view port was changed.
public let lastReasonForChange: CameraChangeReason?

public init(center: CLLocationCoordinate2D,
zoom: Double,
direction: CLLocationDirection,
lastReasonForChange: CameraChangeReason?)
{
self.center = center
self.zoom = zoom
self.direction = direction
self.lastReasonForChange = lastReasonForChange
}

public static func zero(zoom: Double = 10) -> MapViewPort {
MapViewPort(center: CLLocationCoordinate2D(latitude: 0, longitude: 0),
zoom: zoom,
direction: 0)
direction: 0,
lastReasonForChange: nil)
}
}

Expand Down

0 comments on commit 3170249

Please sign in to comment.