MyLocationOverlay - 自定义形象,但没影 [英] MyLocationOverlay - Custom image, but no shadow

查看:224
本文介绍了MyLocationOverlay - 自定义形象,但没影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它使用的自定义实现的 MyLocationOverlay

在我设置的时候已经指定它时使用的位图的财产,通过抽奖的重载的实现。

它工作得很好,用我的自定义图像,,但它不显示阴影 - 就像在自动完成的的 ItemizedOverlay

谁能帮助?

下面是(从有关code)我的类:

 公共类LocationOverlay:MyLocationOverlay
{
    ///&所述;总结>位图用于指示当前的固定位置与所述; /总结>
    公共位图LocationMarker {搞定;组; }    ///<总结>如果已指定使用自定义标记位图。否则,则使用默认&下; /总结>
    ///< PARAM NAME =画布>< /参数>
    ///< PARAM NAME =图形页面>< /参数>
    ///< PARAM NAME =影子>< /参数>
    ///< PARAM NAME =时,>< /参数>
    ///<&回报GT;< /回报>
    公众覆盖布尔抽奖(帆布帆布,MapView类MapView类,布尔阴影,时长)
    {
        VAR drawShadow =阴影;        如果(LocationMarker = NULL&放大器;!&安培;!LastFix = NULL)
        {
            VAR screenPoint =新点();
            VAR的GeoPoint =新的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方法(画布,MapView类,drawShadow);
        返回true;
    }
}


解决方案

明白了。您可以使用的 DrawAt 的自动绘制阴影。

所以,我的财产变成的绘制对象的正是如此:

 公众可绘制MarkerResource
{
    组
    {
        _locationMarker =价值;
        变种widthOffset = _locationMarker.IntrinsicWidth / 2;
        _locationMarker.SetBounds(-widthOffset,-_locationMarker.IntrinsicHeight,widthOffset,0);
    }
}

和覆盖现在看起来是这样的:

 公共覆盖布尔抽奖(帆布帆布,MapView类MapView类,布尔阴影,时长)
{
    如果(LastFix == NULL)返回false;    如果(_locationMarker!= NULL)
    {
        VAR screenPoint =新点();
        VAR的GeoPoint =新的GeoPoint((INT)(LastFix.Latitude * 1E6),(INT)(LastFix.Longitude * 1E6));
        mapView.Projection.ToPixels(GeoPoint对象,screenPoint);
        DrawAt(帆布,_locationMarker,screenPoint.X,screenPoint.Y,阴影);
    }
    否则,如果(MyLocation!= NULL)DrawMyLocation(画布,MapView类,LastFix,MyLocation时);    如果(IsCompassEnabled)DrawCompass(帆布,方向);
    返回false;
}

完美的作品。

这现在也尊重使指南针,如果没有的<​​em>绘制对象的指定将借鉴使用默认的技术。

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;
    }
}

解决方案

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:

public override bool Draw(Canvas canvas, MapView mapView, bool shadow, long when)
{
    if (LastFix == null) return false;

    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);
    }
    else if (MyLocation != null) DrawMyLocation(canvas, mapView, LastFix, MyLocation, when);

    if (IsCompassEnabled) DrawCompass(canvas, Orientation);
    return false;
}

Works perfectly.

This also now respects enabling the compass and will draw using the default technique if no Drawable is specified.

这篇关于MyLocationOverlay - 自定义形象,但没影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆