我已经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)
}
}
}