cluster = anotação como? CKCluster produzindo nada? - ClusterKit, Mapbox
Estou tentando integrar o clusterKit para o Mapbox e estou enfrentando um problema em que a linha abaixo está saindo como nul
if let cluster = annotation as? CKCluster, cluster.count > 1 { //nil
Esta linha está dentro do seguinte método:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
Por que isso está acontecendoComo posso corrigir isso?Update2: Eu acredito que o problema não está aqui, o problema tem a ver com a implementação. a maneira que eu implementei não se agrupa como deveria, por quê? Eu não sei, alguma sugestão seria legal. Mas o elenco é nulo porque não é um cluster e não é um cluster porque não acho que o cluster esteja funcionando como deveri
Eu implementei todos os métodos necessários especificados nosetup process ou pelo menos é o que eu pensav
Atualizar
Aqui estão alguns códigos que podem ser úteis:
var annotations = [CustomPointAnnotation]()
func setupCluster(annotations: [CustomPointAnnotation]) {
print("obj annotations", annotations)
let algorithm = CKNonHierarchicalDistanceBasedAlgorithm()
mapView1.clusterManager.algorithm = algorithm
mapView1.clusterManager.annotations = annotations
}
Outro código ...
@nonobjc func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
print("Change ")
mapView.clusterManager.updateClustersIfNeeded()
}
E este é o método completo que, na parte superior, possui o código que não está sendo executado:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
print(annotation," ",(annotation as? CKCluster)?.count, " also: ",annotation as? CKCluster)
if let cluster = annotation as? CKCluster, cluster.count > 1 {
print("inside if the k=cluser functionaluty")
let edgePadding = UIEdgeInsets(top: 40, left: 20, bottom: 44, right: 20)
let camera = mapView.cameraThatFitsCluster(cluster, edgePadding: edgePadding)
mapView.setCamera(camera, animated: true)
}
//zoom into the taped on annotation:
for object in arrayOfLineInformationObjects {
print(object, "<-- w0w")
let objectPolyline = "\(object.polyline!)" //dangerous to have !
let annotationPolyline = "\(annotation)" // cud be something else so maybe dont make only annotation polyline but acc were also gonna have a checl tp see if it was a poly line or annotation that u clicked on somewhoe
print(objectPolyline, "<-- object poly flower road")
print(annotation, "<-- annotaiton poly flower road")
if annotationPolyline == objectPolyline {
print("success!!")
let cam2 = mapView.cameraThatFitsShape(object.polyline!, direction: 0.0, edgePadding: .init(top: 20, left: 30, bottom: 100, right: 30))
mapView.fly(to: cam2, withDuration: 0.25, completionHandler: nil)
mapView.deselectAnnotation(annotation, animated: false)
break //will this only break the for loop or does it stop the whole function run
} else if annotationPolyline == "\(object.arrayOfPointAnnotations![0])" || annotationPolyline == "\(object.arrayOfPointAnnotations![1])" {
print("YOU HAVE TAPPED ON THIS ANNOTATION!")
let cam = mapView.cameraThatFitsShape(object.polyline!, direction: 0.0, edgePadding: .init(top: 20, left: 30, bottom: 100, right: 30))
mapView.fly(to: cam, withDuration: 0.25, completionHandler: nil)
mapView.deselectAnnotation(annotation, animated: false)
}
print("yes?") //does not print if break occurs
}
print(" ")
print(annotation, "<--") //<MGLPolyline: 0x2825375a0; count = 445; bounds = { sw = {37.3, -122.2}, ne = {37.4, -122.0}}> <--
print(annotation.coordinate, "<--") //center point of polyLine
print(annotation.hash, "<--") //cud this be the 0x2345345.... of the polyLine // its not
print(" ")
}