Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I redraw overlays on a map
    primarykey
    data
    text
    <p>I have a map that creates paths and stores them in a DB. When the app is reloaded any saved paths are loaded again as a overlay It works fine until I zoom in and I see that they don't resize properly. How can I force a redraw to correct the size. I included a screen shot of what I'm seeing.</p> <p><img src="https://i.stack.imgur.com/6hTyt.jpg" alt="enter image description here"></p> <p>Here is a sample of my code. It draws subpaths for each point. Similar to a breadcrump following the users location. It's in a custom overlap class and called in </p> <pre><code>-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { for (int io=0;io&lt;OverlayList.count;io++){ CrumbPath *crumbs = [OverlayList objectAtIndex:io]; NSMutableArray *colors = [NSMutableArray arrayWithCapacity:2]; UIColor *color = [UIColor redColor]; int speedcolor; UIColor *currentColor = [UIColor colorWithRed:255/255.0f green:256/255.0f blue:0/255.0f alpha:1.0f]; UIColor *NewcurrentColor = [UIColor colorWithRed:255/255.0f green:256/255.0f blue:0/255.0f alpha:1.0f]; [colors addObject:(id)[color CGColor]]; for (int i=0;i&lt;crumbs.pointCount;i++){ NSInteger CurrentSpeed=crumbs.pointSpeed[i]; speedcolor=255-((int)CurrentSpeed*3); if (speedcolor&lt;2){ speedcolor=1; } CGMutablePathRef subpath = CGPathCreateMutable(); CGPoint point = [self pointForMapPoint:crumbs.points[i]]; if (i==0){ CGPathMoveToPoint(subpath, nil, point.x, point.y); CGPathRelease(subpath); } else { CGPoint prevPoint = [self pointForMapPoint:crumbs.points[i-1]]; CGPathMoveToPoint(subpath, nil, prevPoint.x, prevPoint.y); CGPathAddLineToPoint(subpath, nil, point.x, point.y); CGFloat lineWidth = MKRoadWidthAtZoomScale(zoomScale); CGFloat gradientLocation[2] = {0,1}; CGContextSaveGState(context); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGPoint gradientStart = prevPoint; CGPoint gradientEnd = point; CGGradientRef gradient; NewcurrentColor = [UIColor colorWithRed:255/255.0f green:speedcolor/255.0f blue:0/255.0f alpha:1.0f]; NSMutableArray *colors = [NSMutableArray arrayWithCapacity:2]; UIColor *color; [colors addObject:(id)[currentColor CGColor]]; color = NewcurrentColor; [colors addObject:(id)[color CGColor]]; gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, gradientLocation); CGPathRef pathToFill = CGPathCreateCopyByStrokingPath(subpath, NULL, lineWidth, kCGLineCapRound, kCGLineJoinBevel, 0); CGContextAddPath(context, pathToFill); //NSLog(@"%f",lineWidth); CGContextClip(context);//&lt;--clip your context after you SAVE it, important! CGContextDrawLinearGradient(context, gradient, gradientStart, gradientEnd, kCGGradientDrawsBeforeStartLocation); CGContextRestoreGState(context);//&lt;--Don't forget to restore your context. currentColor = NewcurrentColor; CGGradientRelease(gradient); CGPathRelease(pathToFill); CGColorSpaceRelease(colorSpace); CGPathRelease(subpath); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload