ios - MapKit - Change the Color/Stroke of a MKPolyline -


i have added overlay map follwing code:

func mapview(mapview: mkmapview!, rendererforoverlay overlay: mkoverlay!) -> mkoverlayrenderer! {     if overlay.iskindofclass(mkpolyline) {         // draw track          let polyline = overlay as! mkpolyline         let polylinerenderer = mkpolylinerenderer(overlay: polyline)         polylinerenderer.strokecolor = uicolor.bluecolor()         polylinerenderer.linewidth = 2.0         return polylinerenderer     }      return nil } 

now want change color or line width of polyline.
way found is:

func randommethod() {     ...// find apolyline     self.myoverlay = apolyline     self.map.removeoverlay(self.myoverlay)     self.map.addoverlay(self.myoverlay) } 

on mapview renderforoverlay method added this:

if (polyline == self.myoverlay) {    polylinerenderer.strokecolor = uicolor.redcolor()    polylinerenderer.linewidth = 5.0 }else{    polylinerenderer.strokecolor = uicolor.bluecolor()    polylinerenderer.linewidth = 2.0  } 

there has better way removing overlay , adding back.
know other way?

i don't think best solution found way of doing without removing/adding overlay.

i keep reference let polylinerenderer = mkpolylinerenderer(overlay: polyline) way on randommethod() can change properties need (stroke, linewidth) , execute setneedsdisplay() on renderer polyline.

is worst other approach? may be.. have add structure store renderers, way found...


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -