diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-03-22 14:42:16 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-03-24 14:02:45 +0100 |
| commit | 582503b0ae8b2572371fbd77cd94595cce730fae (patch) | |
| tree | b6e8efcef2d5deec876839981c16931877ca221b | |
| parent | 884feca5e64cb5022fde33b5c76b63eb91321d2d (diff) | |
| download | mullvadvpn-582503b0ae8b2572371fbd77cd94595cce730fae.tar.xz mullvadvpn-582503b0ae8b2572371fbd77cd94595cce730fae.zip | |
Main: show location marker only in connected state.
| -rw-r--r-- | ios/MullvadVPN/ConnectViewController.swift | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ios/MullvadVPN/ConnectViewController.swift b/ios/MullvadVPN/ConnectViewController.swift index bd2f020cbf..052a017585 100644 --- a/ios/MullvadVPN/ConnectViewController.swift +++ b/ios/MullvadVPN/ConnectViewController.swift @@ -276,20 +276,37 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen private func updateLocation(animated: Bool) { switch tunnelState { case .connecting(let tunnelRelay): + removeLocationMarker() + if let tunnelRelay = tunnelRelay { setLocation(coordinate: tunnelRelay.location.geoCoordinate, animated: animated) } else { unsetLocation(animated: animated) } - case .connected(let tunnelRelay), .reconnecting(let tunnelRelay): + case .reconnecting(let tunnelRelay): + removeLocationMarker() + setLocation(coordinate: tunnelRelay.location.geoCoordinate, animated: animated) + + case .connected(let tunnelRelay): + addLocationMarker(coordinate: tunnelRelay.location.geoCoordinate) setLocation(coordinate: tunnelRelay.location.geoCoordinate, animated: animated) case .disconnected, .disconnecting, .pendingReconnect: + removeLocationMarker() unsetLocation(animated: animated) } } + private func addLocationMarker(coordinate: CLLocationCoordinate2D) { + locationMarker.coordinate = coordinate + mainContentView.mapView.addAnnotation(locationMarker) + } + + private func removeLocationMarker() { + mainContentView.mapView.removeAnnotation(locationMarker) + } + private func setLocation(coordinate: CLLocationCoordinate2D, animated: Bool) { if let lastLocation = self.lastLocation, coordinate.approximatelyEqualTo(lastLocation) { return @@ -298,8 +315,6 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen let markerOffset = locationMarkerOffset() let region = computeCoordinateRegion(centerCoordinate: coordinate, centerOffsetInPoints: markerOffset) - locationMarker.coordinate = coordinate - mainContentView.mapView.addAnnotation(locationMarker) mainContentView.mapView.setRegion(region, animated: animated) self.lastLocation = coordinate @@ -313,7 +328,6 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen let span = MKCoordinateSpan(latitudeDelta: 90, longitudeDelta: 90) let region = MKCoordinateRegion(center: coordinate, span: span) - mainContentView.mapView.removeAnnotation(locationMarker) mainContentView.mapView.setRegion(region, animated: animated) self.lastLocation = coordinate |
