Custom MKOverlayView line width

与世无争的帅哥 提交于 2019-12-18 04:23:09

问题


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?


回答1:


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));


来源:https://stackoverflow.com/questions/5274164/custom-mkoverlayview-line-width

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