自定义MKOverlayView线宽 [英] Custom MKOverlayView line width

查看:84
本文介绍了自定义MKOverlayView线宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的MKOverlayView,它绘制了一条简单的线条。在 drawMapRect:我设置 CGContextSetLineWidth(context,30); 完全放大后看起来很好,但是当你缩小,线条变得越来越薄。 MKOverlayView引用表示它会自动缩放到地图的缩放级别。无论我的缩放级别如何,我如何强制它绘制相同的宽度?我注意到MKPolylineView(和MKPolygonView)正确地执行了此操作...无论何时缩放以调整以保持相同的宽度,您都可以看到线条的宽度调整大小。我怎么能在我的overlayView中做到这一点?

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?

推荐答案

目前还不清楚你想要的结果。无论缩放如何,您是否希望线宽保持不变,或者您希望线条与地图视图绘制的道路宽度相同而不管缩放级别如何?

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?

为了使线宽保持不变,请尝试除以zoomScale:

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

CGContextSetLineWidth(context, (30/zoomScale));

要保持线宽与道路相同,请使用MKRoadWidthAtZoomScale:

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

这篇关于自定义MKOverlayView线宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆