Как показать / добавить имя (метку) в середине MGLPolygon? - Mapbox - PullRequest
0 голосов
/ 01 июля 2019

Мне нужно показать метку в середине полигона, также пользователь может щелкнуть эту часть на карте. У меня есть ссылка на карту mapbox пример полигона Я также ссылаюсь на 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

...