ios - Why is drawRect on MKOverlayRenderer slow -


for app, have place mkcircle annotation on mkmapview. however, circle needs moved/resized. know has been asked, e.g. moving mkcircle in mkmapview removing/adding annotation suggested behavior.

however, consider drawing being slow, user in post: smooth resizing of mkcircle. since there answers question, question seemed use yhanimatedcircleview. slow mean, when use uislider change radius of circle, redrawing sloppy , can notice tiles being used draw it.

i created small test code, overriding drawmaprect of subclasses mkoverlayrenderer. code follows:

-(void) drawmaprect:(mkmaprect)maprect           zoomscale:(mkzoomscale)zoomscale           incontext:(cgcontextref)context {     mkcircle* circleoverlay = (mkcircle*)self.overlay;      cllocationcoordinate2d point = circleoverlay.coordinate;                cgpoint locationpoint =         [self pointformappoint:mkmappointforcoordinate(point)];      cgfloat radius =         mkmappointspermeteratlatitude(circleoverlay.coordinate.latitude) *         circleoverlay.radius;      cgrect circlerect = cgrectmake(locationpoint.x - radius,                                    locationpoint.y - radius,                                    radius * 2.0, radius * 2.0);      cgcontextsavegstate(context);          cgcontextsetfillcolorwithcolor(context, [uicolor blackcolor].cgcolor);     cgcontextfillellipseinrect(context, circlerect);      cgcontextrestoregstate(context); } 

when move uislider old annotation removed , new mkcircle different radius placed , drawmaprect method gets called.

however, small example shows sloppy drawing when resizing circle.

questions:

  1. is above example entirely correct or doing wrong drawing?
  2. if example correct, why redrawing of circle when resizing slow/sloppy?

i had similar issue drawing overlay on mkmapview, issue moving circle had drawn in relation map. causing issue there being lag in movement of map compared movement in circle, looking though circle gliding on top of map opposed being fixed on map.

my solution use cadisplaylink in order synchronise drawing of mkmapview , views had added it. believe work original implementation of changing radius of circle using uislider, without implementation, can't thoroughly test this.

a code example this:

- (void)viewdidload {     self.mapupdatelink = [cadisplaylink displaylinkwithtarget:self                                                  selector:@selector(updatemapview)];     [self.mapupdatelink addtorunloop:[nsrunloop mainrunloop]                              formode:nsrunloopcommonmodes]; }  - (void)updatemapview {     cgpoint centerpoint = [self.mapview convertcoordinate:self.circleview.centercoordinate                                             topointtoview:self.view];     if (!isnan(centerpoint.x) && !isnan(centerpoint.y)) {         self.circleview.center = centerpoint;     } } 

i hope helps issue.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -