2

このコードを使用して地図上にテキストを表示するカスタムmapOverlayViewがあります。

- (void)drawMapRect:(MKMapRect)mapRect
          zoomScale:(MKZoomScale)zoomScale
          inContext:(CGContextRef)ctx
{
       [super drawMapRect:mapRect zoomScale:zoomScale inContext:ctx];
        NSString *t=text2display;
      CGPoint point = CGPointMake(0,30);
        CGFloat fontSize = (3 * MKRoadWidthAtZoomScale(zoomScale)); 

        UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];

        // Draw outlined text.
        CGContextSetTextDrawingMode(ctx, kCGTextStroke);
        // Make the thickness of the outline a function of the font size in use.
        CGContextSetLineWidth(ctx, fontSize/18);
        CGContextSetStrokeColorWithColor(ctx, [[UIColor blackColor] CGColor]);
        [t drawAtPoint:point withFont:font];
        CGContextRestoreGState(ctx);
       UIGraphicsPopContext();

テキストの長方形領域を作成する対応するmapOverlayもあります。

- (MKMapRect)boundingMapRect
{

MKMapRect bounds = MKMapRectMake(upperLeft.x, upperLeft.y-Z , 2000, 2000);

    return bounds;
}

常に同じレベルにとどまるには、テキストの一番下の行が必要です。したがって、描画するテキストのサイズに応じて、上記のコードのZの値を変更する必要があります。

テキストのサイズは、マップのzoomScaleによって異なります。地図のズームスケールを知ることはできますか?テキストのサイズを計算できるようにします。

4

0 に答える 0