cluster = anotación como? CKCluster rindiendo nulo? - ClusterKit, Mapbox

stoy tratando de integrar clusterKit para Mapbox y estoy respondiendo a un problema en el que la línea de abajo sale como nula.

 if let cluster = annotation as? CKCluster, cluster.count > 1 { //nil

Esta línea está dentro del siguiente método:

 func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
¿Por qué está pasando esto¿Cómo puedo arreglarlo

Actualización2: Creo que el problema no radica aquí, el problema tiene que ver con la implementación. la forma en que la he implementado no se agrupa como debería, ¿por qué? No sé, cualquier sugerencia sería buena. Pero el reparto es nulo porque no es un clúster y no es un clúster porque no creo que el clúster funcione como debería.

He implementado todos los métodos necesarios especificados enproceso de configuración o al menos eso es lo que pensé.

Actualizar

Aquí hay un código que puede ser útil:

    var annotations = [CustomPointAnnotation]()

func setupCluster(annotations: [CustomPointAnnotation]) {
    print("obj annotations", annotations)
    let algorithm = CKNonHierarchicalDistanceBasedAlgorithm()
    mapView1.clusterManager.algorithm = algorithm
    mapView1.clusterManager.annotations = annotations
}

Otro código ...

    @nonobjc func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
    print("Change ")
    mapView.clusterManager.updateClustersIfNeeded()
}

Y este es el método completo que en la parte superior tiene el código que no se está ejecutando:

    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(" ")

}

Respuestas a la pregunta(0)

Su respuesta a la pregunta