У меня есть вид карты (mapbox) с некоторыми точками кластера, кластер организован и отображен на основе геойсона, логика кластера такова, что если у него есть соседи, они будут кластеризоваться при уменьшении карты.
Это прекрасно работает, однако мне нужно извлечь значение в пределах NSExpression
, но я не нахожу обходного пути. Есть ли общие методы для таких методов?
Я использую этот пример в качестве своей базы.
https://docs.mapbox.com/ios/maps/examples/clustering/
Я изменил это так, что размер кластера зависит от количества точек в кластере, однако, когда много точек, где-то в диапазоне от 120 точек, кластер становится слишком большим, поэтому моя причина для извлечения point_count
так что я могу использовать его, чтобы установить некоторые правила. Кроме того, если у вас есть лучшее решение моей проблемы, пожалуйста, поделитесь.
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "ports", ofType: "geojson")!)
let source = MGLShapeSource(identifier: "clusteredPorts",
url: url,
options: [.clustered: true, .clusterRadius: icon.size.width])
style.addSource(source)
// Use a template image so that we can tint it with the `iconColor` runtime styling property.
style.setImage(icon.withRenderingMode(.alwaysTemplate), forName: "icon")
// Show unclustered features as icons. The `cluster` attribute is built into clustering-enabled
// source features.
let ports = MGLSymbolStyleLayer(identifier: "ports", source: source)
ports.iconImageName = NSExpression(forConstantValue: "icon")
ports.iconColor = NSExpression(forConstantValue: UIColor.darkGray.withAlphaComponent(0.9))
ports.predicate = NSPredicate(format: "cluster != YES")
ports.iconAllowsOverlap = NSExpression(forConstantValue: true)
style.addLayer(ports)
// Color clustered features based on clustered point counts.
let stops = [
20: UIColor(red: 0, green: 124/255, blue: 1, alpha: 1),
50: UIColor(red: 0, green: 124/255, blue: 1, alpha: 1)
]
// Show clustered features as circles. The `point_count` attribute is built into
// clustering-enabled source features.
let circlesLayer = MGLCircleStyleLayer(identifier: "clusteredPorts", source: source)
circlesLayer.circleOpacity = NSExpression(forConstantValue: 0.75)
circlesLayer.circleStrokeColor = NSExpression(forConstantValue: UIColor.white.withAlphaComponent(1.0))
circlesLayer.circleStrokeWidth = NSExpression(forConstantValue: 3)
circlesLayer.circleColor = NSExpression(format: "mgl_step:from:stops:(point_count, %@, %@)", UIColor(red: 0, green: 124/255, blue: 1, alpha: 1), stops)
circlesLayer.circleRadius = NSExpression(format: "CAST(point_count / 2, 'NSNumber')")
circlesLayer.predicate = NSPredicate(format: "cluster == YES")
style.addLayer(circlesLayer)
// Label cluster circles with a layer of text indicating feature count. The value for
// `point_count` is an integer. In order to use that value for the
// `MGLSymbolStyleLayer.text` property, cast it as a string.
let numbersLayer = MGLSymbolStyleLayer(identifier: "clusteredPortsNumbers", source: source)
numbersLayer.textColor = NSExpression(forConstantValue: UIColor.white)
numbersLayer.textFontSize = NSExpression(forConstantValue: NSNumber(value: Double(icon.size.width) / 2))
numbersLayer.iconAllowsOverlap = NSExpression(forConstantValue: true)
// THIS IS WHERE I WANT TO EXTRACT THE VALUE, from "point_count" to Int.
// `numbersLayer.text = NSExpression(format: "CAST(point_count, 'NSString')")`
numbersLayer.predicate = NSPredicate(format: "cluster == YES")
style.addLayer(numbersLayer)
Я ожидаю извлечь point_count из NSExpression(format: "CAST(point_count, 'NSNumber')")
как In