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

feat: added change reason to view port update #35

Merged
merged 2 commits into from
Apr 18, 2024
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
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 @@
// 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)

Check warning on line 263 in Sources/MapLibreSwiftUI/MapViewCoordinator.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

capture of 'self' with non-sendable type 'MapViewCoordinator' in a `@Sendable` closure
}

guard !suppressCameraUpdatePropagation else {
Expand All @@ -269,18 +269,19 @@

// 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
Task { @MainActor in
updateParentCamera(mapView: mapView, reason: reason)

Check warning on line 272 in Sources/MapLibreSwiftUI/MapViewCoordinator.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

capture of 'self' with non-sendable type 'MapViewCoordinator' in a `@Sendable` closure
}
}

// 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
Loading