Dynamically change MGLPointAnnotation image on Mapbox iOS SDK

I have an application that uses a map Mapboxon its iOS SDKand existing markers ( MGLPointAnnotation) on it.

I want to change the marker image when I select it.

MGLPointAnnotationhas no property image, and I tried calling the delegate method mapView(mapView, imageForAnnotation annotation), but it did not work.

Any idea how I can do this?

Thank!

+1
source share
1 answer
  • I am sure that it is not possible to change the annotation after adding to the map (except annotation)

  • mapView(mapView, imageForAnnotation annotation) only called when an annotation is added.

  • What you can do is use desegete didselect

    func mapView(_ mapView: MGLMapView, didSelect annotationView: MGLAnnotationView){ //code }

, . ,

func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
//code
}

: https://www.mapbox.com/ios-sdk/examples/marker-image/

0

Source: https://habr.com/ru/post/1659030/


All Articles