【问题标题】:My Background and net instead of maps in GMap.NET我的背景和网络,而不是 GMap.NET 中的地图
【发布时间】:2017-02-23 09:20:54
【问题描述】:

如果没有可用的地图,我可以在 GMap.NET 中显示我自己的图案/颜色背景并显示其上的所有标记吗?

Perticullary 我想为用户提供一个由经度和子午线组成的网络(带有一些背景),并允许他使用点和多边形。然后,如果地图可用,在普通地图上显示他的位置。

【问题讨论】:

    标签: c# .net maps gmap.net


    【解决方案1】:

    你愿意修改GMap.net控件的源代码吗?如果有,看看GMapCpntrol类中的方法:

    void DrawMap(Graphics g)
    {
            if (Core.updatingBounds || MapProvider == EmptyProvider.Instance || MapProvider == null)
            {
                Debug.WriteLine("Core.updatingBounds");
                return;
            }
    
            ...
    
    }
    

    在这个方法中你会发现绘制缺失的瓦片信息的部分:

    if (!found) //if the tiles are NOT found
    {
         lock (Core.FailedLoads)
         {
              var lt = new LoadTask(tilePoint.PosXY, Core.Zoom);
              if (Core.FailedLoads.ContainsKey(lt))
              {
                    var ex = Core.FailedLoads[lt];
    
        //This is where you would handle what to do when your tiles are not available
                    g.FillRectangle(EmptytileBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height));
                    g.DrawString("Exception: " + ex.Message, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X + 11, Core.tileRect.Y + 11, Core.tileRect.Width - 11, Core.tileRect.Height - 11));
                    g.DrawString(EmptyTileText, MissingDataFont, Brushes.Blue, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat);
                    g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)   Core.tileRect.Height);
                }
         }
    

    }

    如果您不想修改源,则唯一的选择是添加叠加层并在其上绘制所有内容,例如多边形和用于纬度长网的线条。您还需要将这些属性更改为适当的值:

    gMapControl1.EmptyMapBackground
    gMapControl1.EmptyTileBorders
    gMapControl1.EmptyTileColor
    gMapControl1.EmptyTileText
    

    至于确定你是否有瓷砖,我认为没有修改源的简单方法。

    【讨论】:

    • 感谢您的回答。我想我必须修改它。但是你有没有尝试过类似的东西?我只是想知道加载地图后将正确设置没有可用地图的 id 添加位置。
    • 不客气。我做过类似的事情,效果很好。只要您在添加标记、多边形等时始终定义纬度/经度坐标,一切都会很好地排列。如果您要添加静态的东西,例如比例尺、北方,则唯一一次应该使用像素坐标箭头,或类似的东西。
    猜你喜欢
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    • 2012-12-22
    • 2015-11-28
    • 2013-06-13
    相关资源
    最近更新 更多