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 overloa
Solution 1:
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:
publicoverrideboolDraw(Canvas canvas, MapView mapView, bool shadow, longwhen)
{
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);
}
}
returntrue;
}
Solution 2:
Got it. You can use DrawAt to draw the shadow automatically.
So my property becomes a Drawable thusly:
public Drawable MarkerResource
{
set
{
_locationMarker = value;
var widthOffset = _locationMarker.IntrinsicWidth / 2;
_locationMarker.SetBounds(-widthOffset, -_locationMarker.IntrinsicHeight, widthOffset, 0);
}
}
And the override now looks like this:
publicoverrideboolDraw(Canvas canvas, MapView mapView, bool shadow, longwhen)
{
if (LastFix == null) returnfalse;
if (_locationMarker != null)
{
var screenPoint = new Point();
var geoPoint = new GeoPoint((int)(LastFix.Latitude * 1E6), (int)(LastFix.Longitude * 1E6));
mapView.Projection.ToPixels(geoPoint, screenPoint);
DrawAt(canvas, _locationMarker, screenPoint.X, screenPoint.Y, shadow);
}
elseif (MyLocation != null) DrawMyLocation(canvas, mapView, LastFix, MyLocation, when);
if (IsCompassEnabled) DrawCompass(canvas, Orientation);
returnfalse;
}
Works perfectly.
This also now respects enabling the compass and will draw using the default technique if no Drawable is specified.
Post a Comment for "Mylocationoverlay - Custom Image, But No Shadow"