Outline of polyline in Google Maps sdk for iOS

旧街凉风 提交于 2019-12-06 05:57:40

问题


The requirement that I have is to have a green polyline to be showed on the map. But when the map is switched to satellite view, the green polyline becomes unclear.

I can't get the color of the polyline changed. So to distinguish the polyline from the background(Satellite view of the map), I need to draw white outline to the polyline.

I went through the documentation of GMSPolyline class and could not find anything using which I can outline the polyline with very thin two white lines.

Can anyone please give me suggestions as to how can I achieve this? (Without drawing/overlapping the main polyline with two boundary polylines)


回答1:


The easiest way I've found is to draw a fatter line underneath your main polyline, thereby adding a stroke to either side.

When you define your main polyline(s), add a zIndex:

polyline.strokeColor = [UIColor whiteColor];
polyline.strokeWidth = 2;
polyline.zIndex = 10;
polyline.map = mapView;

Then add another polyline with the same path, modifying your original's strokeWidth and zIndex:

GMSPolyline *stroke = [GMSPolyline polylineWithPath:samePathAsYourMainPolyline];
stroke.strokeColor = [UIColor blackColor];
stroke.strokeWidth = polyline.strokeWidth + 1;
stroke.zIndex = polyline.zIndex - 1;
stroke.map = mapView;


来源:https://stackoverflow.com/questions/23900703/outline-of-polyline-in-google-maps-sdk-for-ios

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