如何使用Mapbox SDK拉伸3D格式的多边形

时间:2019-07-19 13:13:40

标签: swift mapbox-ios

guard let style = self.mapView.style else { return }

let coordinates1 = [Flare.Location(long: -74.16693234972047, lat: 40.611947557346916), Flare.Location(long: -74.16694326727227, lat: 40.61190228031269), Flare.Location(long: -74.16698761150526, lat: 40.6119084907423), Flare.Location(long: -74.16697669398033, lat: 40.61195376688022), Flare.Location(long: -74.16693234972047, lat: 40.611947557346916)]

    var coords: [CLLocationCoordinate2D]! = []

    for coordinates in coordinates1{
        let pair = CLLocationCoordinate2D(latitude: coordinates.lat, longitude: coordinates.long)
        coords.append(pair)
    }

    let s = MGLMultiPolygon(polygons: [MGLPolygon(coordinates: coords, count: 5)])
    print(s)

    let source = MGLShapeSource(identifier: "ex-buildings", shape: s, options: nil)
    style.addSource(source)

    let layer = MGLFillExtrusionStyleLayer(identifier: "ex-buildings", source: source)
    layer.sourceLayerIdentifier = "building"

    layer.predicate = NSPredicate(format: "extrude == 'true'")

    // Set the fill extrusion height to the value for the building height attribute.
    layer.fillExtrusionHeight = NSExpression(forKeyPath: "height")
    layer.fillExtrusionOpacity = NSExpression(forConstantValue: 1)
    layer.fillExtrusionColor = NSExpression(forConstantValue: UIColor.red)

    style.addLayer(layer)

执行后,什么也没有发生,也没有出现在地图上。

0 个答案:

没有答案
相关问题