Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

android - MyLocationOverlay - Custom image, but no shadow

I have an application, which uses a custom implementation of MyLocationOverlay.

In the implementation I set a Bitmap property that is used when it has been specified, by an overload of Draw.

It works nicely, using my custom image, but it doesn't display a shadow - as is done automatically in an ItemizedOverlay.

Can anyone help?

Here is (the relevant code from) my class:

public class LocationOverlay: MyLocationOverlay
{
    /// <summary>Bitmap to use for indicating the current fixed location.</summary>
    public Bitmap LocationMarker { get; set; }

    /// <summary>Uses the custom marker bitmap if one has been specified. Otherwise, the default is used.</summary>
    /// <param name="canvas"></param>
    /// <param name="mapView"></param>
    /// <param name="shadow"></param>
    /// <param name="when"></param>
    /// <returns></returns>
    public override bool Draw(Canvas canvas, MapView mapView, bool shadow, long when)
    {
        var drawShadow = shadow;

        if (LocationMarker != null && LastFix != null)
        {
            var screenPoint = new Point();
            var geoPoint = new GeoPoint((int)(LastFix.Latitude * 1E6), (int)(LastFix.Longitude * 1E6));
            mapView.Projection.ToPixels(geoPoint, screenPoint);
            canvas.DrawBitmap(LocationMarker, screenPoint.X, screenPoint.Y - 32, null);
            drawShadow = true;
        }

        base.Draw(canvas, mapView, drawShadow);
        return true;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you're missing the point of the shadow argument. The map calls your draw() method twice and it tells you whether this is the shadow pass or not. It doesn't draw the shadow for you. So your code will look something like this:

public override bool Draw(Canvas canvas, MapView mapView, bool shadow, long when)
{
    if (LocationMarker != null && LastFix != null)
    {
        var screenPoint = new Point();
        var geoPoint = new GeoPoint((int)(LastFix.Latitude * 1E6), (int)(LastFix.Longitude * 1E6));
        mapView.Projection.ToPixels(geoPoint, screenPoint);

        if(shadow)
        {
            // Draw your shadow bitmap here
        }
        else
        {
            canvas.DrawBitmap(LocationMarker, screenPoint.X, screenPoint.Y - 32, null);
        }
    }

    return true;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...