【发布时间】: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(),但没有解决。