-1

How can I change the color of a MGLPolyline after its already been created?

I have this code I'm trying to make work in the didSelect annotation delegate method: chosenPolyline?.polyline //= UIColor.green

I have looked here. But the answer does not work after the lines creation.

1 Answers1

1

I found that what needs to be done is you need to create a custom object for the polyline. The default MGLPolyline does not support this.

Add a custom polyline like so:

class CustomPostPolyline: MGLPolyline {
    var color: UIColor!
}

Put this in your didSelect:

self.mapView.removeAnnotation(chosenPolyline!.polyline!)
chosenPolyline!.polyline!.lineColor = UIColor.green
self.mapView.addAnnotation(chosenPolyline!.polyline!)
fphilipe
  • 9,739
  • 1
  • 40
  • 52