ios地图sdk | 百度地图api sdk-凯发k8官方旗舰厅

浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
绘制线
下载开发文档
绘制线简介

折线类为 bmkpolyline,由一组经纬度坐标组成,并以有序序列形式建立一系列的线段。

注意:v5.0.0后的版本,绘制线宽会变细,linewidth统一为画笔宽度,请注意适配。
绘制折线
1. 创建bmkmapview,并设置delegate
bmkmapview*mapview =[[bmkmapview alloc]initwithframe:self.view.bounds];
mapview.delegate= self;
[self.view addsubview:mapview];
2. 添加折线覆盖物数据
// 添加折线覆盖物
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];
3. 实现代理方法
-(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的画笔宽度为16
polylineview.linewidth=16;
//圆点虚线,v5.0.0新增
// polylineview.linedashtype = kbmklinedashtypedot;
//方块虚线,v5.0.0新增
// polylineview.linedashtype = kbmklinedashtypesquare;
return polylineview;
}
return nil;
}
4. 运行程序

效果如图:

绘制大地曲线

ios地图sdk支持大地曲线绘制能力。

1. 添加大地曲线数据
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];
2. 实现代理方法,并设置颜色或者纹理图片
-(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;
}
3. 运行程序

效果如图:

绘制渐变线

ios地图sdk支持渐变线绘制能力。

1. 添加渐变线数据,并构建分段渐变颜色索引数组
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];
2. 实现代理方法,并设置渐变颜色数组
-(__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];
// 画笔宽度为12
gradientlineview.linewidth=12;
return gradientlineview;
}
return nil;
}
3. 运行程序

效果如图:

分段颜色绘制折线

ios地图sdk支持折线多段颜色绘制能力。

1. 添加分段折线数据,并构建分段颜色索引数组
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];
2. 实现代理方法,并设置分段颜色
//根据overlay生成对应的view
-(__kindof bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id <bmkoverlay>)overlay {
if([overlay iskindofclass:[bmkmultipolylineclass]]){
bmkmulticolorpolylineview*colorfulpolylineview =[[bmkmulticolorpolylineview alloc] initwithmultipolyline:overlay];
// 设置polylineview的画笔宽度为12
colorfulpolylineview.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;
}
3. 运行程序

效果如图:

分段纹理折线

ios地图sdk支持折线分段颜色绘制能力。

纹理素材格式:纹理图宽高片须是2的整数幂,如64*64,否则无效;若设置了纹理图片,设置线颜色类型将无效。

注意:目前仅支持对折线设置纹理,其余覆盖物目前暂不支持设置纹理。
1. 添加分段纹理绘制折线数据,并构建构建分段纹理索引数组
//构建顶点数组
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];
2. 实现代理方法,并加载分段纹理图片
//根据overlay生成对应的view - (__kindof bmkoverlayview *)mapview:(bmkmapview *)mapview viewforoverlay:(id ) overlay {
if([overlay iskindofclass:[bmkmultipolylineclass]]){
bmkmultitexturepolylineview*multexturepolylineview =[[bmkmultitexturepolylineview alloc] initwithmultipolyline:overlay];
// 设置polylineview的画笔宽度为12
multexturepolylineview.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;
}
3. 运行程序

效果如图:

polyline发光效果

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的画笔宽度为10
polylineview.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;
}

效果如下图所示:

上一篇

绘制点标记

下一篇

绘制弧线和面

本篇文章对您是否有帮助?

网站地图