Looking for an MKOverlayPathRenderer example

半腔热情 提交于 2019-12-12 08:46:41

问题


I am trying to figure out how to use a new MKOverlayPathRenderer class.

In my app I previously used MKOverlayPathView when building with iOS 6 SDK, but it does not seem to work with iOS 7 SDK unfortunately.

So I am trying to move my app from MKOverlayPathView to MKOverlayPathRenderer, but have no success so far.

MKPolylineRenderer works OK, but MKOverlayPathRenderer does not. The code gets called, but no overlay is drawn on a map.

Does anybody have a working example for MKOverlayPathRenderer?


回答1:


First you have to make sure that you set lineWidth and strokeColor

polylineRenderer.lineWidth = 8.0f;
polylineRenderer.strokeColor = [UIColor redColor];

Then In your renderer class, you have to override -(void) createPath method

-(void) createPath{
    CGMutablePathRef path = CGPathCreateMutable();
    BOOL pathIsEmpty = YES;
    for (int i=0;i< polyline.pointCount;i++){
        CGPoint point = [self pointForMapPoint:polyline.points[i]];
        if (pathIsEmpty){
            CGPathMoveToPoint(path, nil, point.x, point.y);
            pathIsEmpty = NO;
        } else {
            CGPathAddLineToPoint(path, nil, point.x, point.y);
        }
    }

    self.path = path; //<—— don't forget this line.
}

if you want custom drawing, you would like to override this

-(void) drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context method.



来源:https://stackoverflow.com/questions/19941200/looking-for-an-mkoverlaypathrenderer-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!