arcgis100添加自定義標註(PictureMarkerSymbol)

最近在作一個關於空氣質量的app,須要在地圖標註各個城市的名稱、空氣質量等級.可是若是顯示呢?arcgis 只提供了PictureMarkerSymbol和SimpleMarkerSymbol.那咱們就把佈局轉換成Drawable用PictureMarkerSymbol顯示.app

1.建立佈局佈局

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

2.轉換佈局爲圖片spa

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.添加標註code

PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol((BitmapDrawable) drawable);
複製代碼
相關文章
相關標籤/搜索