From 27f4afa38c35cc84362f971c56a000a7f085c1b4 Mon Sep 17 00:00:00 2001 From: udumft Date: Thu, 4 Jun 2020 17:11:34 +0300 Subject: [PATCH] vk-puck-location-on-resize: fixed updating Puck location on various events, including map view resizing --- MapboxNavigation/NavigationMapView.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/MapboxNavigation/NavigationMapView.swift b/MapboxNavigation/NavigationMapView.swift index c122aedd074..e2a547a9755 100644 --- a/MapboxNavigation/NavigationMapView.swift +++ b/MapboxNavigation/NavigationMapView.swift @@ -340,16 +340,20 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate { return } + let centerUserCourseView = { [weak self] in + guard let point = self?.convert(location.coordinate, toPointTo: self) else { return } + self?.userCourseView.center = point + } + if tracksUserCourse { + centerUserCourseView() + let newCamera = camera ?? MGLMapCamera(lookingAtCenter: location.coordinate, altitude: altitude, pitch: 45, heading: location.course) let function: CAMediaTimingFunction? = animated ? CAMediaTimingFunction(name: .linear) : nil setCamera(newCamera, withDuration: duration, animationTimingFunction: function, completionHandler: nil) } else { // Animate course view updates in overview mode - UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear], animations: { [weak self] in - guard let point = self?.convert(location.coordinate, toPointTo: self) else { return } - self?.userCourseView.center = point - }) + UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear], animations: centerUserCourseView) } userCourseView.update(location: location, pitch: self.camera.pitch, direction: direction, animated: animated, tracksUserCourse: tracksUserCourse)