Hi ,
I have following scenario where I feel performance issue.
Use-case:
I have multiple Overlays(MKOverlay) rendered on MapView, and overlay needs to refresh on point Drag(MKPinAnnotation). I have custom logic to handle drag behaviour of annotation, on annotation drag I do update the overlay. As point update, I create new overlay with updated coordinate and re-render it. iT slow down the performance after few overlay added.
Additional Notes: Performance was quite good on iOS16 but on iOS17, it lags the perforce on point drag. When I say it the performance, it point drag lags so it slow the overlay rendering.
I am using MKMapView inside SwiftUI.
I am sharing code-snippet where it re-render the overlay. Please help with issue in my code implementation.
func renderSegments(mapView: MKMapView, segmentPoint: FencePointAnnotation, renderNeeded: Bool = true) {
mapViewModel.updateFencePointOrder()
guard let activeLayer = mapViewModel.activeLayer else {
debugPrint("Invalid active layer.")
return
}
let segments = mapViewModel.activeFence.connectedSegmentsOf(vertex: segmentPoint)
// Remove existing overlay.
for overlay in mapView.overlays {
if let overlay = overlay as? FenceOverlay {
if overlay.layerId == activeLayer.layerId {
mapView.removeOverlay(overlay)
}
} else if let overlay = overlay as? FenceSegmentPolyline {
if overlay.layerId == activeLayer.layerId {
for segment in segments.values where segment.identifier == overlay.identifier {
mapView.removeOverlay(overlay)
}
}
}
}
// When vertex removed the no need to add segment
if renderNeeded {
if let segments = mapViewModel.updatedSegements(segment: segments.map({$0.key})) {
let updatedSegments = mapView.updatedSegmentsWithOffset(segments: segments, layer: activeLayer)
mapView.addOverlays(updatedSegments)
}
}
}