0
我試圖在地圖上設置動態自定義標記,但它不起作用,而是顯示默認標記。我在哪裏錯了?MapBox自定義標記不起作用
IconFactory iconFactory = IconFactory.getInstance(MainActivity.this);
TextDrawable iconDrawable = new TextDrawable("CD");
Icon icon = iconFactory.fromDrawable(iconDrawable);
MarkerOptions marker = new MarkerOptions()
.position(new LatLng(location.latitude, location.longitude))
.icon(icon)
mapboxMap.addMarker(marker);
TextDrawable:
public class TextDrawable extends Drawable {
private final String text;
private final Paint paint;
public TextDrawable(String text) {
this.text = text;
this.paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(22f);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.FILL);
paint.setTextAlign(Paint.Align.LEFT);
}
@Override
public void draw(Canvas canvas) {
canvas.drawText(text, 0, 0, paint);
}
@Override
public void setAlpha(int alpha) {
paint.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paint.setColorFilter(cf);
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
感謝胡安用一個矩形的資源!正是我需要的。 – doovers