如何在MapKit中绘制带有外边框的叠加层?

时间:2019-06-03 10:56:10

标签: ios swift mapkit

是否可以在MapKit中使用Swift来绘制这样的叠加层?

enter image description here

我在线搜索,没有找到任何有用的建议。

1 个答案:

答案 0 :(得分:1)

我发现的最简单的方法是在主多段线下方绘制一条较粗的线,从而在主多段线的两侧添加笔触。

定义主折线时,添加一个zIndex:

mainPolyline.strokeColor = UIColor.white
mainPolyline.strokeWidth = 2
mainPolyline.zIndex = 10
mainPolyline.map = mapView

然后添加具有相同路径的另一条折线,修改原始文件的strokeWidth和zIndex:

let lowerPolyLine = GMSPolyline(path: samePathAsYourMainPolyline)
lowerPolyLine.strokeWidth = mainPolyline.strokeWidth + 1
lowerPolyLine.strokeColor = UIColor.black
lowerPolyLine.zIndex = mainPolyline.zIndex - 1
lowerPolyLine.map = mapView;

如果您使用的是地图套件,那么here是可以完全自定义的库。

希望这会有所帮助。