BaiduMap SDK-添加覆盖层

目录

 

1 折线绘制(PolylineOptions)

1.1 折线绘制(Polyline和PolylineOptions)

1.2 同色折线绘制

1.3 不同段不同颜色折线

1.4 使用图片绘制折线

2 多边形覆盖物(PolygonOptions)

3 圆弧覆盖物(ArcOptions)

4 圆点覆盖物(DotOptions)

5 圆环覆盖物(CircleOptions)

6 文字覆盖物(TextOptions)

7 Marker覆盖物(MarkerOptions)

8  ground 覆盖物(GroundOverlayOptions)


1 折线绘制(PolylineOptions

1.1 折线绘制(PolylinePolylineOptions)

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);

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 多边形覆盖物(PolygonOptions

  // 添加多边形
        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 圆弧覆盖物(ArcOptions)

        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 圆点覆盖物(DotOptions)

        LatLng llDot = new LatLng(39.98923, 116.397428);
        OverlayOptions ooDot = new DotOptions().center(llDot).radius(60)
                .color(0xFF0000FF);
        baiduMap.addOverlay(ooDot);

5 圆环覆盖物(CircleOptions)

        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 文字覆盖物(TextOptions

       // 添加文字
        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覆盖物(MarkerOptions)

8  ground 覆盖物(GroundOverlayOptions

猜你喜欢

转载自blog.csdn.net/niuba123456/article/details/81132727
今日推荐