您的位置:首页 > 其它

百度地图添加带有图案的多边形区域

2017-07-13 10:05 190 查看
日常的工作中绘制多边形区域可以设置单色矩形区域,但是特殊需求下,需要绘制指定图案的边框,下面就简单实现下

多种颜色矩形



/**
* 绘制围栏
*/
private void drawBitmapDescriptor(List<LatLng> points) {
BitmapDescriptor custom1 = BitmapDescriptorFactory
.fromResource(R.mipmap.icon_road_red_arrow);
BitmapDescriptor custom2 = BitmapDescriptorFactory
.fromResource(R.mipmap.icon_road_green_arrow);
BitmapDescriptor custom3 = BitmapDescriptorFactory
.fromResource(R.mipmap.icon_road_blue_arrow);

//构造纹理队列
List<BitmapDescriptor> customList = new ArrayList<>();
customList.add(custom1);
customList.add(custom2);
customList.add(custom3);
List<Integer> index = new ArrayList<>();
index.add(0);
index.add(1);
index.add(2);
//构造对象
OverlayOptions ooPolyline = new PolylineOptions().width(25).dottedLine(true).color(0xAAFF0000).points(points)
.customTextureList(customList).textureIndex(index);
//添加到地图
mBaiduMap.addOverlay(ooPolyline);

}单色多边形



/**
* 绘制围栏
*/
private void drawBitmapDescriptor(List<LatLng> points) {
BitmapDescriptor custom1 = BitmapDescriptorFactory
.fromResource(R.mipmap.icon_road_red_arrow1);
//构造纹理队列
List<BitmapDescriptor> customList = new ArrayList<>();
customList.add(custom1);
List<Integer> index = new ArrayList<>();
index.add(0);
//构造对象
OverlayOptions ooPolyline = new PolylineOptions().width(25).dottedLine(true).color(0xAAFF0000).points(points)
.customTextureList(customList).textureIndex(index);
//添加到地图
mBaiduMap.addOverlay(ooPolyline);

}


可以看出其实单色和多色区别在于customList中的图片数量,想要更绚丽的效果,大家自行发挥。
其中width用于设置边框的宽度,dotterLine用于设置两个图片拼接中间是否有分割点,points是传入的经纬度集合,customTextureList是边框样式

textureIndex是指添加的边框集合中的索引,如果有多张图的话,index索引的变化会改变边框矩形样式,如果custonTextureList中只有一个样式的话,则index中添加几次都只显示一种样式。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: