I'm displaying Annotation
s 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 Annotation
s 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.
1 Answer
Reset to default 0The problem stemmed from a third-party clustering library, which removes markers that fall outside the visible map area, thereby preventing deselection from functioning correctly.