BaiduMap SDK-Overlay(覆盖层)
程序员文章站
2022-06-10 16:30:48
...
目录
1 折线绘制(Polyline)
1.1 折线绘制(Polyline)
Polyline是定义折线覆盖物,PolylineOptions主要设置覆盖物的属性;
1.2 同色折线绘制
// 添加多颜色分段的折线绘制
LatLng p11 = new LatLng(39.965, 116.444);
LatLng p21 = new LatLng(39.925, 116.494);
LatLng p31 = new LatLng(39.955, 116.534);
LatLng p41 = new LatLng(39.905, 116.594);
LatLng p51 = new LatLng(39.965, 116.644);
List<LatLng> points1 = new ArrayList<LatLng>();
points1.add(p11);
points1.add(p21);
points1.add(p31);
points1.add(p41);
points1.add(p51);
List<Integer> colorValue = new ArrayList<Integer>();
OverlayOptions ooPolyline1 =null;
ooPolyline1 = new PolylineOptions().width(10)
.color(0xAAFF0000).points(points1);
colorPolyline = (Polyline) baiduMap.addOverlay(ooPolyline1);
//设置是否虚线
colorPolyline.setDottedLine(true);
1.3 不同段不同颜色折线
// 添加多颜色分段的折线绘制
LatLng p11 = new LatLng(39.965, 116.444);
LatLng p21 = new LatLng(39.925, 116.494);
LatLng p31 = new LatLng(39.955, 116.534);
LatLng p41 = new LatLng(39.905, 116.594);
LatLng p51 = new LatLng(39.965, 116.644);
List<LatLng> points1 = new ArrayList<LatLng>();
points1.add(p11);
points1.add(p21);
points1.add(p31);
points1.add(p41);
points1.add(p51);
List<Integer> colorValue = new ArrayList<Integer>();
OverlayOptions ooPolyline1 =null;
colorValue.add(0xAAFF0000);
colorValue.add(0xAA00FF00);
colorValue.add(0xAA0000FF);
ooPolyline1 = new PolylineOptions().width(10)
.color(0xAAFF0000).points(points1).colorsValues(colorValue);
colorPolyline = (Polyline) baiduMap.addOverlay(ooPolyline1);
1.4 使用图片绘制折线
BitmapDescriptor mRedTexture = BitmapDescriptorFactory.fromResource(R.drawable.icon_road_blue_arrow);
BitmapDescriptor mBlueTexture = BitmapDescriptorFactory.fromResource(R.drawable.icon_road_green_arrow);
BitmapDescriptor mGreenTexture = BitmapDescriptorFactory.fromResource(R.drawable.icon_road_red_arrow);
// 添加多颜色分段的折线绘制
LatLng p11 = new LatLng(39.965, 116.444);
LatLng p21 = new LatLng(39.925, 116.494);
LatLng p31 = new LatLng(39.955, 116.534);
LatLng p41 = new LatLng(39.905, 116.594);
List<LatLng> points1 = new ArrayList<LatLng>();
points1.add(p11);
points1.add(p21);
points1.add(p31);
points1.add(p41);
List<Integer> colorValue = new ArrayList<Integer>();
OverlayOptions ooPolyline1 =null;
List<BitmapDescriptor> textureList = new ArrayList<BitmapDescriptor>();
textureList.add(mRedTexture);
textureList.add(mBlueTexture);
textureList.add(mGreenTexture);
List<Integer> textureIndexs = new ArrayList<Integer>();
textureIndexs.add(0);
textureIndexs.add(1);
textureIndexs.add(2);
ooPolyline1 = new PolylineOptions().width(20)
.points(points1).dottedLine(true).customTextureList(textureList).textureIndex(textureIndexs);
colorPolyline = (Polyline) baiduMap.addOverlay(ooPolyline1);
2 多边形覆盖物(Polygon)
// 添加多边形
LatLng pt1 = new LatLng(39.93923, 116.357428);
LatLng pt2 = new LatLng(39.91923, 116.327428);
LatLng pt3 = new LatLng(39.89923, 116.347428);
LatLng pt4 = new LatLng(39.89923, 116.367428);
LatLng pt5 = new LatLng(39.91923, 116.387428);
List<LatLng> pts = new ArrayList<LatLng>();
pts.add(pt1);
pts.add(pt2);
pts.add(pt3);
pts.add(pt4);
pts.add(pt5);
OverlayOptions ooPolygon = new PolygonOptions().points(pts)
.stroke(new Stroke(5, 0xAA00FF00)).fillColor(0xAAFFFF00);
baiduMap.addOverlay(ooPolygon);
3 圆弧覆盖物(Arc)
LatLng p1 = new LatLng(39.97923, 116.357428);
LatLng p2 = new LatLng(39.94923, 116.397428);
LatLng p3 = new LatLng(39.97923, 116.437428);
OverlayOptions ooArc = new ArcOptions().color(0xAA00FF00).width(4)
.points(p1, p2, p3);
baiduMap.addOverlay(ooArc);
4 圆点覆盖物(Dot)
LatLng llDot = new LatLng(39.98923, 116.397428);
OverlayOptions ooDot = new DotOptions().center(llDot).radius(60)
.color(0xFF0000FF);
baiduMap.addOverlay(ooDot);
5 圆环覆盖物(Circle)
LatLng llCircle = new LatLng(39.90923, 116.447428);
OverlayOptions ooCircle = new CircleOptions().fillColor(0x000000FF)
.center(llCircle).stroke(new Stroke(5, 0xAA000000))
.radius(1400);
baiduMap.addOverlay(ooCircle);
6 文字覆盖物(Text)
Text官方文档:http://wiki.lbsyun.baidu.com/cms/androidsdk/doc/v5.1.0/com/baidu/mapapi/map/Text.html
// 添加文字
LatLng llText = new LatLng(39.86923, 116.397428);
OverlayOptions ooText = new TextOptions().bgColor(0xAAFFFF00)
.fontSize(24).fontColor(0xFFFF00FF).text("百度地图SDK").rotate(-30)
.position(llText);
baiduMap.addOverlay(ooText);
7 Marker覆盖物(Marker)
详情参考:BaiduMap SDK-点标记(Marker和InfoWindow)
8 自定义图层
8.1 ground 覆盖物(GroundOverlay)
详情参考:BaiduMap SDK-GroundOverlay(图片覆盖物)
8.2 TileOverlay(瓦片图层)
详情参考:BaiduMap SDK-TileOverlay(瓦片图层)