I realise that there is a serious lack of documentation for using GMap.Net, and not many blogs have covered it. But I am hoping someone has encountered my problem (or something similar) and fixed it.
I am using the Google Maps instance of GMap.Net on my windows application in C# and drawing routes. Now, my entire application is timer controlled, so the routes that are drawn must be redrawn every second, and after a certain amount of time (say 30 seconds), the route changes. Think of a traffic junction situation if that helps.
The following is creating an instance of the maps on form load.
gMapControl1.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
gMapControl1.Position = new PointLatLng(12.934416, 77.612395);
routesOverlayM = new GMapOverlay(gMapControl1, "routeM");
Once this is achieved, in the timer tick event, I am drawing the route. To do so, I have am creating a list of latitude longitude points. Now, before I draw a route, I am clearing the overlay, the route and the list
private void timer1_Tick(object sender, EventArgs e)
{
GMapRoute routeM;
gMapControl1.Overlays.Remove(routesOverlayM);
routesOverlayM.Routes.Remove(routeM);
List<PointLatLng> rightListM = new List<PointLatLng>();
rightListM.Clear();
rightListM.Add(new PointLatLng(12.933702, 77.612720));
rightListM.Add(new PointLatLng(12.934411, 77.612328));
rightListM.Add(new PointLatLng(12.935896, 77.615324));
routeM = new GMapRoute(rightListM, "rightroute");
routeM.Stroke.Color = Color.FromArgb(50, 128,0,128);
routeM.Stroke.Width = 10;
routesOverlayM.Routes.Add(routeM);
gMapControl1.Overlays.Add(routesOverlayM);
}
Now, logic dictates that on clearing all the three, the routes must be freshly drawn, but on running the code, the color of the road just gets darker, and the task manager shows that the CPU usage is increasing with time, which leads me to conclude that the routes are being redrawn over the existing routes.
I have even refresh the map to see if it makes a difference, but it works in vain.
gMapControl1.Refresh();
Any suggestions on what I can do to fix this?
Aucun commentaire:
Enregistrer un commentaire