折线类为 bmkpolyline,由一组经纬度坐标组成,并以有序序列形式建立一系列的线段。
bmkmapview*mapview =[[bmkmapview alloc]initwithframe:self.view.bounds];mapview.delegate= self;[self.view addsubview:mapview];
// 添加折线覆盖物cllocationcoordinate2d coords[5]={0};coords[0]=cllocationcoordinate2dmake(39.968,116.260);coords[1]=cllocationcoordinate2dmake(39.912,116.324);coords[2]=cllocationcoordinate2dmake(39.968,116.373);coords[3]=cllocationcoordinate2dmake(39.912,116.439);coords[4]=cllocationcoordinate2dmake(39.968,116.490);bmkpolyline*polyline =[bmkpolyline polylinewithcoordinates:coors count:5];[_mapview addoverlay:polyline];
-(bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id <bmkoverlay>)overlay{if([overlay iskindofclass:[bmkpolylineclass]]){bmkpolylineview*polylineview =[[bmkpolylineview alloc] initwithpolyline:overlay];//设置polylineview的画笔颜色为蓝色polylineview.strokecolor=[[uicolor alloc] initwithred:19/255.0green:107/255.0blue:251/255.0alpha:1.0];//设置polylineview的画笔宽度为16polylineview.linewidth=16;//圆点虚线,v5.0.0新增// polylineview.linedashtype = kbmklinedashtypedot;//方块虚线,v5.0.0新增// polylineview.linedashtype = kbmklinedashtypesquare;return polylineview;}return nil;}
效果如图:
ios地图sdk支持大地曲线绘制能力。
cllocationcoordinate2d coords[2]={0};coords[1]=cllocationcoordinate2dmake(36.53,-121.47);coords[0]=cllocationcoordinate2dmake(22.33,114);bmkgeodesicline*geodesicline =[bmkgeodesicline geodesiclinewithcoordinates:coords count:2];// 若经度跨180,则须设置linedirectioncross180参数_geodesicline.linedirectioncross180= kbmklinedirectioncross180typewest_to_east;[_mapview addoverlay:geodesicline];
-(bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id<bmkoverlay>)overlay {if([overlay iskindofclass:[bmkgeodesiclineclass]]){bmkgeodesiclineview*geodesicview =[[bmkgeodesiclineview alloc] initwithgeodesicline:overlay];geodesicview.strokecolor=[uicolor colorwithred:0green:0blue:1alpha:1];geodesicview.linewidth=6;geodesicview.linedashtype= kbmklinedashtypedot;return geodesicview;}return nil;}
效果如图:
ios地图sdk支持渐变线绘制能力。
cllocationcoordinate2d coords[5]={0};coords[0]=cllocationcoordinate2dmake(39.965,116.404);coords[1]=cllocationcoordinate2dmake(39.925,116.454);coords[2]=cllocationcoordinate2dmake(39.955,116.494);coords[3]=cllocationcoordinate2dmake(39.905,116.554);coords[4]=cllocationcoordinate2dmake(39.965,116.604);// 构建分段渐变颜色索引数组nsarray*drawindexs =[nsarray arraywithobjects:[nsnumber numberwithint:0],[nsnumber numberwithint:1],[nsnumber numberwithint:2],[nsnumber numberwithint:3], nil];bmkgradientline*gradientline =[bmkgradientline gradientlinewithcoordinates:coords count:5drawindexs:drawindexs];[_mapview addoverlay:gradientline];
-(__kindof bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id<bmkoverlay>)overlay {if([overlay iskindofclass:[bmkgradientlineclass]]){// 初始化一个overlay并返回相应的bmkgradientlineview的实例bmkgradientlineview*gradientlineview =[[bmkgradientlineview alloc] initwithgradientline:overlay];// 渐变线颜色数组gradientlineview.strokecolors=[nsarray arraywithobjects:[[uicolor alloc] initwithred:1green:0blue:0alpha:1],[[uicolor alloc] initwithred:1green:1blue:0alpha:0.5],[[uicolor alloc] initwithred:0green:0blue:1alpha:1],[[uicolor alloc] initwithred:0green:1blue:0alpha:1],nil];// 画笔宽度为12gradientlineview.linewidth=12;return gradientlineview;}return nil;}
效果如图:
ios地图sdk支持折线多段颜色绘制能力。
cllocationcoordinate2d coords[5]={0};coords[0]=cllocationcoordinate2dmake(39.968,116.260);coords[1]=cllocationcoordinate2dmake(39.912,116.324);coords[2]=cllocationcoordinate2dmake(39.968,116.373);coords[3]=cllocationcoordinate2dmake(39.912,116.439);coords[4]=cllocationcoordinate2dmake(39.968,116.490);//构建分段颜色索引数组nsarray*drawindexs =[nsarray arraywithobjects:[nsnumber numberwithint:0],[nsnumber numberwithint:1],[nsnumber numberwithint:2],[nsnumber numberwithint:3], nil];// 构造分段折线colorfulpolyline =[bmkmultipolyline multipolylinewithcoordinates:coords count:5drawindexs:colorindexs];[_mapview addoverlay:colorfulpolyline];
//根据overlay生成对应的view-(__kindof bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id <bmkoverlay>)overlay {if([overlay iskindofclass:[bmkmultipolylineclass]]){bmkmulticolorpolylineview*colorfulpolylineview =[[bmkmulticolorpolylineview alloc] initwithmultipolyline:overlay];// 设置polylineview的画笔宽度为12colorfulpolylineview.linewidth=12;colorfulpolylineview.colors=[nsarray arraywithobjects:[[uicolor alloc] initwithred:246/255.0green:57/255.0blue:57/255.0alpha:1.0],[[uicolor alloc] initwithred:253/255.0green:173/255.0blue:42/255.0alpha:1.0],[[uicolor alloc] initwithred:28/255.0green:188/255.0blue:82/255.0alpha:1.0],[[uicolor alloc] initwithred:19/255.0green:107/255.0blue:251/255.0alpha:1.0],nil];// 设置头尾处圆帽样式,v5.0.0新增colorfulpolylineview.linecaptype= kbmklinecapround;return colorfulpolylineview;}return nil;}
效果如图:
ios地图sdk支持折线分段颜色绘制能力。
纹理素材格式:纹理图宽高片须是2的整数幂,如64*64,否则无效;若设置了纹理图片,设置线颜色类型将无效。
//构建顶点数组cllocationcoordinate2d coords[5]={0};coords[0]=cllocationcoordinate2dmake(39.968,116.260);coords[1]=cllocationcoordinate2dmake(39.912,116.324);coords[2]=cllocationcoordinate2dmake(39.968,116.373);coords[3]=cllocationcoordinate2dmake(39.912,116.439);coords[4]=cllocationcoordinate2dmake(39.968,116.490);//构建分段颜色索引数组nsarray*drawindexs =[nsarray arraywithobjects:[nsnumber numberwithint:0],[nsnumber numberwithint:1],[nsnumber numberwithint:2],[nsnumber numberwithint:3], nil];// 构造分段折线bmkmultipolyline*multexturepolyline =[bmkmultipolyline multipolylinewithcoordinates:coords count:5drawindexs:drawindexs];[_mapview addoverlay:multexturepolyline];
//根据overlay生成对应的view - (__kindof bmkoverlayview *)mapview:(bmkmapview *)mapview viewforoverlay:(id) overlay { if([overlay iskindofclass:[bmkmultipolylineclass]]){bmkmultitexturepolylineview*multexturepolylineview =[[bmkmultitexturepolylineview alloc] initwithmultipolyline:overlay];// 设置polylineview的画笔宽度为12multexturepolylineview.linewidth=12;multexturepolylineview.textureimages= @[[uiimage imagenamed:@"traffic_texture_congestion"],[uiimage imagenamed:@"traffic_texture_slow"],[uiimage imagenamed:@"traffic_texture_smooth"],[uiimage imagenamed:@"traffic_texture_unknown"]];nil];// linejointype,默认是kbmklinejoinbevel(不支持虚线)// 拐角处圆角衔接multexturepolylineview.linejointype= kbmklinejoinround;// 拐角处平角衔接multexturepolylineview.linejointype= kbmklinejoinbevel;// 拐角处尖角衔接,ps尖角连接(尖角过长(大于线宽)按平角处理)multexturepolylineview.linejointype= kbmklinejoinmiter;return multexturepolylineview}return nil;}
效果如图:
since 6.5.7 ios地图sdk支持发光线绘制能力。
#pragma mark -bmkmapviewdelegate-(__kindof bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id<bmkoverlay>)overlay {if([overlay isequal:_polyline]){bmkpolylineview*polylineview =[[bmkpolylineview alloc] initwithpolyline:overlay];// 设置polylineview的画笔颜色为蓝色polylineview.strokecolor=[[uicolor yellowcolor] colorwithalphacomponent:1];// 设置polylineview的画笔宽度为10polylineview.linewidth=10;polylineview.linecaptype= kbmklinecapround;polylineview.linejointype= kbmklinejoinbevel;polylineview.linebloommode= kbmklinebloommodegradient;polylineview.linebloomwidth=10*1.5f;polylineview.linebloomalpha=255.f;polylineview.linebloomgradientaspeed=10;return polylineview;}elseif([overlay isequal:_gradientline]){bmkgradientlineview*gradientlineview =[[bmkgradientlineview alloc] initwithoverlay:overlay];gradientlineview.strokecolors= @[[[uicolor yellowcolor] colorwithalphacomponent:0.5],[uicolor colorwithred:1.f green:0.f blue:0.f alpha:0.5f],[uicolor colorwithred:0.f green:1.f blue:0.f alpha:0.5f],[uicolor colorwithred:1.f green:0.84blue:0.f alpha:0.5f],[uicolor colorwithred:0.58green:0.44blue:0.86alpha:0.5f],[uicolor colorwithred:1green:1blue:0alpha:1]];gradientlineview.linewidth=8;gradientlineview.isclickable=yes;gradientlineview.linebloommode= kbmklinebloommodeblur;gradientlineview.linebloomwidth=8*2.0f;gradientlineview.linebloomalpha=155.f;return gradientlineview;}return nil;}
效果如下图所示:
上一篇
下一篇
本篇文章对您是否有帮助?