我有特征集合geojson。我想为他们每个人的属性设置不同的图标基础。但我找不到如何。现在我只能为所有图层设置一个图像。是否可以为每个功能设置不同的图标?
func drawPoint(geoJson : String , id: String) {
DispatchQueue.global(qos: .background).async(execute: {
do {
let data = geoJson.data(using: .utf8)
let id = "kgm-\(id)"
guard let shapeCollectionFeature = try MGLShape(data: data!, encoding: String.Encoding.utf8.rawValue) as? MGLShapeCollectionFeature else {
fatalError("Could not cast to specified MGLShapeCollectionFeature")
}
let source = MGLShapeSource(identifier: id, shape: shapeCollectionFeature, options: nil)
self.mapView.style?.addSource(source)
let pointLayer = MGLSymbolStyleLayer(identifier: id, source: source)
let zoomStops = [
13.49: NSExpression(forConstantValue: 0),
13.5: NSExpression(forConstantValue: 1)
]
pointLayer.iconOpacity = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", zoomStops)
pointLayer.iconImageName = NSExpression(forConstantValue: id)
pointLayer.iconAllowsOverlap = NSExpression(forConstantValue: true)
self.mapView.style!.addLayer(pointLayer)
} catch {
print("GeoJSON parsing failed")
}
})
}