0

这就是我定义多边形特征的方式:

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)

但这不起作用。如何设置填充颜色取决于属性?

4

1 回答 1

2

如果您想根据属性字典中的颜色值设置多边形的颜色,可以使用标识函数

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

特征选择示例显示了基于值设置填充样式图层样式的其他方法。

于 2018-06-19T00:39:17.920 回答