arcgis100添加自定义标注(PictureMarkerSymbol)

908 阅读1分钟

最近在做一个关于空气质量的app,需要在地图标注各个城市的名称、空气质量等级.但是如果显示呢?arcgis 只提供了PictureMarkerSymbol和SimpleMarkerSymbol.那我们就把布局转换成Drawable用PictureMarkerSymbol显示.

1.创建布局


View view = LayoutInflater.from(getActivity()).inflate(R.layout.quality_layout_mark_nearby, null);

2.转换布局为图片


public static Bitmap createBitmapFromView(View v, int width, int height) {
    //测量使得view指定大小
    int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.UNSPECIFIED);
    int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED);
    Log.e(TAG, "measuredWidth: " + measuredWidth + " " +measuredHeight);
    v.measure(measuredWidth, measuredHeight);
    //调用layout方法布局后,可以得到view的尺寸大小
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    Log.e(TAG, "createBitmapFromView: " + v.getHeight() + " " +v.getWidth());
    Bitmap bmp = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmp);
    c.drawColor(Color.WHITE);
    v.draw(c);
    return bmp;
}
Bitmap bitmap =createBitmapFromView(view, 500, 100);
Drawable drawable = new BitmapDrawable(bitmap);

3.添加标注


PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol((BitmapDrawable) drawable);