地图显示annnotations优化

This commit is contained in:
DDIsFriend
2023-08-29 18:07:16 +08:00
parent 5450dc500b
commit dfcdee023c
5 changed files with 44 additions and 37 deletions

View File

@@ -407,20 +407,24 @@ extension VehicleMonitoringController : JXCategoryListContainerViewDelegate {
self?.preciousTableView = vc?.vehicleMonitoringListView.tableView
// annotation
self?.vehicleMonitoringView.maMapView.maMapView.setCenter(CLLocationCoordinate2D(latitude: Double(model.lat ?? "0")!, longitude: Double(model.lon ?? "0")!), animated: true)
if let lat = model.lat,let lon = model.lon {
self?.vehicleMonitoringView.maMapView.maMapView.setCenter(CLLocationCoordinate2D(latitude: Double(lat) ?? 0, longitude: Double(lon) ?? 0), animated: true)
}
// annotation
self?.vehicleMonitoringView.maMapView.maMapView.removeAnnotations(self?.mapAnnotaions)
self?.mapAnnotaions.removeAll()
for index in 0..<(vc?.models.count ?? 0) {
let model = vc?.models[index]
let coordinate = CLLocationCoordinate2D(latitude: Double(model?.lat ?? "") ?? 0, longitude: Double(model?.lon ?? "") ?? 0)
let pointAnnotation = MAPointAnnotation.init()
pointAnnotation.annotationClass = VehicleMonitoringPointAnnotation.self
pointAnnotation.coordinate = coordinate
pointAnnotation.tag = index
self?.vehicleMonitoringView.maMapView.maMapView.addAnnotation(pointAnnotation)
self?.mapAnnotaions.append(pointAnnotation)
if let _ = model?.lat,let _ = model?.lon {
let coordinate = CLLocationCoordinate2D(latitude: Double(model?.lat ?? "") ?? 0, longitude: Double(model?.lon ?? "") ?? 0)
let pointAnnotation = MAPointAnnotation.init()
pointAnnotation.annotationClass = VehicleMonitoringPointAnnotation.self
pointAnnotation.coordinate = coordinate
pointAnnotation.tag = index
self?.vehicleMonitoringView.maMapView.maMapView.addAnnotation(pointAnnotation)
self?.mapAnnotaions.append(pointAnnotation)
}
}
}
return vc
@@ -467,7 +471,6 @@ extension VehicleMonitoringController : JXCategoryViewDelegate {
}
vehicleMonitoringView.maMapView.maMapView.removeAnnotations(mapAnnotaions)
var hasSetCenter = false
for index in 0..<(mapModel?.count ?? 0) {
let model = mapModel?[index]
if model?.lat != nil && model?.lon != nil {
@@ -478,13 +481,12 @@ extension VehicleMonitoringController : JXCategoryViewDelegate {
pointAnnotation.tag = index
vehicleMonitoringView.maMapView.maMapView.addAnnotation(pointAnnotation)
mapAnnotaions.append(pointAnnotation)
if hasSetCenter == false {
hasSetCenter = true
vehicleMonitoringView.maMapView.maMapView.setCenter(coordinate, animated: true)
}
}
}
if let annotations = vehicleMonitoringView.maMapView.maMapView.annotations {
vehicleMonitoringView.maMapView.maMapView.showAnnotations(annotations, animated: true)
}
}
}