Winforms GMAP.NET,为标记添加标签

Winforms GMAP.NET,为标记添加标签,winforms,google-maps,label,marker,Winforms,Google Maps,Label,Marker,我在C#(Winforms)中使用GMAP,我想添加一个带有标签的标记。我在一次会议上遵循了答案,并注意到实现中存在一个问题。标记没有打印在正确的位置,标签都是在彼此的顶部打印的。我认为它没有正确地调用标记的OnRender方法?有人能给我指出正确的方向吗?in遇到了同样的问题,只需调用base.OnRender(g)不是为我修好的。诀窍是从GMarkerGoogle推导,而不是像您提供的答案那样从GMapMarker推导 此外,我还必须对文本渲染进行一些调整。我提出了这个解决方案,对我来说很好

我在C#(Winforms)中使用GMAP,我想添加一个带有标签的标记。我在一次会议上遵循了答案,并注意到实现中存在一个问题。标记没有打印在正确的位置,标签都是在彼此的顶部打印的。我认为它没有正确地调用标记的OnRender方法?有人能给我指出正确的方向吗?

in遇到了同样的问题,只需调用
base.OnRender(g)不是为我修好的。诀窍是从
GMarkerGoogle
推导,而不是像您提供的答案那样从
GMapMarker
推导

此外,我还必须对文本渲染进行一些调整。我提出了这个解决方案,对我来说很好:

public class GmapMarkerWithLabel : GMarkerGoogle, ISerializable
{
    private readonly Font _font;
    private GMarkerGoogle _innerMarker;
    private readonly string _caption;

    public GmapMarkerWithLabel(PointLatLng p, string caption, GMarkerGoogleType type)
        : base(p, type)
    {
        _font = new Font("Arial", 11);
        _innerMarker = new GMarkerGoogle(p, type);

        _caption = caption;
    }

    public override void OnRender(Graphics g)
    {
        base.OnRender(g);

        var stringSize = g.MeasureString(_caption, _font);
        var localPoint = new PointF(LocalPosition.X - stringSize.Width / 2, LocalPosition.Y + stringSize.Height);
        g.DrawString(_caption, _font, Brushes.Black, localPoint);
    }

    public override void Dispose()
    {
        if (_innerMarker != null)
        {
            _innerMarker.Dispose();
            _innerMarker = null;
        }

        base.Dispose();
    }

    #region ISerializable Members

    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
    {
        GetObjectData(info, context);
    }

    protected GmapMarkerWithLabel(SerializationInfo info, StreamingContext context)
        : base(info, context)
    { }

    #endregion
}

听起来像是几年前修复的一个bug。据我所知,我使用的是最新版本(1.7.1)。我通过调用base.OnRender(g)解决了标记放置问题。