gpt4 book ai didi

ios - FBAnnotationClustering 快速删除注释

转载 作者:行者123 更新时间:2023-11-28 06:31:32 34 4
gpt4 key购买 nike

我在我的应用程序中使用 FBAnnotationClustering cocoa pod 库来进行集群。在此 removeAllAnnotation 方法中仅在 Objective-C 中可用,但在 swift 3 中不可用。所以我发布 swift 版本以帮助像我这样的人。请在下面查看我自己的回答。

最佳答案

FBClusteringManager.swift:

open func removeAnnotations() {
if tree == nil {
return
}
lock.lock()
for annotation: MKAnnotation in allAnnotations() {
tree!.remove(annotation)
}
lock.unlock()
}

FBQuadTree.swift

func remove(_ annotation: MKAnnotation) -> Bool {
return self.remove(annotation, from: rootNode!)
}

func remove(_ annotation: MKAnnotation, from node: FBQuadTreeNode) -> Bool {

if !FBQuadTreeNode.FBBoundingBoxContainsCoordinate(node.boundingBox!, coordinate: annotation.coordinate) {
return false
}

do {
if let index = node.annotations.index(where: {self.equate(lhs: $0, rhs: annotation)}) {
node.annotations.remove(at: index)
node.count -= 1
}
} catch {
return false
}

if let northEast = node.northEast {
if self.remove(annotation, from: northEast) {
return true
}
}

if let northWest = node.northWest {
if self.remove(annotation, from: northWest) {
return true
}
}

if let southEast = node.southEast {
if self.remove(annotation, from: southEast) {
return true
}
}

if let southWest = node.southWest {
if self.remove(annotation, from: southWest) {
return true
}
}

return false
}

func equate(lhs: MKAnnotation, rhs: MKAnnotation) -> Bool{
return lhs.coordinate.latitude == rhs.coordinate.latitude
&& lhs.coordinate.longitude == rhs.coordinate.longitude

}

关于ios - FBAnnotationClustering 快速删除注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40190065/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com