MapAmapThemeControl.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. //
  2. // MapAmapThemeControl.swift
  3. // map_amap_ios
  4. //
  5. // Created by 诺诺诺的言 on 2025/7/22.
  6. //
  7. import Foundation
  8. import MapKit
  9. import Combine
  10. import AMapFoundationKit
  11. import MAMapKit
  12. @available(iOS 13.0, *)
  13. class MapAmapThemeControl: UIViewController {
  14. required init?(coder: NSCoder) {
  15. fatalError("init(coder:) has not been implemented")
  16. }
  17. let viewModel: MapAmapViewAndDataExchange
  18. var autonaviMap : MAMapView!
  19. //let mapView = MKMapView()
  20. private var cancellables = Set<AnyCancellable>()
  21. init(viewModel: MapAmapViewAndDataExchange) {
  22. self.viewModel = viewModel
  23. super.init(nibName: nil, bundle: nil)
  24. //mapView.showsUserLocation = false
  25. }
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28. // 1. 设置隐私(必须!)
  29. MAMapView.updatePrivacyShow(.didShow, privacyInfo: .didContain)
  30. MAMapView.updatePrivacyAgree(.didAgree)
  31. AMapServices.shared().enableHTTPS = true
  32. loadMainMapView()
  33. bindViewModel()
  34. }
  35. private func loadMainMapView() {
  36. guard AMapServices.shared().apiKey != nil else {
  37. fatalError("高德地图API Key未配置!")
  38. }
  39. autonaviMap = MAMapView(frame: view.bounds)
  40. print("地图初始化失败,请检查Key和Bundle ID--\(autonaviMap)")
  41. guard let map = autonaviMap else {
  42. print("地图初始化失败,请检查Key和Bundle ID--")
  43. return
  44. }
  45. map.delegate = self
  46. map.isRotateCameraEnabled = false
  47. map.showsCompass = false
  48. map.isRotateEnabled = false
  49. map.mapType = .standard
  50. map.showsUserLocation = false
  51. map.userTrackingMode = .none
  52. view.addSubview(map)
  53. map.translatesAutoresizingMaskIntoConstraints = false
  54. view.addSubview(map)
  55. NSLayoutConstraint.activate([
  56. map.topAnchor.constraint(equalTo: view.topAnchor),
  57. map.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  58. map.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  59. map.trailingAnchor.constraint(equalTo: view.trailingAnchor)
  60. ])
  61. }
  62. private func bindViewModel() {
  63. viewModel.$markers
  64. .receive(on: DispatchQueue.main)
  65. .sink { [weak self] markers in
  66. if let annotationsList = self?.autonaviMap.annotations {
  67. print("annotationsListsdfsdfs---\(annotationsList)");
  68. self?.autonaviMap.removeAnnotations(self?.autonaviMap.annotations)
  69. }
  70. // UIView.animate(withDuration: 0.3) {
  71. // self?.autonaviMap.addAnnotations(markers)
  72. // }
  73. var mapMarkerList = [MAPointAnnotation]();
  74. for markerItem in markers {
  75. let annotationItem : MyMAPointAnnotation = MyMAPointAnnotation(itemMarker: markerItem)
  76. annotationItem.title = markerItem.markerName;
  77. annotationItem.coordinate = markerItem.coordinate;
  78. mapMarkerList.append(annotationItem)
  79. }
  80. self?.autonaviMap.addAnnotations(mapMarkerList)
  81. // self?.autonaviMap.selectAnnotation(mapMarkerList.first, animated: true)
  82. self?.autonaviMap.setZoomLevel(20, animated: true)
  83. if !mapMarkerList.isEmpty {
  84. let selectIemt : MAPointAnnotation = mapMarkerList.first!
  85. self?.autonaviMap.setCenter(selectIemt.coordinate, animated: true)
  86. }
  87. //self?.mapView.removeAnnotations(self?.mapView.annotations ?? [])
  88. // UIView.animate(withDuration: 0.3) {
  89. // self?.mapView.addAnnotations(markers)
  90. // }
  91. }
  92. .store(in: &cancellables)
  93. viewModel.$polylines
  94. .receive(on: DispatchQueue.main)
  95. .sink { [weak self] polylines in
  96. self!.autonaviMap.removeOverlays(self!.autonaviMap.overlays)
  97. guard let self, !polylines.isEmpty else { return }
  98. // 清除旧覆盖物
  99. self.autonaviMap.removeOverlays(self.autonaviMap.overlays)
  100. var polyinesList = [MAPolyline]();
  101. for polyline in polylines {
  102. let polylineItem : MyMAPolyline = MyMAPolyline(coordinates: &polyline.points, count: UInt(polyline.points.count))
  103. polylineItem.itemPolyLine = polyline
  104. polyinesList.append(polylineItem)
  105. }
  106. // 添加新覆盖物
  107. self.autonaviMap.addOverlays(polyinesList)
  108. // 自动调整视野
  109. if let lastPolyline = polylines.last,
  110. let padding = lastPolyline.mapPadding {
  111. self.autonaviMap.showOverlays(
  112. polyinesList,
  113. edgePadding: UIEdgeInsets(
  114. top: padding.top,
  115. left: padding.left,
  116. bottom: padding.bottom,
  117. right: padding.right
  118. ),
  119. animated: true
  120. )
  121. }
  122. /*var polyinesList = [MKPolyline]();
  123. for polyline in polylines {
  124. let polylineItem : MKPolyline = polyline.polyline
  125. polylineItem.associatedLineId = polyline.id
  126. polylineItem.associatedLineType = polyline.lineType
  127. polylineItem.associatedColor = polyline.color
  128. polylineItem.associatedWidth = polyline.width
  129. polyinesList.append(polylineItem)
  130. }
  131. self?.mapView.addOverlays(polyinesList)
  132. //self?.mapView.addOverlays(polylines.map({ $0.polyline }))
  133. if let padding = polylines.last?.mapPadding {
  134. self?.mapView.fitsAllPoints(
  135. points: polylines.last?.points.compactMap({ MKMapPoint($0) }) ?? [],
  136. padding: padding.padding,
  137. animated: true
  138. )
  139. }
  140. guard let self, !polylines.isEmpty else { return }
  141. // 清除旧覆盖物
  142. self.autonaviMap.removeOverlays(self.autonaviMap.overlays)
  143. // 创建自定义Polyline类数组
  144. let customPolylines = polylines.compactMap { polyline -> CustomPolyline? in
  145. // 创建高德地图Polyline
  146. let count = UInt(polyline.points.count)
  147. guard let mapPolyline = MAPolyline(coordinates: &polyline.points , count: count) else {
  148. return nil
  149. }
  150. // 使用自定义类包装
  151. return CustomPolyline(
  152. polyline: mapPolyline,
  153. id: polyline.id,
  154. color: polyline.color,
  155. width: polyline.width
  156. )
  157. }
  158. // 添加新覆盖物
  159. self.autonaviMap.addOverlays(customPolylines.map { $0.polyline })
  160. // 自动调整视野
  161. if let lastPolyline = polylines.last,
  162. let padding = lastPolyline.mapPadding {
  163. self.autonaviMap.showOverlays(
  164. customPolylines.map { $0.polyline },
  165. edgePadding: UIEdgeInsets(
  166. top: padding.top,
  167. left: padding.left,
  168. bottom: padding.bottom,
  169. right: padding.right
  170. ),
  171. animated: true
  172. )
  173. }*/
  174. }
  175. .store(in: &cancellables)
  176. //移动至多个点的位置,并提供设置padding距离
  177. viewModel.$suitableLocation
  178. .receive(on: DispatchQueue.main)
  179. .sink{ [weak self] polylines in
  180. if let padding = polylines.last?.mapPadding {
  181. if let atMapPoint : [CLLocationCoordinate2D] = polylines.last?.points {
  182. self?.autonaviMap.moveToSuitableLocation(points: atMapPoint, padding: padding)
  183. //self?.mapView.moveToSuitableLocation(points: atMapPoint, padding: padding)
  184. }
  185. }
  186. }
  187. .store(in: &cancellables)
  188. /*viewModel.$polylines
  189. .receive(on: DispatchQueue.main)
  190. .sink { [weak self] polylines in
  191. guard let self else { return }
  192. // 清除旧覆盖物
  193. self.autonaviMap.removeOverlays(self.autonaviMap.overlays)
  194. // 空数据检查
  195. guard !polylines.isEmpty else {
  196. print("轨迹数据为空")
  197. return
  198. }
  199. // 处理每条轨迹
  200. var validPolylines: [MAPolyline] = []
  201. for polyline in polylines {
  202. // 坐标数量检查
  203. guard !polyline.points.isEmpty else {
  204. print("发现空坐标的轨迹: \(polyline.id)")
  205. continue
  206. }
  207. // 指针转换
  208. let creationResult = polyline.points.withUnsafeBufferPointer { bufferPointer -> MAPolyline? in
  209. guard let baseAddress = bufferPointer.baseAddress, bufferPointer.count > 0 else {
  210. return nil
  211. }
  212. let unsafePointer = UnsafeMutablePointer(mutating: baseAddress)
  213. return MAPolyline(
  214. coordinates: unsafePointer,
  215. count: UInt(bufferPointer.count)
  216. )
  217. }
  218. // 结果检查
  219. guard let mapPolyline = creationResult else {
  220. print("轨迹创建失败: \(polyline.id)")
  221. continue
  222. }
  223. // 绑定属性
  224. mapPolyline.associatedData = [
  225. "id": polyline.id,
  226. "color": polyline.color,
  227. "width": polyline.width
  228. ]
  229. validPolylines.append(mapPolyline)
  230. }
  231. // 添加有效轨迹
  232. guard !validPolylines.isEmpty else {
  233. print("没有有效的轨迹数据")
  234. return
  235. }
  236. self.autonaviMap.addOverlays(validPolylines)
  237. // 调整视野
  238. if let lastValid = validPolylines.last,
  239. let padding = polylines.last?.mapPadding {
  240. self.autonaviMap.showOverlays(
  241. validPolylines,
  242. edgePadding: UIEdgeInsets(
  243. top: padding.top,
  244. left: padding.left,
  245. bottom: padding.bottom,
  246. right: padding.right
  247. ),
  248. animated: true
  249. )
  250. }
  251. }
  252. .store(in: &cancellables)
  253. viewModel.$markers
  254. .receive(on: DispatchQueue.main)
  255. .sink { [weak self] markers in
  256. self?.mapView.removeAnnotations(self?.mapView.annotations ?? [])
  257. UIView.animate(withDuration: 0.3) {
  258. self?.mapView.addAnnotations(markers)
  259. }
  260. }
  261. .store(in: &cancellables)
  262. viewModel.$polylines
  263. .receive(on: DispatchQueue.main)
  264. .sink { [weak self] polylines in
  265. self?.mapView.removeOverlays(self?.mapView.overlays ?? [])
  266. var polyinesList = [MKPolyline]();
  267. for polyline in polylines {
  268. let polylineItem : MKPolyline = polyline.polyline
  269. polylineItem.associatedLineId = polyline.id
  270. polylineItem.associatedLineType = polyline.lineType
  271. polylineItem.associatedColor = polyline.color
  272. polylineItem.associatedWidth = polyline.width
  273. polyinesList.append(polylineItem)
  274. }
  275. self?.mapView.addOverlays(polyinesList)
  276. //self?.mapView.addOverlays(polylines.map({ $0.polyline }))
  277. if let padding = polylines.last?.mapPadding {
  278. self?.mapView.fitsAllPoints(
  279. points: polylines.last?.points.compactMap({ MKMapPoint($0) }) ?? [],
  280. padding: padding.padding,
  281. animated: true
  282. )
  283. }
  284. }
  285. .store(in: &cancellables)
  286. //移动至多个点的位置,并提供设置padding距离
  287. viewModel.$suitableLocation
  288. .receive(on: DispatchQueue.main)
  289. .sink{ [weak self] polylines in
  290. if let padding = polylines.last?.mapPadding {
  291. if let atMapPoint : [CLLocationCoordinate2D] = polylines.last?.points {
  292. self?.mapView.moveToSuitableLocation(points: atMapPoint, padding: padding)
  293. }
  294. }
  295. }
  296. .store(in: &cancellables)*/
  297. }
  298. /*private func bindViewModel() {
  299. viewModel.$markers
  300. .receive(on: DispatchQueue.main)
  301. .sink { [weak self] markers in
  302. self?.autonaviMap.removeAnnotations(self?.autonaviMap.annotations)
  303. var mapMarkerList = [MAPointAnnotation]();
  304. for markerItem in markers {
  305. let annotationItem : MAPointAnnotation = MAPointAnnotation()
  306. annotationItem.title = markerItem.markerName;
  307. annotationItem.coordinate = markerItem.coordinate;
  308. mapMarkerList.append(annotationItem)
  309. }
  310. self?.autonaviMap.addAnnotations(mapMarkerList)
  311. self?.autonaviMap.selectAnnotation(mapMarkerList.first, animated: true)
  312. self?.autonaviMap.setZoomLevel(15.1, animated: true)
  313. let selectIemt : MAPointAnnotation = mapMarkerList.first!
  314. self?.autonaviMap.setCenter(selectIemt.coordinate, animated: true)
  315. //self?.mapView.removeAnnotations(self?.mapView.annotations ?? [])
  316. // UIView.animate(withDuration: 0.3) {
  317. // self?.mapView.addAnnotations(markers)
  318. // }
  319. }
  320. .store(in: &cancellables)
  321. viewModel.$currentRegion
  322. .compactMap { $0 }
  323. .receive(on: DispatchQueue.main)
  324. .sink { [weak self] region in
  325. self?.mapView.setRegion(region, animated: true)
  326. }
  327. .store(in: &cancellables)
  328. viewModel.$markers
  329. .receive(on: DispatchQueue.main)
  330. .sink { [weak self] markers in
  331. self?.mapView.removeAnnotations(self?.mapView.annotations ?? [])
  332. UIView.animate(withDuration: 0.3) {
  333. self?.mapView.addAnnotations(markers)
  334. }
  335. }
  336. .store(in: &cancellables)
  337. viewModel.$polylines
  338. .receive(on: DispatchQueue.main)
  339. .sink { [weak self] polylines in
  340. self?.mapView.removeOverlays(self?.mapView.overlays ?? [])
  341. var polyinesList = [MKPolyline]();
  342. for polyline in polylines {
  343. let polylineItem : MKPolyline = polyline.polyline
  344. polylineItem.associatedLineId = polyline.id
  345. polylineItem.associatedLineType = polyline.lineType
  346. polylineItem.associatedColor = polyline.color
  347. polylineItem.associatedWidth = polyline.width
  348. polyinesList.append(polylineItem)
  349. }
  350. self?.mapView.addOverlays(polyinesList)
  351. //self?.mapView.addOverlays(polylines.map({ $0.polyline }))
  352. if let padding = polylines.last?.mapPadding {
  353. self?.mapView.fitsAllPoints(
  354. points: polylines.last?.points.compactMap({ MKMapPoint($0) }) ?? [],
  355. padding: padding.padding,
  356. animated: true
  357. )
  358. }
  359. }
  360. .store(in: &cancellables)
  361. //移动至多个点的位置,并提供设置padding距离
  362. viewModel.$suitableLocation
  363. .receive(on: DispatchQueue.main)
  364. .sink{ [weak self] polylines in
  365. if let padding = polylines.last?.mapPadding {
  366. if let atMapPoint : [CLLocationCoordinate2D] = polylines.last?.points {
  367. self?.mapView.moveToSuitableLocation(points: atMapPoint, padding: padding)
  368. }
  369. }
  370. }
  371. .store(in: &cancellables)
  372. }*/
  373. }
  374. // 自定义Polyline包装类
  375. private class CustomPolyline {
  376. let polyline: MAPolyline
  377. let id: String
  378. let color: String
  379. let width: Double
  380. init(polyline: MAPolyline, id: String, color: String, width: Double) {
  381. self.polyline = polyline
  382. self.id = id
  383. self.color = color
  384. self.width = width
  385. }
  386. }
  387. private class MyMAPointAnnotation : MAPointAnnotation {
  388. let itemMarker : ATMapMarker
  389. init(itemMarker: ATMapMarker) {
  390. self.itemMarker = itemMarker
  391. }
  392. }
  393. private class MyMAPolyline : MAPolyline {
  394. var itemPolyLine : ATMapPolyline! = nil
  395. }
  396. @available(iOS 13.0, *)
  397. extension MapAmapThemeControl : MAMapViewDelegate {
  398. //根据anntation生成对应的View。
  399. func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
  400. // guard let marker = annotation as? ATMapMarker else {
  401. // return nil
  402. // }
  403. if let myitemAnnotation = annotation as? MyMAPointAnnotation {
  404. if myitemAnnotation.itemMarker.markerType.isMapAchorPoint {
  405. let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationAnchorPointView.identifier) as? MapAnnotationAnchorPointView) ?? MapAnnotationAnchorPointView(annotation: (myitemAnnotation as MAAnnotation), reuseIdentifier: MapAnnotationAnchorPointView.identifier)
  406. annotationView!.marker = myitemAnnotation.itemMarker
  407. return annotationView
  408. } else if (myitemAnnotation.itemMarker.markerType.isTracePopup) {
  409. let annotationBubbleView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAmapPopUpWindowView.identifier) as? MapAmapPopUpWindowView) ?? MapAmapPopUpWindowView(annotation: (myitemAnnotation as MAAnnotation), reuseIdentifier: MapAmapPopUpWindowView.identifier)
  410. annotationBubbleView!.marker = myitemAnnotation.itemMarker
  411. return annotationBubbleView
  412. }
  413. let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationView.identifier) as? MapAnnotationView) ?? MapAnnotationView(annotation: (myitemAnnotation as MAAnnotation), reuseIdentifier: MapAnnotationView.identifier)
  414. annotationView!.marker = myitemAnnotation.itemMarker
  415. return annotationView
  416. }
  417. return nil
  418. /*if annotation is MyMAPointAnnotation,let myitemAnnotation = annotation as? MyMAPointAnnotation {
  419. let pointReuseIdentifier = "pointReuseIndetifier"
  420. var annotationView = mapView.dequeueReusableAnnotationView(
  421. withIdentifier: pointReuseIdentifier
  422. ) as? MAPinAnnotationView
  423. if annotationView == nil {
  424. annotationView = MAPinAnnotationView(
  425. annotation: annotation,
  426. reuseIdentifier: pointReuseIdentifier
  427. )
  428. }
  429. annotationView?.canShowCallout = true
  430. annotationView?.animatesDrop = true
  431. annotationView?.isDraggable = false
  432. annotationView?.pinColor = .purple
  433. return annotationView
  434. }
  435. return nil*/
  436. }
  437. func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! {
  438. guard let polyline = overlay as? MyMAPolyline else {
  439. return MAPolylineRenderer(polyline: overlay as? MAPolyline)
  440. }
  441. // 外层边框(粗线)
  442. // let borderRenderer = MAPolylineRenderer(polyline: polyline)
  443. // borderRenderer?.lineWidth = 8
  444. // borderRenderer?.strokeColor = UIColor(red: 0.35, green: 0.36, blue: 0.99, alpha: 1)
  445. //
  446. let renderer = MAPolylineRenderer(polyline: polyline)
  447. renderer?.lineWidth = 12
  448. renderer?.lineCapType = kMALineCapRound//kMALineCapArrow
  449. renderer?.lineJoinType = kMALineJoinRound
  450. // 设置箭头样式
  451. // 加载箭头纹理图片
  452. //normal error selected color
  453. if polyline.itemPolyLine.lineType == "normal" {
  454. renderer?.strokeImage = readImageContentFrom(imageName: "com.shishi.dingwei_bluearrow")
  455. //renderer?.strokeColor = UIColor(red: 0.27, green: 0.46, blue: 1, alpha: 1)
  456. } else if polyline.itemPolyLine.lineType == "error" {
  457. //renderer?.strokeColor = UIColor(red: 1, green: 0.43, blue: 0.43, alpha: 1)
  458. renderer?.strokeImage = readImageContentFrom(imageName: "com.shishi.dingwei_redarrow")
  459. } else if polyline.itemPolyLine.lineType == "selected" {
  460. //renderer?.strokeColor = UIColor(red: 0.08, green: 0.8, blue: 0.63, alpha: 1)
  461. renderer?.strokeImage = readImageContentFrom(imageName: "com.shishi.dingwei_greetarrow")
  462. } else if polyline.itemPolyLine.lineType == "color" {
  463. renderer?.strokeColor = UIColor(red: 0.27, green: 0.46, blue: 1, alpha: 1)
  464. renderer?.lineWidth = polyline.itemPolyLine.width
  465. renderer?.sideColor = UIColor(red: 0.35, green: 0.36, blue: 0.99, alpha: 1)
  466. renderer?.is3DArrowLine = true
  467. renderer?.fillColor = UIColor(hex: polyline.itemPolyLine.color)//UIColor.init(hex: "#4476FF");//UIColor(red: 123 / 255, green: 125 / 255, blue: 255 / 255, alpha: 1)
  468. }
  469. return renderer
  470. }
  471. private func readImageContentFrom(imageName : String) -> UIImage {
  472. if let image = UIImage(named: imageName) {
  473. return image
  474. }
  475. // 尝试从插件资源束加载
  476. let bundleURL = Bundle(for: MapAnnotationView.self).url(forResource: "map_amap_ios_image_source", withExtension: "bundle")
  477. if let bundleURL = bundleURL, let resourceBundle = Bundle(url: bundleURL) {
  478. return UIImage(named: imageName, in: resourceBundle, compatibleWith: nil) ?? UIImage()
  479. }
  480. return UIImage()
  481. }
  482. }
  483. /*
  484. @available(iOS 13.0, *)
  485. extension MapAmapThemeControl: MKMapViewDelegate {
  486. func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
  487. guard let marker = annotation as? ATMapMarker else {
  488. return nil
  489. }
  490. print("markerTypesfdsdfs---\(marker.markerType.markType)");
  491. if marker.markerType.isMapAchorPoint {
  492. let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationAnchorPointView.identifier) as? MapAnnotationAnchorPointView) ?? MapAnnotationAnchorPointView(annotation: marker, reuseIdentifier: MapAnnotationAnchorPointView.identifier)
  493. annotationView.marker = marker
  494. annotationView.prepareForDisplay()
  495. return annotationView
  496. } else if (marker.markerType.isTracePopup) {
  497. let annotationBubbleView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAmapPopUpWindowView.identifier) as? MapAmapPopUpWindowView) ?? MapAmapPopUpWindowView(annotation: marker, reuseIdentifier: MapAmapPopUpWindowView.identifier)
  498. annotationBubbleView.marker = marker
  499. annotationBubbleView.prepareForDisplay()
  500. return annotationBubbleView
  501. }
  502. let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationView.identifier) as? MapAnnotationView) ?? MapAnnotationView(annotation: marker, reuseIdentifier: MapAnnotationView.identifier)
  503. annotationView.marker = marker
  504. annotationView.prepareForDisplay()
  505. return annotationView
  506. }
  507. func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
  508. guard var marker = view.annotation as? ATMapMarker else {
  509. return
  510. }
  511. viewModel.handleMarkerTap(marker: &marker)
  512. }
  513. func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
  514. guard let polyline = overlay as? MKPolyline else {
  515. return MKOverlayRenderer(overlay: overlay)
  516. }
  517. let renderer = MapAmapArrowPolylineRenderer(polyline: polyline)
  518. renderer.lineWidth = 6
  519. //rgba(123, 125, 255, 1)
  520. renderer.strokeColor = UIColor(red: 0.27, green: 0.46, blue: 1, alpha: 1)//UIColor.init(hex: "#4476FF");//UIColor(red: 123 / 255, green: 125 / 255, blue: 255 / 255, alpha: 1)
  521. renderer.lineCap = .round
  522. renderer.lineJoin = .round
  523. // 设置箭头样式
  524. renderer.arrowColor = UIColor.white // 箭头颜色
  525. renderer.arrowSize = 12 // 增大箭头大小
  526. renderer.arrowSpacing = 50 // 减小箭头间距
  527. renderer.borderWidth = 1
  528. renderer.borderColor = UIColor(red: 0.35, green: 0.36, blue: 0.99, alpha: 1)
  529. //normal error selected color
  530. if polyline.associatedLineType == "normal" {
  531. renderer.strokeColor = UIColor(red: 0.27, green: 0.46, blue: 1, alpha: 1)
  532. } else if polyline.associatedLineType == "error" {
  533. renderer.strokeColor = UIColor(red: 1, green: 0.43, blue: 0.43, alpha: 1)
  534. } else if polyline.associatedLineType == "selected" {
  535. renderer.strokeColor = UIColor(red: 0.08, green: 0.8, blue: 0.63, alpha: 1)
  536. } else if polyline.associatedLineType == "color" {
  537. renderer.strokeColor = UIColor(hex: polyline.associatedColor ?? "#4476FF")
  538. renderer.lineWidth = polyline.associatedWidth ?? 0
  539. }
  540. return renderer
  541. }
  542. }*/