我有点卡在这里…
我正在尝试为我的 mapbox 视图中的每个标记添加不同的图像。为了填充地图,我使用了一个查看数组的 for 循环:
for arrayInterest in dicoInterest {
let point = MGLPointAnnotation()
var latitudePoint : Double
var longitudePoint : Double
var typePoint : String
latitudePoint = (arrayInterest["latitude"] as! Double)
longitudePoint = (arrayInterest["longitude"] as! Double)
typePoint = (arrayInterest["type"] as! String)
point.coordinate = CLLocationCoordinate2D(latitude: latitudePoint, longitude: longitudePoint)
mapView.addAnnotation(point)
print("latitude : \(latitudePoint)")
print("longitude : \(longitudePoint)")
print("point : \(point)")
print("type : \(typePoint)")
}
到目前为止,一切都很好。问题是,添加我在网上找到的特定图像的唯一方法是:
func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? {
var annotationImage = mapView.dequeueReusableAnnotationImageWithIdentifier(typePoint)
var image = UIImage(named: typePoint)
image = image?.imageWithAlignmentRectInsets(UIEdgeInsetsMake(0, 0, image!.size.height/2, image!.size.width/2))
annotationImage = MGLAnnotationImage(image: image!, reuseIdentifier:"\(point)")
return annotationImage
}
我添加将其放在循环之外,因此,它不适用于每个标记。
还有另一种方法吗?