0

我已经MGLPointFeatureCluster在我的应用程序中实现了一个并且一切都运行良好,但是当我放大时,MGLSymbolStyleLayer名称采用数组的姓氏。我尝试了一切,但仍然不想工作。

 func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
    guard let path = Bundle.main.path(forResource: "data", ofType: "geojson") else {return}
    let url = URL(fileURLWithPath: path)

    let source = MGLShapeSource(identifier: "clusteredPorts", url: url, options: [.clustered: true, .clusterRadius: icon.size.width])
    style.addSource(source)
    style.setImage(icon?.withRenderingMode(.alwaysTemplate) ?? .init(), forName: "icon")
    
    LocalFileManager().decodeFile(fileURL: url) { (results) in
        results.features.forEach { (feature) in
            let ports = MGLSymbolStyleLayer(identifier: "ports\(feature.properties.name)", source: source)
            ports.text = NSExpression(forConstantValue: feature.properties.name)
            ports.iconColor = NSExpression(forConstantValue: UIColor.red)
            ports.textColor = NSExpression(forConstantValue: UIColor.white)
            ports.predicate = NSPredicate(format: "cluster != YES")
            ports.iconAllowsOverlap = NSExpression(forConstantValue: true)
            style.addLayer(ports)
        }
    }
 }

缩放前 [1]:https ://i.stack.imgur.com/2bRz1.jpg

缩放后[2]:https ://i.stack.imgur.com/r5sZg.png

4

1 回答 1

0

所以解决方案是ports.text = NSExpression(forKeyPath: "name")

于 2020-10-05T11:46:28.223 回答