如何在MKMapView上使用MKOverlayView绘制弧/曲线 [英] How to draw arc/curve line with MKOverlayView on MKMapView

查看:237
本文介绍了如何在MKMapView上使用MKOverlayView绘制弧/曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在需要帮助。
我可以使用MKPolyline和MKPolylineView绘制线条,但是如何在MKMapView上的两个坐标之间绘制圆弧或曲线?
非常感谢。

Help needed now. I can draw lines with MKPolyline and MKPolylineView, but how to draw an arc or curve lines between two coordinates on the MKMapView? Great thanks.

最终解决方案

最后,我在这里写下了这些结论,以帮助谁想要它。

如果你想:


  1. 只需在地图上绘制圆弧路径

  2. 只需在地图上绘制图像

  3. 将圆弧路径和图像组合为叠加在地图上

所以解决方案是:


  1. MKPolyline MKPolylineView 来绘制线条, MKPolygon MKPolygonView 来绘制多边形, MKCircle MKCircleView 来绘制圆圈。没人适合?弧线在哪里?哦,是的。现在真正的解决方案:您创建一个派生自 MKOverlayPathView 的自定义类并覆盖 -createPath 方法,在 -createPath 中创建一个arc使用 CGContextAddArcToPoint 或您喜欢的其他功能,并将您刚创建的路径与 MKOverlayPathView 的路径属性相关联,并完成自定义工作。然后在地图中添加MKPolyline(是!只需 MKPolyline !),然后在 -mapView:viewForOverlay:方法中创建自定义类获取该折线。然后,只需运行它,一切都按照您的意愿运行。魔法?你可以画一个 MKPolyline 作为弧线!

  2. 只是一张图片?使用 MKAnnotationView 。那已经完成了!你能行的!我相信!

  3. 在我的问题中,我想在叠加层中绘制一个带有图像的圆弧。因此,我创建了一个符合 MKOverlay 协议的自定义类,以及一个从 MKOverlayView 派生的自定义类来绘制该叠加层。一切正常,但我不能在地图上绘制任何路径!我将lineWidth设置为1,2,3,4 ...但它不起作用!啊..解决方案是用 MKRoadWidthAtZoomScale(zoomScale)功能设置线宽,你可以看到路径!这已经完成......

  1. There are MKPolyline and MKPolylineView to draw lines, MKPolygon and MKPolygonView to draw polygons, MKCircle and MKCircleView to draw circles. No one fit? Where is an arc? Oh, yes. Now the really solution: You create a custom class derived from MKOverlayPathView and override the -createPath method, in the -createPath you create an arc use CGContextAddArcToPoint or others functions you like, and associate the path you just create to the path property of MKOverlayPathView and the custom works are done. Then you add MKPolyline in the map(Yes! just MKPolyline!), Then in the -mapView:viewForOverlay: method you create the custom class take that polyline. Then, just run it, everything is runs as you wish. Magic? you can draw a MKPolyline as an arc!
  2. Just an image? Use MKAnnotationView. That's done! you can do it! I believe that!
  3. In my problem, I want to draw an arc with an image in the overlay. So I create a custom class conforms to the MKOverlay protocol, and a custom class derived from MKOverlayView to draw that overlay. Everything works fine but I can't draw any path on the map! I've set the lineWidth to 1,2,3,4... but it wasn't work! Ah..the solution is set the line width with MKRoadWidthAtZoomScale(zoomScale) function and you can see the path! That's done......

这里有一些提示:


  1. 使用Core Graphic绘制路径,而不是MapKit坐标或UIView坐标!

  2. 在CG函数中,请记住线宽应该由此函数转换: MKRoadWidthAtZoomScale(zoomScale)

  3. 希望提供帮助


推荐答案

你已经在评论中回答了自己,但我想指出每个人都在优秀的 AIMapViewWrapper 项目,其中包括示例用于在一组坐标上绘制圆弧路径的代码。在该项目中,它用于绘制平面所包含的路径,包括其下方的阴影路径(以及其他内容,例如沿该路径设置平面动画)。对于任何对此进行刺杀的人来说应该派上用场。

You answered yourself in your comment already, but I'd like to point everyone at the excellent AIMapViewWrapper project on GitHub which includes sample code for plotting an arc path over a set of coordinates. In that project it's being used to draw the path a plane takes including a shadow path underneath it (and other stuff such as animating a plane along that path). Should come in handy for anyone taking a stab at this.

这篇关于如何在MKMapView上使用MKOverlayView绘制弧/曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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