SwiftUI - Control over MapViewAnnotation z index
New Feature
I'd like to have control over the z Index of each MapViewAnnotation. Currently, only the .selected modifier allows us to control which annotation gets pushed to the front, but that is of no use when dealing with a larger set of annotations where the order matters. The current iOS docs (non-SwiftUI) tell us that the order of adding annotations determines their z index. Changing the order of MapViewAnnotations in a ForEvery loop does not seem to change their z index.
Hey, @MaartenDEV that's a nice suggestion actually. May you please elaborate on your specific use case and provide a code snippet with how you try to achieve it as it may help us to better understand the needs.
Hi @aleksproger, I would expect to be able to set a modifier on a MapViewAnnotation, something like 'weight', 'zIndex' or 'order', where a higher number would mean showing the annotation above annotations with lower numbers. 'zIndex' would make the most sense as that is also already a SwiftUI view modifier.
In this example, the yellow circle would appear behind the red circle.
Map(viewPort: $viewPort) {
MapViewAnnotation(coordinate: coordinates) {
Circle()
.fill(Color.red)
}
.zIndex(10)
MapViewAnnotation(coordinate: coordinates) {
Circle()
.fill(Color.yellow)
}
.zIndex(8)
}
Also have a similar use case. Would like to show icons on a map as well as text below the icon. I want the icons to always show up but the text to show up when zoomed in enough for there to be space to show them. If I allowOverlap on the map icon MapViewAnnotations, but not on the text MapViewAnnotations the text never shows up correctly -- even when zooming in.