younger_times
2023-05-06 2a8d65d91258689d2f51448517245b247a08a61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    //
    //  HomeDetailMapVC.swift
    //  BrokerDriver
    //
    //  Created by 无故事王国 on 2023/4/25.
    //
 
import UIKit
import GoogleMaps
 
class HomeDetailMapVC: BaseViewController {
 
    private var troubleBtn:UIButton!
    private var orderId:String!
    private lazy var mapView:GMSMapView = {
        let map = GMSMapView()
        map.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: JQ_ScreenW * 0.6)
        map.mapType = .normal
        map.settings.scrollGestures = false
        map.settings.zoomGestures = false
        map.accessibilityElementsHidden = false
        map.isBuildingsEnabled = false
        map.settings.compassButton = true
        return map
    }()
 
    private lazy var destionMarker:GMSMarker = {
        let marker = GMSMarker()
        marker.title = "Terminal"
        marker.icon = UIImage(named: "marker_terminate")
        return marker
    }()
 
    private lazy var carMarker:GMSMarker = {
        let marker = GMSMarker()
        marker.title = "Car"
        marker.icon = UIImage(named: "marker_car")
        return marker
    }()
 
    private lazy var polyline:GMSPolyline = {
        let line = GMSPolyline()
        line.strokeWidth = 4.0
        line.strokeColor = UIColor(hexString: "#FED703")!
        line.geodesic = true
        return line
    }()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
    }
 
    required init(orderId:String) {
        super.init(nibName: nil, bundle: nil)
        self.orderId = orderId
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    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))
    }
 
 
    override func setUI() {
        super.setUI()
        troubleBtn = UIButton(type: .custom)
        troubleBtn.setTitle("Trouble", for: .normal)
        troubleBtn.cornerRadius = 6
        troubleBtn.jq_masksToBounds = false
        troubleBtn.setTitleColor(UIColor(hexStr: "#333333"), for: .normal)
        troubleBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .medium)
        troubleBtn.backgroundColor = UIColor.white
        troubleBtn.shadowColor = UIColor(hexStr: "#C2C2C2")
        troubleBtn.shadowOffset = CGSize(width: 0, height: 2)
        troubleBtn.shadowOpacity = 1
        troubleBtn.addTarget(self, action: #selector(troubleAction), for: .touchUpInside)
        view.addSubview(troubleBtn)
        troubleBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-12)
            make.width.equalTo(61)
            make.height.equalTo(24)
        }
    }
 
    func updateBounds(carCoordinate:CLLocationCoordinate2D,terminalCoordinate:CLLocationCoordinate2D){
        destionMarker.position = terminalCoordinate
        carMarker.position = carCoordinate
        destionMarker.map = mapView
        carMarker.map = mapView
 
        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)
 
    }
 
    private func updatePath(start:CLLocationCoordinate2D,terminal:CLLocationCoordinate2D){
 
        let path = GMSMutablePath()
        path.add(start)
        path.add(terminal)
 
        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(){
        let vc = TroubleListVC(orderId: orderId)
        push(vc: vc)
    }
}