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

日常的工作中绘制多边形区域可以设置单色矩形区域,但是特殊需求下,需要绘制指定图案的边框,下面就简单实现下

多种颜色矩形


 /**
     * 绘制围栏
     */
    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中添加几次都只显示一种样式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值