Custom Line Width MKOverlayView

I have a custom MKOverlayView that draws a simple string. In drawMapRect:I set. CGContextSetLineWidth(context, 30);It looks great when it is fully enlarged, but when you zoom out, the line becomes thinner. The MKOverlayView link states that it automatically scales to the map zoom level. How can I make it draw the same width no matter what zoom level I have? I notice that MKPolylineView (and MKPolygonView) do it right ... you can see the line width changes with each zoom to adjust it to the same width. How can I do this in my overlayView?

+5
source share
1 answer

It is not clear what result you want. Do you want the line width to remain the same regardless of scaling, or do you want the line to be the same width as the tracks that the map view displays regardless of the zoom level?

To keep the line width somewhat constant no matter what, try dividing by scaling:

CGContextSetLineWidth(context, (30/zoomScale));

To make the line the same as the roads, use MKRoadWidthAtZoomScale:

CGContextSetLineWidth(context, MKRoadWidthAtZoomScale(zoomScale));

You can also apply additional scaling to the width of the road if you want:

CGContextSetLineWidth(context, 1.5*MKRoadWidthAtZoomScale(zoomScale));
+14
source

All Articles