生活随笔
收集整理的這篇文章主要介紹了
百度地图添加带有图案的多边形区域
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
日常的工作中繪制多邊形區域可以設置單色矩形區域,但是特殊需求下,需要繪制指定圖案的邊框,下面就簡單實現下
多種顏色矩形
/*** 繪制圍欄*/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中添加幾次都只顯示一種樣式。
總結
以上是生活随笔為你收集整理的百度地图添加带有图案的多边形区域的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。