从点列表创建路线 Gmap

Create a route from a list of points Gmap

我目前正在开发一个 windows 表单应用程序,它从服务器获取 PointLatLng 列表并将它们显示在地图上。

这是我到目前为止所做的(在所有点之间画线):

private void DrawRoute()
{
       List<PointLatLng> inter = new List<PointLatLng>();
       //--- 
       GMap.NET.WindowsForms.GMapOverlay markers = new GMap.NET.WindowsForms.GMapOverlay("markers");
       //--- Creating the "Start" marker below
       GMap.NET.WindowsForms.GMapMarker marker_start = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(
            new GMap.NET.PointLatLng(points[0].Lat, points[0].Lng),
            GMap.NET.WindowsForms.Markers.GMarkerGoogleType.arrow);
        marker_start.ToolTipText = "Start";

        //--- Center the map on the Start marker
        _Map.Position = new PointLatLng(points[0].Lat,points[0].Lng);
        _Map.MinZoom = 5;
        _Map.MaxZoom = 100;
        _Map.Zoom = 14;
        //---
        GMap.NET.WindowsForms.GMapOverlay polyOverlay = new GMap.NET.WindowsForms.GMapOverlay("polygons");
        for (int i=0; i<points.Count -2; i++)
        {
                anterior = false;
                //--- Adding a GmapPolygon with only 2 points (Drawing a line on the map)
                inter.Add(points[i]);
                inter.Add(points[i + 1]);
                GMap.NET.WindowsForms.GMapPolygon polygon = new GMap.NET.WindowsForms.GMapPolygon(inter, "mypolygon");
                polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Red));
                polygon.Stroke = new Pen(Color.Red, 5);
                polyOverlay.Polygons.Add(polygon);
                _Map.Overlays.Add(polyOverlay);
                inter.Remove(inter[1]);
                inter.Remove(inter[0]);
        }
        //-- Creating the "Finish" marker
        GMap.NET.WindowsForms.GMapMarker marker_finish = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(
            new GMap.NET.PointLatLng(p_anterior.Lat , p_anterior.Lng),
            GMap.NET.WindowsForms.Markers.GMarkerGoogleType.arrow);
        marker_finish.ToolTipText = "Finish";
        //--- Adding the "Start" and the "Finish" marker on map
        markers.Markers.Add(marker_start);
        markers.Markers.Add(marker_finish);            
}

我是否可以使用 gmap 库从该点列表创建路线?

创建路线就像将 List<PointLatLng> 传递给 GMapRoute 并将其添加到叠加层一样简单:

val route = new GMapRoute(points, "sample route");

route.Stroke = new Pen(GetRandomColor());
route.Stroke.Width = 4;
route.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
route.Stroke.StartCap = LineCap.NoAnchor;
route.Stroke.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
route.Stroke.LineJoin = LineJoin.Round;

routes.Routes.Add(route);

有疑问时check the sample at github