0

mapkit でカスタム ルート描画を作成するために、MKPolylineRenderer をサブクラス化しようとしています。カスタムマップパスラインをたどってみました

しかし、私が何をしても、私の道は地図に表示されません。私はCGに慣れていないので、単純なものが欠けているかもしれません。ポリラインから CG に変更することはできますか? それともポリラインを CGPoints に変換する必要がありますか?

私のマップビューで、サブクラスを呼び出します

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]]) {
    MKPolyline *route = overlay;
    //MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
    CustomPathOverlayRenderer *routeRenderer = [[CustomPathOverlayRenderer alloc] initWithPolyline:route];
    //routeRenderer.strokeColor = [UIColor blueColor];
    //routeRenderer.lineWidth = 4;

    return routeRenderer;
}
    return nil;
}

それから私は CustomPathOverlayRenderer.m を持っています

- (id)initWithPolyline:(MKPolyline *)polyline
{
    if (self = [super initWithPolyline:polyline])
{
    //
}
    return self;
}


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

CGMutablePathRef path = CGPathCreateMutable();
if (path != nil)
{

    CGPathRef  path2 = CGPathCreateCopy(path);

    //[line.color getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];

    //UIColor *c2 =[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:0.4];
    CGContextAddPath(context, path);

    CGContextSetStrokeColorWithColor(context, [UIColor purpleColor].CGColor);
    CGContextSetLineJoin(context, kCGLineJoinRound);
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, MKRoadWidthAtZoomScale(zoomScale));
    CGContextStrokePath(context);
    CGPathRelease(path);

    CGContextSetBlendMode(context, kCGBlendModeSourceAtop);
    CGContextAddPath(context, path2);
    CGContextSetRGBStrokeColor(context, 1.0f, 0, 0, 0.3f);
    CGContextSetLineJoin(context, kCGLineJoinRound);
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, MKRoadWidthAtZoomScale(zoomScale)/2.0f);
    CGContextStrokePath(context);
    CGPathRelease(path2);

    }

}
4

1 に答える 1