Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI - Control over MapViewAnnotation z index #2135

Open
MaartenDEV opened this issue Feb 28, 2024 · 3 comments
Open

SwiftUI - Control over MapViewAnnotation z index #2135

MaartenDEV opened this issue Feb 28, 2024 · 3 comments

Comments

@MaartenDEV
Copy link

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.

@aleksproger
Copy link
Contributor

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.

@MaartenDEV
Copy link
Author

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)
                }

@kaspesi
Copy link

kaspesi commented Apr 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants