I'm using MapKit for SwiftUI and having an issue when conditionally rendering MapPolygons or MapPolylines. Removing these overlays after a previous render causes them to flicker sporadically in their previous location when a user zooms or moves the camera.
The relevant code is as follows:
Map(position: $cameraPosition, scope: mapScope) {
MapPolygon(coordinates: selectedTileVertices)
.stroke(
Color(red: 1.0, green: 1.0, blue: 1.0, opacity: isTileSelected ? 1.0 : 0.0),
style: StrokeStyle(lineWidth: 5, lineJoin: .round))
.foregroundStyle(selectedTile.color.opacity(0.0))
}
A polygon is rendered around a coordinate that a user selects. Upon selecting a new coordinate, a new polygon should render and the old be completely removed from the map.
In practice, the new polygon is rendered and the old initially removed, but upon zooming the old polygon flickers in and out of appearance. At some zoom levels the old polygon is completely visible again.
The crux of the problem sees to be that I am using .mapStyle(.imagery(elevation: .realistic)). Upon switching to .hybrid all flickering behavior is gone. The flickering becomes worse when doing a lot of zooming/camera movement while the old polygon is rendered and then swapping to a new polygon, and is largely nonexistent if swapping to a new polygon at the same zoom level. I imagine this has something to do with the extra rendering optimizations for satellite imagery. Any help resolving this issue would be appreciated.