我有一个包含 FeatureCollection 的 geojson 文件。我用 GEOSwift 解析 json 并最终得到 MKPolygon 对象。
我已经设法将多边形绘制为 MKMapView 的叠加层,但性能真的很差!
我拥有的 geojson 文件包含通往世界上每个国家/地区的路径。所以我实际上不需要地图,因为我只想将多边形直接绘制到 UIView。这是我获取 MKPolygon 的代码:
func drawPolygonsFromFeatures(_ features: Features) {
var i = 0
for feature in features {
if let geometries = feature.geometries {
for geometry in geometries {
if let shapesCollection = geometry.mapShape() as? MKShapesCollection {
let shapes = shapesCollection.shapes
for shape in shapes {
if let polygon = shape as? MKPolygon {
if let identifier = feature.id as? String, self.countryDict.count > 0 {
// Set title in order to set color on country
polygon.title = self.countryDict[identifier]
}
main {
// TODO: Draw polygons on view
}
}
}
}
}
}
i += 1
}
}
我知道可以使用 UIBeizerPath 绘制形状,但我不知道如何将我的 MKPolygon 转换为可以在 UIView 上显示形状的东西。