天天看点

ArcGIS For Android 中文标注不显示解决方案

思路:

  1. 将文字转换成图片
  2. 获取目标图形中心点坐标
  3. 使用PictureMarkerSymbol函数将图片标注打在地图上

文字转图片:

/**
	 * 文字转换BitMap
	 * @param text
	 * @return
	 */
	public static Drawable createMapBitMap(String text) {

		Paint paint = new Paint();
		paint.setColor(Color.BLACK);
		paint.setTextSize(20);
		paint.setAntiAlias(true);
		paint.setTextAlign(Align.CENTER);

		float textLength = paint.measureText(text);

		int width = (int) textLength + 10;
		int height = 40;

		Bitmap newb = Bitmap.createBitmap(width, height, Config.ARGB_8888);

		Canvas cv = new Canvas(newb);
		cv.drawColor(Color.parseColor("#00000000"));

		cv.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG
				| Paint.FILTER_BITMAP_FLAG));

		cv.drawText(text, width / 2, 20, paint);

		cv.save(Canvas.ALL_SAVE_FLAG);// 保存
		cv.restore();// 存储

		return new BitmapDrawable(newb);

	}
           

使用方法:

PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol(
						CacheData.createMapBitMap(list.get(i).getAREA() + "亩"));
				Graphic graphic2 = new Graphic(env.getCenter(), markerSymbol);