Mapbox iOS:集群的叶子有时会崩溃

问题描述

我有一个集群,里面有很多功能我有一个逻辑可以放大集群直到某个缩放级别。之后,我想获得此集群中的所有功能。大多数时候我使用

正常工作
source.leaves(of: cluster)

但有时它会因错误而崩溃: 错误:执行被中断,原因:内部c++异常断点(-4)..

我也尝试先获取所有子集群,但不知何故,子集群始终是同一个集群,但具有不同的 ID:

po cluster
<MGLPointFeatureCluster: 0x280f03740; identifier = "112",coordinate = 47.582946,12.168623,attributes = {
    "5020_only" = 0;
    cluster = 1;
    "cluster_id" = 112;
    "point_count" = 3;
    "point_count_abbreviated" = 3;
}>

(lldb) po source.children(of: cluster)
▿ 1 element
  - 0 : <MGLPointFeatureCluster: 0x280f22740; identifier = "113",attributes = {
    "5020_only" = 0;
    cluster = 1;
    "cluster_id" = 113;
    "point_count" = 3;
    "point_count_abbreviated" = 3;
}>

(lldb) po source.children(of: source.children(of: cluster).first as! MGLPointFeatureCluster)
▿ 1 element
  - 0 : <MGLPointFeatureCluster: 0x280f00700; identifier = "114",attributes = {
    "5020_only" = 0;
    cluster = 1;
    "cluster_id" = 114;
    "point_count" = 3;
    "point_count_abbreviated" = 3;
}>

(lldb) po source.children(of: source.children(of: source.children(of: cluster).first as! MGLPointFeatureCluster).first as! MGLPointFeatureCluster)
▿ 1 element
  - 0 : <MGLPointFeatureCluster: 0x280f268c0; identifier = "115",attributes = {
    "5020_only" = 0;
    cluster = 1;
    "cluster_id" = 115;
    "point_count" = 3;
    "point_count_abbreviated" = 3;
}>

(lldb) po source.children(of: source.children(of: source.children(of: source.children(of: cluster).first as! MGLPointFeatureCluster).first as! MGLPointFeatureCluster).first as! MGLPointFeatureCluster)
▿ 1 element
  - 0 : <MGLPointFeatureCluster: 0x280f0fc80; identifier = "116",attributes = {
    "5020_only" = 0;
    cluster = 1;
    "cluster_id" = 116;
    "point_count" = 3;
    "point_count_abbreviated" = 3;
}>

如果我试图获取那些孩子的叶子(不管是哪个),我总是会收到错误(崩溃)。

这是我创建的集群:

func addCluster(features _features: [MGLPointFeature]?) {
        guard let features = _features else {
            // No features
            return
        }
        
        guard let style = self.style else {
            // No style
            return
        }
        
        // Remove old style
        let all: [CyclingType] = [.bike,.raceBike,.mountainBike,.singleTrail]
        for type in all {
            // Remove old layer
            if let old = style.layer(withIdentifier: Constants.cluster_layer_unclustered + "_\(type.rawValue)") {
                style.removeLayer(old)
            }
        }
        
        if let old = style.layer(withIdentifier: Constants.cluster_layer_clustered) {
            style.removeLayer(old)
        }
        if let old = style.layer(withIdentifier: Constants.cluster_layer_clustered_number) {
            style.removeLayer(old)
        }

        //Remove old source
        if let old = style.source(withIdentifier: Constants.cluster_source) {
            style.removeSource(old)
        }

        // Add new source & style
        let source = MGLShapeSource(identifier: Constants.cluster_source,features: features,options: [.clustered: true,.clusterRadius: 50,.maximumZoomLevelForClustering: Constants.cluster_max_zoom,.clusterProperties: ["5019_only": [NSExpression(mglJSONObject: ["all",["==",["get","category"],5019]]),NSExpression(forConstantValue: "unkNown")],"5020_only": [NSExpression(mglJSONObject: ["all",5020]]),"5021_only": [NSExpression(mglJSONObject: ["all",5021]]),"5022_only": [NSExpression(mglJSONObject: ["all",5022]]),NSExpression(forConstantValue: "unkNown")]]])
        style.addSource(source)
        
        // Set iamges
        if let icon = UIImage(fromresource: "icon_map_pin_start_travel") {
            style.setimage(icon,forName: "icon_5019")
        }
        if let icon = UIImage(fromresource: "icon_map_pin_start_mountain") {
            style.setimage(icon,forName: "icon_5020")
        }
        if let icon = UIImage(fromresource: "icon_map_pin_start_singletrail") {
            style.setimage(icon,forName: "icon_5021")
        }
        if let icon = UIImage(fromresource: "icon_map_pin_start_race") {
            style.setimage(icon,forName: "icon_5022")
        }
        
        // Show unclustered features as icons. The `cluster` attribute is built into clustering-enabled
        // source features.
        if let types = UAIDManager.cyclingTypes() {
            for type in types {
                // Add new layer
                let ports = MGLSymbolStyleLayer(identifier: Constants.cluster_layer_unclustered + "_\(type.rawValue)",source: source)
                ports.iconImageName = NSExpression(forConstantValue: "icon_\(type.rawValue)")
                let predicate1 = nspredicate(format: "cluster != YES")
                let predicate2 = nspredicate(format: "category == \(type.rawValue)")
                ports.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate1,predicate2])
                ports.iconAllowsOverlap = NSExpression(forConstantValue: true)
                style.insertLayer(ports,at: self.biggestPossibleLayerIndex)
            }
        }

        // Show clustered features as circles. The `point_count` attribute is built into
        // clustering-enabled source features.
        let circlesLayer = MGLCircleStyleLayer(identifier: Constants.cluster_layer_clustered,source: source)
        circlesLayer.circleRadius = NSExpression(forConstantValue: 16)
        circlesLayer.circleOpacity = NSExpression(forConstantValue: 1.0)
        circlesLayer.circleColor = NSExpression(forConstantValue: UIColor.clientMain)
        circlesLayer.predicate = nspredicate(format: "cluster == YES")
        style.insertLayer(circlesLayer,at: self.biggestPossibleLayerIndex)
    }

有人知道这是怎么回事吗? MapBox iOS SDK 6.3.0。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...