簡體   English   中英

使用 GMap.net 在地圖上繪制多段線

[英]Draw a polyline on the map using GMap.net

是的,我不是第一個提問的人,但我沒有找到答案(也許是因為我的英語不好)。 如何在地圖上繪制折線? 不是路線(方向),而只是折線,就像在 JS Google Maps API 中使用 Polyline 函數一樣。 我無法理解。

不管怎么說,還是要謝謝你。

雖然有點矯枉過正,但您可以使用 GMap 路線功能來繪制簡單的線條。 這還有一個主要優點,它可以讓您在必要時確定該線的長度(以公里為單位)。 以下是繪制單條線的方法:

GMapRoute line_layer;
GMapOverlay line_overlay

line_layer = new GMapRoute("single_line");
line_layer.Stroke = new Pen(Brushes.Black, 2); //width and color of line

line_overlay.Routes.Add(line_layer);
gMapControl1.Overlays.Add(line_overlay)

//Once the layer is created, simply add the two points you want

line_layer.Points.Add(new PointLatLng(lat, lon));
line_layer.Points.Add(new PointLatLng(lat2, lon2));

//Note that if you are using the MouseEventArgs you need to use local coordinates and convert them:
line_layer.Points.Add(gMapControl1.FromLocalToLatLng(e.X, e.Y));

//To force the draw, you need to update the route
gMapControl1.UpdateRouteLocalPosition(line_layer);

//you can even add markers at the end of the lines by adding markers to the same layer:

GMapMarker marker_ = new GMarkerCross(p);
line_overlay.Markers.Add(marker_);

好好閱讀本教程:

http://www.independent-software.com/gmap-net-tutorial-maps-markers-and-polygons/

這應該讓你開始:

GMapOverlay polyOverlay = new GMapOverlay("polygons");
IList<PointLatLng> points = new List<PointLatLng>();
points.Add(new PointLatLng(-25.969562,32.585789));
points.Add(new PointLatLng(-25.966205,32.588171));
GMapPolygon polygon = new GMapPolygon(points, "mypolygon");
polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Red));
polygon.Stroke = new Pen(Color.Red, 1);
polyOverlay.Polygons.Add(polygon);
gmap.Overlays.Add(polyOverlay);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM