| | |
| | | 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.isMyLocationEnabled = false |
| | | map.settings.scrollGestures = true |
| | | map.settings.zoomGestures = true |
| | | map.isBuildingsEnabled = true |
| | | map.settings.compassButton = true |
| | | map.settings.myLocationButton = false |
| | | map.setMinZoom(15, maxZoom: 20) |
| | | map.setMinZoom(5, maxZoom: 20) |
| | | map.delegate = self |
| | | return map |
| | | }() |
| | |
| | | return line |
| | | }() |
| | | |
| | | private lazy var sharpBtn:UIButton = { |
| | | let btn = UIButton(type: .custom) |
| | | btn.backgroundColor = .white |
| | | btn.layer.shadowColor = UIColor.black.withAlphaComponent(0.3).cgColor |
| | | btn.layer.shadowOpacity = 1 |
| | | btn.layer.shadowRadius = 5 |
| | | btn.layer.shadowOffset = CGSize(width: 1, height: 1) |
| | | btn.setImage(UIImage(named: "btn_full"), for: .normal) |
| | | btn.isSelected = true |
| | | btn.layer.cornerRadius = 5 |
| | | return btn |
| | | }() |
| | | |
| | | private lazy var positionBtn:UIButton = { |
| | | let btn = UIButton(type: .custom) |
| | | btn.backgroundColor = .white |
| | | btn.layer.shadowColor = UIColor.black.withAlphaComponent(0.3).cgColor |
| | | btn.layer.shadowOpacity = 1 |
| | | btn.layer.shadowRadius = 5 |
| | | btn.layer.shadowOffset = CGSize(width: 1, height: 1) |
| | | btn.setImage(UIImage(named: "btn_nav"), for: .normal) |
| | | btn.isSelected = true |
| | | btn.layer.cornerRadius = 5 |
| | | return btn |
| | | }() |
| | | |
| | | private lazy var userLocalBtn:UIButton = { |
| | | let btn = UIButton(type: .custom) |
| | | btn.backgroundColor = .white |
| | | btn.layer.shadowColor = UIColor.black.withAlphaComponent(0.3).cgColor |
| | | btn.layer.shadowOpacity = 1 |
| | | btn.layer.shadowRadius = 5 |
| | | btn.layer.shadowOffset = CGSize(width: 1, height: 1) |
| | | btn.setImage(UIImage(named: "btn_local"), for: .normal) |
| | | btn.isSelected = true |
| | | btn.layer.cornerRadius = 5 |
| | | return btn |
| | | }() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | sharpBtn.addTarget(self, action: #selector(sharpAction), for: .touchUpInside) |
| | | positionBtn.addTarget(self, action: #selector(locationToAction), for: .touchUpInside) |
| | | userLocalBtn.addTarget(self, action: #selector(currentUserLocation), for: .touchUpInside) |
| | | } |
| | | |
| | | override func setRx() { |
| | |
| | | guard let weakSelf = self else { return } |
| | | if let tuple = noti.object as? OrderDetailModel{ |
| | | |
| | | guard let start = tuple.lonlat.first else { return } |
| | | guard let terminal = tuple.lonlat.last else { return } |
| | | var wayPointes = [String]() |
| | | weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: 30.670682, longitude: 104.078942) |
| | | // weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: start.lat, longitude: start.lat) |
| | | weakSelf.startMarker.map = weakSelf.mapView |
| | | |
| | | |
| | | weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: 30.616992, longitude: 104.070893) |
| | | // weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: terminal.lat, longitude: terminal.lat) |
| | | weakSelf.destionMarker.map = weakSelf.mapView |
| | | |
| | | |
| | | for tu in tuple.lonlat{ |
| | | switch tu.type{ |
| | | case .CheckRoom: |
| | | weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) |
| | | weakSelf.checkMarker.map = weakSelf.mapView |
| | | wayPointes.append(String(format: "%lf;%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) |
| | | case .StartPoint: |
| | | // weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: 30.670682, longitude: 104.078942) //测试 |
| | | weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lat) |
| | | weakSelf.startMarker.map = weakSelf.mapView |
| | | case .Terminal: |
| | | // weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: 30.616992, longitude: 104.070893) //测试 |
| | | weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lat) |
| | | weakSelf.destionMarker.map = weakSelf.mapView |
| | | case .Yard: |
| | | weakSelf.yardMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) |
| | | weakSelf.yardMarker.map = weakSelf.mapView |
| | | wayPointes.append(String(format: "%lf;%lf", weakSelf.yardMarker.position.latitude,weakSelf.yardMarker.position.longitude)) |
| | | } |
| | | } |
| | | |
| | | // 1 - 2: 2,3,5,12,13,14 |
| | | // 1- 3: 5,6 |
| | |
| | | //4 - 3: 9,10,11 |
| | | // 3 - 1: 11,18 |
| | | |
| | | |
| | | // index = 3 // 1:起点,2:检查站 ,3:场地,4:终点 |
| | | // if tuple.lonlat.count == 4{ |
| | | // weakSelf.yardMarker.position = CLLocationCoordinate2D(latitude: tuple.lonlat[2].lat, longitude: tuple.lonlat[2].lon) |
| | | // weakSelf.yardMarker.map = weakSelf.mapView |
| | | // wayPointes.append(String(format: "%lf;%lf", weakSelf.yardMarker.position.latitude,weakSelf.yardMarker.position.longitude)) |
| | | // |
| | | // weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tuple.lonlat[1].lat, longitude: tuple.lonlat[1].lon) |
| | | // weakSelf.checkMarker.map = weakSelf.mapView |
| | | // wayPointes.append(String(format: "%lf;%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) |
| | | // } |
| | | // |
| | | // if tuple.lonlat.count == 3{ |
| | | // weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tuple.lonlat[1].lat, longitude: tuple.lonlat[1].lon) |
| | | // weakSelf.checkMarker.map = weakSelf.mapView |
| | | // wayPointes.append(String(format: "%lf;%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) |
| | | // } |
| | | |
| | | GoogleServices.directionsLine(origin: .byCoordinates(weakSelf.startMarker.position), destination: .byCoordinates(weakSelf.destionMarker.position), waypoints: wayPointes.joined(separator: "|")).subscribe(onNext: {[weak self] data in |
| | | if let lg = data.routes.first?.legs.first{ |
| | |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | self?.mananger.startUpdatingLocation() |
| | | // self?.updateBounds(carCoordinate: tuple.0, terminalCoordinate: tuple.1) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | view.addSubview(mapView) |
| | | mapView.snp.makeConstraints { make in |
| | | make.edges.equalToSuperview() |
| | | } |
| | | |
| | | view.addSubview(sharpBtn) |
| | | sharpBtn.snp.makeConstraints { make in |
| | | make.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-5) |
| | | make.right.equalTo(-5) |
| | | make.height.width.equalTo(30) |
| | | } |
| | | |
| | | view.addSubview(positionBtn) |
| | | positionBtn.snp.makeConstraints { make in |
| | | make.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-5) |
| | | make.right.equalTo(sharpBtn.snp.left).offset(-5) |
| | | make.height.width.equalTo(30) |
| | | } |
| | | |
| | | view.addSubview(userLocalBtn) |
| | | userLocalBtn.snp.makeConstraints { make in |
| | | make.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-5) |
| | | make.right.equalTo(positionBtn.snp.left).offset(-5) |
| | | make.height.width.equalTo(30) |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @objc func sharpAction(_ btn:UIButton){ |
| | | btn.isSelected = !btn.isSelected |
| | | let img = btn.isSelected ? UIImage(named: "btn_full"):UIImage(named: "btn_full_cancel") |
| | | btn.setImage(img, for: .normal) |
| | | NotificationCenter.default.post(name: Shrink_Noti, object: btn.isSelected) |
| | | } |
| | | |
| | | @objc func locationToAction(_ btn:UIButton){ |
| | | |
| | | |
| | | let alertVC = UIAlertController(title: "Navgation", message: "Where to go?", preferredStyle: .actionSheet) |
| | | |
| | | |
| | | if checkMarker.position.latitude != 0 && checkMarker.position.longitude != 0{ |
| | | alertVC.addAction(UIAlertAction(title: "Check Point", style: .default) { [weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | MapNavigationTool.startNav(weakSelf.checkMarker.position, distanceName: weakSelf.checkMarker.title ?? "None", scheme: "BrokerDriver") |
| | | }) |
| | | } |
| | | |
| | | if yardMarker.position.latitude != 0 && yardMarker.position.longitude != 0{ |
| | | alertVC.addAction(UIAlertAction(title: "Yard Point", style: .default) { [weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | MapNavigationTool.startNav(weakSelf.yardMarker.position, distanceName: weakSelf.yardMarker.title ?? "None", scheme: "BrokerDriver") |
| | | }) |
| | | } |
| | | |
| | | alertVC.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) |
| | | alertVC.show() |
| | | } |
| | | |
| | | @objc func currentUserLocation(_ btn:UIButton){ |
| | | mapView.animate(toLocation: carMarker.position) |
| | | mapView.animate(toZoom: 7) |
| | | } |
| | | |
| | | |
| | | override func setUI() { |
| | |
| | | extension HomeDetailMapVC:CLLocationManagerDelegate{ |
| | | func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { |
| | | if let location = locations.last{ |
| | | let marker = GMSMarker(position: location.coordinate) |
| | | marker.icon = UIImage(named: "marker_car") |
| | | marker.map = mapView |
| | | carMarker = GMSMarker(position: location.coordinate) |
| | | carMarker.icon = UIImage(named: "marker_car") |
| | | carMarker.position = location.coordinate |
| | | carMarker.map = mapView |
| | | mapView.animate(toLocation: location.coordinate) |
| | | } |
| | | } |