Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

ios - Custom MKOverlayView line width

I have a custom MKOverlayView, which draws a simple line. In drawMapRect: I am setting CGContextSetLineWidth(context, 30); This looks fine when completely zoomed in, but when you zoom out, the line becomes more and more thin. The MKOverlayView reference says that it automatically scales to the map's zoom level. How can I force it to draw the same width no matter what my zoom level? I notice that MKPolylineView (and MKPolygonView) do this correctly... you can see the line's width resize whenever you zoom to adjust to keep the same width. How can I do this in my overlayView?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's not clear which result you want. Do you want the line width to remain the same regardless of the zoom or do you want the line to be same width as the roads that the map view draws regardless of zoom level?

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

CGContextSetLineWidth(context, (30/zoomScale));

To keep the line the same width as the roads, use MKRoadWidthAtZoomScale:

CGContextSetLineWidth(context, MKRoadWidthAtZoomScale(zoomScale));

You could also apply an additional scaling to the road width if you wanted:

CGContextSetLineWidth(context, 1.5*MKRoadWidthAtZoomScale(zoomScale));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...