|
|
@@ -55,6 +55,7 @@ class MapAmapThemeControl: UIViewController {
|
|
|
}
|
|
|
|
|
|
map.delegate = self
|
|
|
+ map.logoCenter = CGPointMake(-100, 0)
|
|
|
map.isRotateCameraEnabled = false
|
|
|
map.showsCompass = false
|
|
|
map.isRotateEnabled = false
|
|
|
@@ -85,6 +86,7 @@ class MapAmapThemeControl: UIViewController {
|
|
|
// }
|
|
|
var mapMarkerList = [MAPointAnnotation]();
|
|
|
for markerItem in markers {
|
|
|
+ print("markerItemsfsfdsytp---\(markerItem.markerType)---\(String(describing: markerItem.markerName))---\(String(describing: markerItem.tags))")
|
|
|
let annotationItem : MyMAPointAnnotation = MyMAPointAnnotation(itemMarker: markerItem)
|
|
|
annotationItem.title = markerItem.markerName;
|
|
|
annotationItem.coordinate = markerItem.coordinate;
|
|
|
@@ -92,7 +94,7 @@ class MapAmapThemeControl: UIViewController {
|
|
|
}
|
|
|
self?.autonaviMap.addAnnotations(mapMarkerList)
|
|
|
// self?.autonaviMap.selectAnnotation(mapMarkerList.first, animated: true)
|
|
|
- self?.autonaviMap.setZoomLevel(20, animated: true)
|
|
|
+ //self?.autonaviMap.setZoomLevel(20, animated: true)
|
|
|
/*if !mapMarkerList.isEmpty {
|
|
|
let selectIemt : MAPointAnnotation = mapMarkerList.first!
|
|
|
self?.autonaviMap.setCenter(selectIemt.coordinate, animated: true)
|
|
|
@@ -120,6 +122,7 @@ class MapAmapThemeControl: UIViewController {
|
|
|
var polyinesList = [MAPolyline]();
|
|
|
for polyline in polylines {
|
|
|
let polylineItem : MyMAPolyline = MyMAPolyline(coordinates: &polyline.points, count: UInt(polyline.points.count))
|
|
|
+ print("polylinesfsfs---\(polyline.lineType)")
|
|
|
polylineItem.itemPolyLine = polyline
|
|
|
polyinesList.append(polylineItem)
|
|
|
}
|
|
|
@@ -141,67 +144,6 @@ class MapAmapThemeControl: UIViewController {
|
|
|
animated: true
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
- /*var polyinesList = [MKPolyline]();
|
|
|
- for polyline in polylines {
|
|
|
- let polylineItem : MKPolyline = polyline.polyline
|
|
|
- polylineItem.associatedLineId = polyline.id
|
|
|
- polylineItem.associatedLineType = polyline.lineType
|
|
|
- polylineItem.associatedColor = polyline.color
|
|
|
- polylineItem.associatedWidth = polyline.width
|
|
|
- polyinesList.append(polylineItem)
|
|
|
- }
|
|
|
- self?.mapView.addOverlays(polyinesList)
|
|
|
- //self?.mapView.addOverlays(polylines.map({ $0.polyline }))
|
|
|
- if let padding = polylines.last?.mapPadding {
|
|
|
- self?.mapView.fitsAllPoints(
|
|
|
- points: polylines.last?.points.compactMap({ MKMapPoint($0) }) ?? [],
|
|
|
- padding: padding.padding,
|
|
|
- animated: true
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- guard let self, !polylines.isEmpty else { return }
|
|
|
-
|
|
|
- // 清除旧覆盖物
|
|
|
- self.autonaviMap.removeOverlays(self.autonaviMap.overlays)
|
|
|
-
|
|
|
- // 创建自定义Polyline类数组
|
|
|
- let customPolylines = polylines.compactMap { polyline -> CustomPolyline? in
|
|
|
- // 创建高德地图Polyline
|
|
|
- let count = UInt(polyline.points.count)
|
|
|
-
|
|
|
- guard let mapPolyline = MAPolyline(coordinates: &polyline.points , count: count) else {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- // 使用自定义类包装
|
|
|
- return CustomPolyline(
|
|
|
- polyline: mapPolyline,
|
|
|
- id: polyline.id,
|
|
|
- color: polyline.color,
|
|
|
- width: polyline.width
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- // 添加新覆盖物
|
|
|
- self.autonaviMap.addOverlays(customPolylines.map { $0.polyline })
|
|
|
-
|
|
|
- // 自动调整视野
|
|
|
- if let lastPolyline = polylines.last,
|
|
|
- let padding = lastPolyline.mapPadding {
|
|
|
- self.autonaviMap.showOverlays(
|
|
|
- customPolylines.map { $0.polyline },
|
|
|
- edgePadding: UIEdgeInsets(
|
|
|
- top: padding.top,
|
|
|
- left: padding.left,
|
|
|
- bottom: padding.bottom,
|
|
|
- right: padding.right
|
|
|
- ),
|
|
|
- animated: true
|
|
|
- )
|
|
|
- }*/
|
|
|
}
|
|
|
.store(in: &cancellables)
|
|
|
|
|
|
@@ -344,6 +286,66 @@ class MapAmapThemeControl: UIViewController {
|
|
|
.store(in: &cancellables)*/
|
|
|
}
|
|
|
|
|
|
+ /*var polyinesList = [MKPolyline]();
|
|
|
+ for polyline in polylines {
|
|
|
+ let polylineItem : MKPolyline = polyline.polyline
|
|
|
+ polylineItem.associatedLineId = polyline.id
|
|
|
+ polylineItem.associatedLineType = polyline.lineType
|
|
|
+ polylineItem.associatedColor = polyline.color
|
|
|
+ polylineItem.associatedWidth = polyline.width
|
|
|
+ polyinesList.append(polylineItem)
|
|
|
+ }
|
|
|
+ self?.mapView.addOverlays(polyinesList)
|
|
|
+ //self?.mapView.addOverlays(polylines.map({ $0.polyline }))
|
|
|
+ if let padding = polylines.last?.mapPadding {
|
|
|
+ self?.mapView.fitsAllPoints(
|
|
|
+ points: polylines.last?.points.compactMap({ MKMapPoint($0) }) ?? [],
|
|
|
+ padding: padding.padding,
|
|
|
+ animated: true
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ guard let self, !polylines.isEmpty else { return }
|
|
|
+
|
|
|
+ // 清除旧覆盖物
|
|
|
+ self.autonaviMap.removeOverlays(self.autonaviMap.overlays)
|
|
|
+
|
|
|
+ // 创建自定义Polyline类数组
|
|
|
+ let customPolylines = polylines.compactMap { polyline -> CustomPolyline? in
|
|
|
+ // 创建高德地图Polyline
|
|
|
+ let count = UInt(polyline.points.count)
|
|
|
+
|
|
|
+ guard let mapPolyline = MAPolyline(coordinates: &polyline.points , count: count) else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用自定义类包装
|
|
|
+ return CustomPolyline(
|
|
|
+ polyline: mapPolyline,
|
|
|
+ id: polyline.id,
|
|
|
+ color: polyline.color,
|
|
|
+ width: polyline.width
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加新覆盖物
|
|
|
+ self.autonaviMap.addOverlays(customPolylines.map { $0.polyline })
|
|
|
+
|
|
|
+ // 自动调整视野
|
|
|
+ if let lastPolyline = polylines.last,
|
|
|
+ let padding = lastPolyline.mapPadding {
|
|
|
+ self.autonaviMap.showOverlays(
|
|
|
+ customPolylines.map { $0.polyline },
|
|
|
+ edgePadding: UIEdgeInsets(
|
|
|
+ top: padding.top,
|
|
|
+ left: padding.left,
|
|
|
+ bottom: padding.bottom,
|
|
|
+ right: padding.right
|
|
|
+ ),
|
|
|
+ animated: true
|
|
|
+ )
|
|
|
+ }*/
|
|
|
|
|
|
/*private func bindViewModel() {
|
|
|
viewModel.$markers
|
|
|
@@ -466,7 +468,9 @@ extension MapAmapThemeControl : MAMapViewDelegate {
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
+
|
|
|
if let myitemAnnotation = annotation as? MyMAPointAnnotation {
|
|
|
+ print("markerItemsfsfdsytp--AT-\(myitemAnnotation.itemMarker.markerType)---\(String(describing: myitemAnnotation.itemMarker.markerName))---\(String(describing: myitemAnnotation.itemMarker.tags))--")
|
|
|
if myitemAnnotation.itemMarker.markerType.isMapAchorPoint {
|
|
|
let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationAnchorPointView.identifier) as? MapAnnotationAnchorPointView) ?? MapAnnotationAnchorPointView(annotation: (myitemAnnotation as MAAnnotation), reuseIdentifier: MapAnnotationAnchorPointView.identifier)
|
|
|
annotationView!.marker = myitemAnnotation.itemMarker
|
|
|
@@ -476,40 +480,13 @@ extension MapAmapThemeControl : MAMapViewDelegate {
|
|
|
annotationBubbleView!.marker = myitemAnnotation.itemMarker
|
|
|
return annotationBubbleView
|
|
|
}
|
|
|
- let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationView.identifier) as? MapAnnotationView) ?? MapAnnotationView(annotation: (myitemAnnotation as MAAnnotation), reuseIdentifier: MapAnnotationView.identifier)
|
|
|
+ let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAmapMarkerNormalView.identifier) as? MapAmapMarkerNormalView) ?? MapAmapMarkerNormalView(annotation: (myitemAnnotation as MAAnnotation), reuseIdentifier: MapAmapMarkerNormalView.identifier)
|
|
|
annotationView!.marker = myitemAnnotation.itemMarker
|
|
|
return annotationView
|
|
|
}
|
|
|
return nil
|
|
|
-
|
|
|
-
|
|
|
- /*if annotation is MyMAPointAnnotation,let myitemAnnotation = annotation as? MyMAPointAnnotation {
|
|
|
-
|
|
|
-
|
|
|
- let pointReuseIdentifier = "pointReuseIndetifier"
|
|
|
- var annotationView = mapView.dequeueReusableAnnotationView(
|
|
|
- withIdentifier: pointReuseIdentifier
|
|
|
- ) as? MAPinAnnotationView
|
|
|
-
|
|
|
- if annotationView == nil {
|
|
|
- annotationView = MAPinAnnotationView(
|
|
|
- annotation: annotation,
|
|
|
- reuseIdentifier: pointReuseIdentifier
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- annotationView?.canShowCallout = true
|
|
|
- annotationView?.animatesDrop = true
|
|
|
- annotationView?.isDraggable = false
|
|
|
- annotationView?.pinColor = .purple
|
|
|
-
|
|
|
- return annotationView
|
|
|
- }
|
|
|
-
|
|
|
- return nil*/
|
|
|
}
|
|
|
|
|
|
-
|
|
|
func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! {
|
|
|
guard let polyline = overlay as? MyMAPolyline else {
|
|
|
return MAPolylineRenderer(polyline: overlay as? MAPolyline)
|
|
|
@@ -525,6 +502,7 @@ extension MapAmapThemeControl : MAMapViewDelegate {
|
|
|
renderer?.lineCapType = kMALineCapRound//kMALineCapArrow
|
|
|
renderer?.lineJoinType = kMALineJoinRound
|
|
|
|
|
|
+ print("lineTypesfsdfsdf---\(polyline.itemPolyLine.lineType)----\(polyline.itemPolyLine.lineId)")
|
|
|
// 设置箭头样式
|
|
|
// 加载箭头纹理图片
|
|
|
//normal error selected color
|
|
|
@@ -548,13 +526,54 @@ extension MapAmapThemeControl : MAMapViewDelegate {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ func mapView(_ mapView: MAMapView, didFailToLocateUserWithError error: Error?) {
|
|
|
+ guard let error = error else { return }
|
|
|
+
|
|
|
+ // 打印错误信息,便于调试
|
|
|
+ print("定位失败: \(error.localizedDescription)")
|
|
|
+
|
|
|
+ // 根据错误类型处理黑屏问题
|
|
|
+ handleLocationError(error: error as NSError)
|
|
|
+
|
|
|
+ // 即使定位失败,也显示默认地图(避免黑屏)
|
|
|
+ mapView.showsUserLocation = true // 显示用户位置(即使定位失败)
|
|
|
+ mapView.userTrackingMode = .follow // 设置跟踪模式
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private func handleLocationError(error: NSError) {
|
|
|
+ switch error.code {
|
|
|
+ case CLError.denied.rawValue:
|
|
|
+ // 权限被拒绝
|
|
|
+ showPermissionAlert()
|
|
|
+ print("权限被拒绝")
|
|
|
+
|
|
|
+ case CLError.locationUnknown.rawValue:
|
|
|
+ // 位置未知(临时错误)
|
|
|
+ print("位置未知(临时错误)")
|
|
|
+
|
|
|
+ case CLError.network.rawValue:
|
|
|
+ // 网络错误
|
|
|
+ print("网络错误")
|
|
|
+
|
|
|
+ case CLError.headingFailure.rawValue:
|
|
|
+ // 方向获取失败(不影响定位,可忽略)
|
|
|
+ print("方向获取失败,但位置可能正常")
|
|
|
+
|
|
|
+ default:
|
|
|
+ // 其他错误
|
|
|
+ print("其他错误")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private func readImageContentFrom(imageName : String) -> UIImage {
|
|
|
if let image = UIImage(named: imageName) {
|
|
|
return image
|
|
|
}
|
|
|
|
|
|
// 尝试从插件资源束加载
|
|
|
- let bundleURL = Bundle(for: MapAnnotationView.self).url(forResource: "map_amap_ios_image_source", withExtension: "bundle")
|
|
|
+ let bundleURL = Bundle(for: MapAmapMarkerNormalView.self).url(forResource: "map_amap_ios_image_source", withExtension: "bundle")
|
|
|
if let bundleURL = bundleURL, let resourceBundle = Bundle(url: bundleURL) {
|
|
|
return UIImage(named: imageName, in: resourceBundle, compatibleWith: nil) ?? UIImage()
|
|
|
}
|
|
|
@@ -562,6 +581,48 @@ extension MapAmapThemeControl : MAMapViewDelegate {
|
|
|
return UIImage()
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private func showPermissionAlert() {
|
|
|
+ let alert = UIAlertController(
|
|
|
+ title: "定位权限被拒绝",
|
|
|
+ message: "请在设置中为高德地图开启位置权限",
|
|
|
+ preferredStyle: .alert
|
|
|
+ )
|
|
|
+
|
|
|
+ alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
|
|
+ alert.addAction(UIAlertAction(title: "去设置", style: .default) { _ in
|
|
|
+ // 打开系统设置中的应用权限页面
|
|
|
+ if let url = URL(string: UIApplication.openSettingsURLString) {
|
|
|
+ UIApplication.shared.open(url)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ present(alert, animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private func showDefaultMap() {
|
|
|
+ // 如果有历史位置,使用历史位置
|
|
|
+ if let lastLocation = self.autonaviMap.userLocation.location {
|
|
|
+ let region = MACoordinateRegion(
|
|
|
+ center: lastLocation.coordinate,
|
|
|
+ span: MACoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
|
|
|
+ )
|
|
|
+ autonaviMap.setRegion(region, animated: true)
|
|
|
+ } else {
|
|
|
+ // 没有历史位置,使用默认区域(如北京)
|
|
|
+ let defaultLocation = CLLocationCoordinate2D(latitude: 39.9042, longitude: 116.4074)
|
|
|
+ let region = MACoordinateRegion(
|
|
|
+ center: defaultLocation,
|
|
|
+ span: MACoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
|
|
|
+ )
|
|
|
+ autonaviMap.setRegion(region, animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保地图可见元素正常显示
|
|
|
+ autonaviMap.isShowsBuildings = true
|
|
|
+ autonaviMap.isShowTraffic = false // 根据需要显示交通
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -584,7 +645,7 @@ extension MapAmapThemeControl: MKMapViewDelegate {
|
|
|
annotationBubbleView.prepareForDisplay()
|
|
|
return annotationBubbleView
|
|
|
}
|
|
|
- let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAnnotationView.identifier) as? MapAnnotationView) ?? MapAnnotationView(annotation: marker, reuseIdentifier: MapAnnotationView.identifier)
|
|
|
+ let annotationView = (mapView.dequeueReusableAnnotationView(withIdentifier: MapAmapMarkerNormalView.identifier) as? MapAmapMarkerNormalView) ?? MapAmapMarkerNormalView(annotation: marker, reuseIdentifier: MapAmapMarkerNormalView.identifier)
|
|
|
annotationView.marker = marker
|
|
|
annotationView.prepareForDisplay()
|
|
|
return annotationView
|