如何在MGLPolygon的中间显示/添加名称(标签)? -Mapbox

时间:2019-07-01 11:27:01

标签: mapbox mapbox-ios

我需要在多边形中间显示标签,用户也可以单击地图中的该部分。 我已引用此地图框链接polygon example 我还引用了MGLPolygonFeature,但是在地图多边形中没有以下代码,因此我已经完成了MGLPolygon。

let objPolyFeature = MGLPolygonFeature.init(coordinates: &coordinates, count: UInt(coordinates.count), interiorPolygons: [ MGLPolygon.init(coordinates: &coordinates, count: UInt(coordinates.count))])
    let source = MGLShapeSource(identifier: "\(object.ioiId)", features: [objPolyFeature], options: nil)

    // Customize the route line color and width
    if let lineStyle = self.mapView.style?.layer(withIdentifier: "\(object.id)") as? MGLLineStyleLayer {
        let color = UIColor.init(hexString: object.line_color)
        lineStyle.lineColor = NSExpression(forConstantValue: color)
        lineStyle.lineWidth = NSExpression(forConstantValue: 3)
        lineStyle.lineDashPattern = NSExpression(forConstantValue: [2, 1.5])
    } else {
        let lineStyle = MGLLineStyleLayer(identifier: "\(object.id)", source: source)
        let color = UIColor.init(hexString: object.line_color)
        lineStyle.lineColor = NSExpression(forConstantValue: color)
        lineStyle.lineWidth = NSExpression(forConstantValue: 3)
        lineStyle.lineDashPattern = NSExpression(forConstantValue: [2, 1.5])
        mapView.style?.addLayer(lineStyle)
    }
    // Add the source and style layer of the route line to the map
    mapView.style?.addSource(source)

让我知道如何实现此功能。 enter image description here

0 个答案:

没有答案