【问题标题】:No line between points in Gmap.Net routeGmap.Net路线中的点之间没有线
【发布时间】:2016-09-28 07:07:54
【问题描述】:

我在 Windows 窗体上使用 Gmap.Net,我想在收到对象位置时绘制对象的轨迹,为此我使用 Routes。当我向路线添加点时,地图上看不到线,但是当我更改地图的缩放比例时,它们会出现在地图上。此外,当我在向路线添加一个点 (gMapControl1.Position = new PointLatLng(...)) 后设置地图的位置时,它可以正常工作,并且我在地图上看到了路线,知道吗?我的代码如下。

void NewDataReceived(DeviceInfo deviceinf)
{
    //---some codes
    //----For the first time I add layer and route 
    if (deviceOverLay == null)
    {
        deviceOverLay = new GMapOverlay(deviceinf.DeviceId.ToString());
        gMapControl1.Overlays.Add(deviceOverLay);
        deviceRoute = new GMapRoute(new List<PointLatLng>(), deviceinf.DeviceName);
        deviceOverLay.Routes.Add(deviceRoute);
        //Add all your points here
        deviceRoute.Points.Add(new PointLatLng(deviceinf.Latitude, deviceinf.Longitude));
        deviceRoute.Tag = deviceinf;
    }
    else
    {
        deviceOverLay.Routes[0].Points.Add(new PointLatLng(deviceinf.Latitude, deviceinf.Longitude));
    }

    //if I call this line it works, but I don't want it
    // gMapControl1.Position = new PointLatLng(deviceinf.Latitude, deviceinf.Longitude);  
    //---some codes
}

【问题讨论】:

  • 我从未使用过 GMap.Net,但看起来更新 Route 不会立即使地图控件无效,而直接向地图控件添加一个点会。有道理,因为我可能想在绘制之前构建一条完整的路线。尝试 gMapControl.Invalidate() 或类似的东西。当您更改缩放时它显示的事实意味着该点已被添加。
  • 感谢“cdkMoose”,我试过gMapControl.Invalidate(),但没有解决。

标签: c# winforms gmap.net


【解决方案1】:

尝试使用

gMapControl1.UpdateRouteLocalPosition(deviceRoute);

这会更新本地位置并进行重绘。

【讨论】:

  • 非常感谢@JAlecksen,您几乎解决了这个问题。通过调用 UpdateRouteLocalPosition 方法,即使单击地图我也可以看到路线,以前只有更改缩放或调用其他缩放方法才能看到路线。最后,如果我们在您提到的方法之前调用“gMapControl.Invalidate()”,它会正常工作,再次感谢。我还将在此链接中提及您的答案:link。再次感谢。
猜你喜欢
  • 2018-11-13
  • 1970-01-01
  • 2016-05-26
  • 1970-01-01
  • 2010-11-03
  • 2011-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多