Skip to content

Commit

Permalink
Updating zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
gbreen12 committed Apr 4, 2022
1 parent 32d8ed7 commit eae3d9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
31 changes: 13 additions & 18 deletions Sources/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,16 @@ open class MapViewCoordinator: NSObject {

super.init()

parent.viewModel.zoomToViewpoint
.sink { [unowned self] viewpoint in
self.parent.mapView.setViewpoint(viewpoint)
}
.store(in: &subscriptions)

parent.viewModel.zoomToGeometry
.sink { [unowned self] obj in
self.parent.mapView.setViewpointGeometry(obj.geometry, padding: obj.padding, completion: obj.completion)
}
.store(in: &subscriptions)

parent.viewModel.zoomToCurrentLocation
.sink { [unowned self] in
self.tryZoomToCurrentLocation()
parent.viewModel.zoom
.sink { [unowned self] type in
switch type {
case .currentLocation:
self.tryZoomToCurrentLocation()
case .geometry(let geo):
self.parent.mapView.setViewpointGeometry(geo.geometry, padding: geo.padding, completion: geo.completion)
case .viewpoint(let viewpoint):
self.parent.mapView.setViewpoint(viewpoint)
}
}
.store(in: &subscriptions)

Expand Down Expand Up @@ -163,16 +158,16 @@ open class MapViewCoordinator: NSObject {
return point.lastKnown
})
.first()
.sink(receiveCompletion: { [unowned self] completion in
.sink { [unowned self] completion in
switch completion {
case .finished:
break
case .failure:
self.parent.viewModel.errorGettingLocation = true
}
}, receiveValue: { [unowned self] location in
} receiveValue: { [unowned self] location in
self.zoomToCurrentLocation()
})
}
.store(in: &self.subscriptions)
}

Expand Down
10 changes: 7 additions & 3 deletions Sources/MapViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ import ArcGIS
import Combine
import SwiftUI

public enum ZoomType {
case geometry(geometry: GeometryZoom)
case viewpoint(viewpoint: AGSViewpoint)
case currentLocation
}

open class MapViewModel: ObservableObject {
var subscriptions = Set<AnyCancellable>()
@Published public var map: AGSMap
@Published public var graphicsOverlays: [AGSGraphicsOverlay]
@Published public var isAttributionTextVisible: Bool
@Published public var errorGettingLocation = false

public let zoomToGeometry = PassthroughSubject<GeometryZoom, Never>()
public let zoomToViewpoint = PassthroughSubject<AGSViewpoint, Never>()
public let zoomToCurrentLocation = PassthroughSubject<Void, Never>()
public let zoom = PassthroughSubject<ZoomType, Never>()
public let graphicsOverlayIdentify = PassthroughSubject<GraphicsOverlayIdentifyRequest, Never>()

public init(map: AGSMap = AGSMap(basemap: .openStreetMap()), graphicsOverlays: [AGSGraphicsOverlay] = [], isAttributionTextVisible: Bool = true) {
Expand Down

0 comments on commit eae3d9c

Please sign in to comment.