代码之家  ›  专栏  ›  技术社区  ›  Bartłomiej Semańczyk

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

  •  0
  • Bartłomiej Semańczyk  · 技术社区  · 7 年前

    这是我如何定义多边形功能的:

    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)
    

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

    1 回复  |  直到 7 年前
        1
  •  2
  •   jmkiley    7 年前

    如果要基于多边形的属性字典中的颜色值设置多边形的颜色,可以使用 an identity function .

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

    这个 feature selection 示例显示了基于值设置填充样式图层样式的其他方法。