Skip to content

Commit

Permalink
modifying code so tapped annotations contains newly selected annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiZasaurus committed Nov 2, 2022
1 parent cbc1e76 commit ca35b5f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,26 @@ public class CircleAnnotationManager: AnnotationManagerInternal {
// MARK: - User interaction handling

internal func handleQueriedFeatureIds(_ queriedFeatureIds: [String]) {
// Find if any `queriedFeatureIds` match an annotation's `id`
let tappedAnnotations = annotations.filter { queriedFeatureIds.contains($0.id) }

if tappedAnnotations.isEmpty {
guard annotations.map(\.id).contains(where: queriedFeatureIds.contains(_:)) else {
return
}

let selectedAnnotationIds = tappedAnnotations.map(\.id)
let allAnnotations: [CircleAnnotation] = annotations.map { annotation in
if selectedAnnotationIds.contains(annotation.id) {
var mutableAnnotation = annotation
mutableAnnotation.isSelected.toggle()
return mutableAnnotation
var tappedAnnotations: [CircleAnnotation] = []
var annotations: [CircleAnnotation] = []

for var annotation in self.annotations {
if queriedFeatureIds.contains(annotation.id) {
annotation.isSelected.toggle()
tappedAnnotations.append(annotation)
}
return annotation
annotations.append(annotation)
}

self.annotations = allAnnotations
self.annotations = annotations

delegate?.annotationManager(self, didDetectTappedAnnotations: tappedAnnotations)
delegate?.annotationManager(
self,
didDetectTappedAnnotations: tappedAnnotations)
}

private func createDragSourceAndLayer() {
Expand Down Expand Up @@ -302,7 +302,7 @@ public class CircleAnnotationManager: AnnotationManagerInternal {
self.annotationBeingDragged = nil

// avoid blinking annotation by waiting
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.removeDragSourceAndLayer()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,26 +556,26 @@ public class PointAnnotationManager: AnnotationManagerInternal {
// MARK: - User interaction handling

internal func handleQueriedFeatureIds(_ queriedFeatureIds: [String]) {
// Find if any `queriedFeatureIds` match an annotation's `id`
let tappedAnnotations = annotations.filter { queriedFeatureIds.contains($0.id) }

if tappedAnnotations.isEmpty {
guard annotations.map(\.id).contains(where: queriedFeatureIds.contains(_:)) else {
return
}

let selectedAnnotationIds = tappedAnnotations.map(\.id)
let allAnnotations: [PointAnnotation] = annotations.map { annotation in
if selectedAnnotationIds.contains(annotation.id) {
var mutableAnnotation = annotation
mutableAnnotation.isSelected.toggle()
return mutableAnnotation
var tappedAnnotations: [PointAnnotation] = []
var annotations: [PointAnnotation] = []

for var annotation in self.annotations {
if queriedFeatureIds.contains(annotation.id) {
annotation.isSelected.toggle()
tappedAnnotations.append(annotation)
}
return annotation
annotations.append(annotation)
}

self.annotations = allAnnotations
self.annotations = annotations

delegate?.annotationManager(self, didDetectTappedAnnotations: tappedAnnotations)
delegate?.annotationManager(
self,
didDetectTappedAnnotations: tappedAnnotations)
}

private func createDragSourceAndLayer() {
Expand Down Expand Up @@ -627,7 +627,7 @@ public class PointAnnotationManager: AnnotationManagerInternal {
let offsetPoint = offsetPointCalculator.geometry(for: translation, from: annotationBeingDragged.point) else {
return
}

self.annotationBeingDragged?.point = offsetPoint
do {
try style.updateGeoJSONSource(withId: dragSourceId, geoJSON: .feature(annotationBeingDragged.feature))
Expand All @@ -642,7 +642,7 @@ public class PointAnnotationManager: AnnotationManagerInternal {
self.annotationBeingDragged = nil

// avoid blinking annotation by waiting
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.removeDragSourceAndLayer()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,26 @@ public class PolygonAnnotationManager: AnnotationManagerInternal {
// MARK: - User interaction handling

internal func handleQueriedFeatureIds(_ queriedFeatureIds: [String]) {
// Find if any `queriedFeatureIds` match an annotation's `id`
let tappedAnnotations = annotations.filter { queriedFeatureIds.contains($0.id) }

if tappedAnnotations.isEmpty {
guard annotations.map(\.id).contains(where: queriedFeatureIds.contains(_:)) else {
return
}

let selectedAnnotationIds = tappedAnnotations.map(\.id)
let allAnnotations: [PolygonAnnotation] = annotations.map { annotation in
if selectedAnnotationIds.contains(annotation.id) {
var mutableAnnotation = annotation
mutableAnnotation.isSelected.toggle()
return mutableAnnotation
var tappedAnnotations: [PolygonAnnotation] = []
var annotations: [PolygonAnnotation] = []

for var annotation in self.annotations {
if queriedFeatureIds.contains(annotation.id) {
annotation.isSelected.toggle()
tappedAnnotations.append(annotation)
}
return annotation
annotations.append(annotation)
}

self.annotations = allAnnotations
self.annotations = annotations

delegate?.annotationManager(self, didDetectTappedAnnotations: tappedAnnotations)
delegate?.annotationManager(
self,
didDetectTappedAnnotations: tappedAnnotations)
}

private func createDragSourceAndLayer() {
Expand Down Expand Up @@ -278,7 +278,7 @@ public class PolygonAnnotationManager: AnnotationManagerInternal {
let offsetPoint = offsetPolygonCalculator.geometry(for: translation, from: annotationBeingDragged.polygon) else {
return
}

self.annotationBeingDragged?.polygon = offsetPoint
do {
try style.updateGeoJSONSource(withId: dragSourceId, geoJSON: .feature(annotationBeingDragged.feature))
Expand All @@ -293,7 +293,7 @@ public class PolygonAnnotationManager: AnnotationManagerInternal {
self.annotationBeingDragged = nil

// avoid blinking annotation by waiting
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.removeDragSourceAndLayer()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,26 @@ public class PolylineAnnotationManager: AnnotationManagerInternal {
// MARK: - User interaction handling

internal func handleQueriedFeatureIds(_ queriedFeatureIds: [String]) {
// Find if any `queriedFeatureIds` match an annotation's `id`
let tappedAnnotations = annotations.filter { queriedFeatureIds.contains($0.id) }

if tappedAnnotations.isEmpty {
guard annotations.map(\.id).contains(where: queriedFeatureIds.contains(_:)) else {
return
}

let selectedAnnotationIds = tappedAnnotations.map(\.id)
let allAnnotations: [PolylineAnnotation] = annotations.map { annotation in
if selectedAnnotationIds.contains(annotation.id) {
var mutableAnnotation = annotation
mutableAnnotation.isSelected.toggle()
return mutableAnnotation
var tappedAnnotations: [PolylineAnnotation] = []
var annotations: [PolylineAnnotation] = []

for var annotation in self.annotations {
if queriedFeatureIds.contains(annotation.id) {
annotation.isSelected.toggle()
tappedAnnotations.append(annotation)
}
return annotation
annotations.append(annotation)
}

self.annotations = allAnnotations
self.annotations = annotations

delegate?.annotationManager(self, didDetectTappedAnnotations: tappedAnnotations)
delegate?.annotationManager(
self,
didDetectTappedAnnotations: tappedAnnotations)
}

private func createDragSourceAndLayer() {
Expand Down Expand Up @@ -318,7 +318,7 @@ public class PolylineAnnotationManager: AnnotationManagerInternal {
let offsetPoint = offsetLineStringCalculator.geometry(for: translation, from: annotationBeingDragged.lineString) else {
return
}

self.annotationBeingDragged?.lineString = offsetPoint
do {
try style.updateGeoJSONSource(withId: dragSourceId, geoJSON: .feature(annotationBeingDragged.feature))
Expand All @@ -333,7 +333,7 @@ public class PolylineAnnotationManager: AnnotationManagerInternal {
self.annotationBeingDragged = nil

// avoid blinking annotation by waiting
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.removeDragSourceAndLayer()
}
}
Expand Down

0 comments on commit ca35b5f

Please sign in to comment.