Google Maps sdk for iOS中多段线的轮廓 [英] Outline of polyline in Google Maps sdk for iOS

查看:119
本文介绍了Google Maps sdk for iOS中多段线的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是在地图上显示绿色折线。但是,当地图切换到卫星视图时,绿色多段线变得不清晰。



我无法使折线的颜色改变。所以为了区分折线和背景(地图的卫星视图),我需要在折线上绘制白色轮廓。



我浏览了GMSPolyline类的文档,找不到任何可以用非常细的两条白线勾勒出折线的东西。



任何人都可以给我一些建议,告诉我怎么做到这一点? (不绘制/重叠主折线与两条边界多段线)

在你的主折线下面,从而在两侧添加一个笔划。



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

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

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

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


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)

解决方案

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;

这篇关于Google Maps sdk for iOS中多段线的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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