/**
* 设置路线
*
* @param points
*/
private void showLine(List<com.amap.api.maps.model.LatLng> points) {
try {
Bitmap bitmap = BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.wenli_jiantou);
Bitmap bitmap_ = resizeImage(bitmap, 16, 64);
BitmapDescriptor mRedTexture = BitmapDescriptorFactory.fromBitmap(bitmap_);
List<BitmapDescriptor> textureList = new ArrayList<BitmapDescriptor>();
textureList.add(mRedTexture);
// //添加纹理索引
List<Integer> indexList = new ArrayList<>();
for (int i = 0; i < textureList.size(); i++) {
indexList.add(i);
}
PolylineOptions options = new PolylineOptions();
options.addAll(points)
.width(UIUtils.dp2px(10)) //设置线的宽度,单位px
.setCustomTexture(mRedTexture)
.setCustomTextureIndex(indexList)
.setUseTexture(true)
.color(Color.argb(255, 1, 1, 1));
mPolyline = mGaodeMap.addPolyline(options);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Bitmap resizeImage(Bitmap bm, int newWidth, int newHeight) {
Bitmap newbm = null;
if (bm != null) {
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
}
return newbm;
}
Android 高德地图,生成带纹理的线
最新推荐文章于 2024-04-26 09:14:08 发布