From a8c2422e12becdfc3da0907ff5b589f7f86d0dd5 Mon Sep 17 00:00:00 2001
From: younger_times <841720330@qq.com>
Date: 星期六, 06 五月 2023 16:18:46 +0800
Subject: [PATCH] 完成功能

---
 BrokerDriver/Home/VC/HomeDetailMapVC.swift |   55 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/BrokerDriver/Home/VC/HomeDetailMapVC.swift b/BrokerDriver/Home/VC/HomeDetailMapVC.swift
index 3aa927e..c811473 100644
--- a/BrokerDriver/Home/VC/HomeDetailMapVC.swift
+++ b/BrokerDriver/Home/VC/HomeDetailMapVC.swift
@@ -8,6 +8,9 @@
 import UIKit
 import GoogleMaps
 
+
+let UpdateMap_Noti = Notification.Name.init("UpdateMap_Noti")
+
 class HomeDetailMapVC: BaseViewController {
 
     private var troubleBtn:UIButton!
@@ -51,6 +54,14 @@
 
     }
 
+    override func setRx() {
+        NotificationCenter.default.rx.notification(UpdateMap_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in
+            if let tuple = noti.object as? (CLLocationCoordinate2D?,CLLocationCoordinate2D?){
+                self?.updateBounds(carCoordinate: tuple.0, terminalCoordinate: tuple.1)
+            }
+        }).disposed(by: disposeBag)
+    }
+
     required init(orderId:String) {
         super.init(nibName: nil, bundle: nil)
         self.orderId = orderId
@@ -63,7 +74,6 @@
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         view.addSubview(mapView)
-        updateBounds(carCoordinate: CLLocationCoordinate2D(latitude: 30.572961, longitude: 104.166301), terminalCoordinate: CLLocationCoordinate2D(latitude: 30.572995, longitude: 104.066315))
     }
 
 
@@ -89,17 +99,30 @@
         }
     }
 
-    func updateBounds(carCoordinate:CLLocationCoordinate2D,terminalCoordinate:CLLocationCoordinate2D){
-        destionMarker.position = terminalCoordinate
-        carMarker.position = carCoordinate
-        destionMarker.map = mapView
-        carMarker.map = mapView
+    func updateBounds(carCoordinate:CLLocationCoordinate2D?,terminalCoordinate:CLLocationCoordinate2D?){
 
-        let bounds = GMSCoordinateBounds(coordinate: carCoordinate, coordinate: terminalCoordinate)
-        let update = GMSCameraUpdate.fit(bounds, with: UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30))
-        mapView.moveCamera(update)
-        updatePath(start: carCoordinate, terminal: terminalCoordinate)
+        var centerCoordiante:CLLocationCoordinate2D?
 
+        if carCoordinate != nil{
+            carMarker.position = carCoordinate!
+            carMarker.map = mapView
+            centerCoordiante = carCoordinate
+        }
+
+        if terminalCoordinate != nil{
+            destionMarker.position = terminalCoordinate!
+            destionMarker.map = mapView
+            centerCoordiante = terminalCoordinate
+        }
+
+        if carCoordinate != nil && terminalCoordinate != nil{
+            let bounds = GMSCoordinateBounds(coordinate: carCoordinate!, coordinate: terminalCoordinate!)
+            let update = GMSCameraUpdate.fit(bounds, with: UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30))
+            mapView.moveCamera(update)
+            updatePath(start: carCoordinate!, terminal: terminalCoordinate!)
+        }else if centerCoordiante != nil{
+            mapView.animate(toLocation: centerCoordiante!)
+        }
     }
 
     private func updatePath(start:CLLocationCoordinate2D,terminal:CLLocationCoordinate2D){
@@ -110,18 +133,6 @@
 
         polyline.path = path
         polyline.map = mapView
-
-
-//        let span = GMSStyleSpan(style: .gradient(from: UIColor(hexStr: "#FED703"), to: .red))
-//        polyline.spans = [span]
-
-//        GoogleServices.directionsLine(origin: GoogleServices.DirectionType.byCoordinates(start), destination: GoogleServices.DirectionType.byCoordinates(terminal)).subscribe(onNext: {data in
-//
-//
-//        }) { error in
-//
-//        }.disposed(by: disposeBag)
-
     }
 
     @objc func troubleAction(){

--
Gitblit v1.7.1