【问题标题】:GMAP.NET, adding labels to markersGMAP.NET,为标记添加标签
【发布时间】:2017-11-23 19:54:55
【问题描述】:

我在 C# (Winforms) 中使用 GMAPS,我想添加一个带有标签的标记。我按照GMAP.NET adding labels underneath markers 的答案进行操作,并注意到实现存在问题。标记未绘制在正确的位置,并且所有标签都绘制在彼此的顶部。我认为它没有正确调用标记的 OnRender 方法?谁能指出我正确的方向?

【问题讨论】:

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

标签: winforms google-maps label marker


【解决方案1】:

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
}

【讨论】:

    猜你喜欢
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多