最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Why does Map Annotation deselection does not work when tapping on empty map are while selected Annotation not visible? -

programmeradmin7浏览0评论

I'm displaying Annotations on a SwiftUI.Map view and I'm seeing a strange behaviour that I'm not able to remedy.

When I tap on an Annotation, it get's selected and selectionId is se to whatever UUID the the selection has. While the selected item is still within the bounds of the Map (still visible) tapping anywhere on the Map causes the Annotation to be deselected (as expected). Performing the same action while the selected Annotation is out of Map bounds (not visible) does not result in deselection. I checked using Maps.app and deselection works both while selected markers are on/off screen.

Does anyone have any ideas why I'm unable to deselect?

Code:

struct TestMarker: Identifiable {
    let id: UUID
    let coordinate: CLLocationCoordinate2D
}
struct SomeView: View {
    @State var selectionId: UUID?
    var markers: [TestMarker]
    var body: some View {

        Map(selection: $selectionId) {
            ForEach(markers) { marker in
                Annotation(
                    "",
                    coordinate: marker.coordinate
                ) {
                    Text("\(marker.id)")
                }
            }
        }
    }
}

Moved Annotation out of visible map bounds and tapped on empty map area. Expected deselection, however that did not happen.

I'm displaying Annotations on a SwiftUI.Map view and I'm seeing a strange behaviour that I'm not able to remedy.

When I tap on an Annotation, it get's selected and selectionId is se to whatever UUID the the selection has. While the selected item is still within the bounds of the Map (still visible) tapping anywhere on the Map causes the Annotation to be deselected (as expected). Performing the same action while the selected Annotation is out of Map bounds (not visible) does not result in deselection. I checked using Maps.app and deselection works both while selected markers are on/off screen.

Does anyone have any ideas why I'm unable to deselect?

Code:

struct TestMarker: Identifiable {
    let id: UUID
    let coordinate: CLLocationCoordinate2D
}
struct SomeView: View {
    @State var selectionId: UUID?
    var markers: [TestMarker]
    var body: some View {

        Map(selection: $selectionId) {
            ForEach(markers) { marker in
                Annotation(
                    "",
                    coordinate: marker.coordinate
                ) {
                    Text("\(marker.id)")
                }
            }
        }
    }
}

Moved Annotation out of visible map bounds and tapped on empty map area. Expected deselection, however that did not happen.

Share Improve this question asked Mar 14 at 21:20 RandomUsernameRandomUsername 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The problem stemmed from a third-party clustering library, which removes markers that fall outside the visible map area, thereby preventing deselection from functioning correctly.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论