0

我正在使用自定义类在小部件Overlay上显示标记。MapView我正在使用我发现的另一个示例中的相同图像,但我的叠加层缺少阴影。

这是原文:

这是原文

..这是我的:

..这是我的:

那个影子是怎么产生的?那是另一个可绘制资源还是类draw方法中的一些技巧Overlay。谢谢。

--

这是我的Overlay课:

public class Mappin extends com.google.android.maps.Overlay {

    private final GeoPoint geoPoint;
    private final Context ctxContext;

    public Mappin(Context ctxContext, GeoPoint geoPoint) {
        super();

        this.geoPoint = geoPoint;
        this.ctxContext = ctxContext;
    }

    public boolean draw(Canvas canCanvas, MapView mvwMap, boolean booShadow, long lngWhen) {
        super.draw(canCanvas, mvwMap, booShadow);

        Point screenPts = new Point();
        mvwMap.getProjection().toPixels(this.geoPoint, screenPts);

        Bitmap bmp = BitmapFactory.decodeResource(this.ctxContext.getResources(), R.drawable.ic_location_marker);
        canCanvas.drawBitmap(bmp, screenPts.x - bmp.getWidth() / 2, screenPts.y - bmp.getHeight(), null);

        return true;
    }

}
4

1 回答 1

0

我找到了一些显示标记阴影的代码。我需要调整偏斜因子以使其正常工作,但它现在起到了作用。这是我自定义的完整代码Overlay

public class Mappin extends Overlay {

    protected Drawable drwMarker;
    protected GeoPoint gptCoordinates;

    public Mappin(Drawable drwMarker, GeoPoint gptCoordinates) {

        this.drwMarker = drwMarker;
        this.gptCoordinates = gptCoordinates;

    }

    @Override
    public void draw(Canvas canCanvas, MapView mapView, boolean booShadow) {

        super.draw(canCanvas, mapView, booShadow);

        Projection prjProjection = mapView.getProjection();

        Integer x;
        Integer y;

        if (!booShadow) {

            x = prjProjection.toPixels(gptCoordinates, null).x - (drwMarker.getIntrinsicWidth() / 2);
            y = prjProjection.toPixels(gptCoordinates, null).y - (drwMarker.getIntrinsicHeight());

        } else {

            Integer intSign = (SHADOW_X_SKEW > 0 ? 1 : -1);
            Float fltScaler = 1.1F - Math.abs(SHADOW_X_SKEW);
            x = (int) (prjProjection.toPixels(gptCoordinates, null).x - (intSign * (drwMarker.getIntrinsicWidth() * fltScaler)));
            y = (int) (prjProjection.toPixels(gptCoordinates, null).y - (drwMarker.getIntrinsicHeight() * SHADOW_Y_SCALE));

        }

        drawAt(canCanvas, drwMarker, x, y, booShadow);

    }

}
于 2012-10-04T10:37:28.710 回答