我需要在多边形中间显示标签,用户也可以单击地图中的该部分。 我已引用此地图框链接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)