如何根据多边形要素的属性值设置填充颜色?

How can I set fill color depends on attribute value of polygon feature?

我是这样定义多边形特征的:

let polygon = MGLPolygonFeature(coordinates: &coordinates, count: UInt(coordinates.count))
polygon.attributes = ["name": card.name, "identifier": card.identifier, "color": card.set.colorMode] //UIColor

let cardSource = MGLShapeSource(identifier: "cards", features: [polygon], options: [:])

let polygonLayer = MGLFillStyleLayer(identifier: "polygon-level", source: cardSource)
polygonLayer.fillColor = MGLStyleValue(rawValue: "{color}")
polygonLayer.fillOpacity = MGLStyleValue(rawValue: 0.4)

但这不起作用。如何根据属性设置填充颜色?

如果您想根据属性字典中的颜色值设置多边形的颜色,可以使用an identity function

polygonLayer.fillColor = MGLStyleValue(interpolationMode: .identity, 
                                         sourceStops: nil, 
                                         attributeName: "color",  
                                         options: nil)

feature selection 示例展示了根据值设置填充样式图层样式的其他方法。