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

arcgis100添加自定义标注(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);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-06-22
  • 2021-11-19
  • 2021-06-01
  • 2021-06-17
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-01-19
  • 2021-10-02
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2021-08-05
相关资源
相似解决方案