I'm a little bit stuck hereā¦
I'm trying to add a different image for each marker in my mapbox view. To populate the map I used a for loop that look into an array :
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)")
}
So far so good. The problem is, the only way to add a specific image I found looking online was this :
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
}
I add to put that outside the loop, and therefore, it doesnt work for each marker.
Is there another way to do that ?