我正在创建一个从 CSV 导入一组值的应用程序,包括测量某些内容时的一组坐标。我从 CSV 文件创建了一个对象列表,并尝试创建一个提取的坐标列表以在地图上创建一条路线,因此我尝试从其他人那里寻找他们如何创建路线的方法,但在我的情况下没有任何效果
public partial class RouteWindow : Window
{
private GMapControl gmapControl;
public RouteWindow(List<BaseCsvData> list)
{
InitializeComponent();
List<(double Latitude, double Longitude)> coordinates =
list.Select(data => (data.Latitude, data.Longitude)).ToList();
gmapControl = new GMapControl();
gmapControl.Width = 800;
gmapControl.Height = 460;
// init
gmapControl.MapProvider = GMapProviders.OpenStreetMap;
GMaps.Instance.Mode = AccessMode.ServerOnly;
gmapControl.MinZoom = 1;
gmapControl.MaxZoom = 18;
gmapControl.Zoom = 12;
gmapControl.Position = new PointLatLng(coordinates[0].Latitude, coordinates[0].Longitude);
// markers
foreach (var (latitude, longitude) in coordinates)
{
GMapMarker marker = new GMapMarker(new PointLatLng(latitude, longitude));
gmapControl.Markers.Add(marker);
}
// list of points
List<PointLatLng> routePoints = coordinates.Select(c => new PointLatLng(c.Latitude, c.Longitude)).ToList();
// add GMapControl to grid
Grid grid = new Grid();
grid.Children.Add(gmapControl);
this.Content = grid;
// zooming
gmapControl.MouseWheel += GmapControl_MouseWheel;
this.Closed += (sender, e) =>
{
DisposeMapControl();
};
}
private void GmapControl_MouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
if (e.Delta > 0)
{
// Zoom in
gmapControl.Zoom += 1;
}
else if (e.Delta < 0)
{
// Zoom out, with a minimum zoom level
if (gmapControl.Zoom > 1)
{
gmapControl.Zoom -= 1;
}
}
}
public void DisposeMapControl()
{
gmapControl.Dispose();
}
}
我尝试了其他一些在线项目的代码,一些来自 WinForms,我尝试向 ChatGPT 寻求帮助,但它返回了
// Create a route
GMapRoute route = new GMapRoute(routePoints, "Route");
route.Stroke = new Pen(Brushes.Blue, 3).Frozen; // Set the color and thickness of the route line
gmapControl.Overlays.Add(route);
Stroke 'GMapRoute' 上的错误不包含 'Stroke' 的定义,并且找不到接受类型 'GMapRoute' 的第一个参数的可访问扩展方法 'Stroke' (您是否缺少 using 指令或程序集引用?)以及叠加层的相同错误。我对 C# 比较陌生,并且使用一些地图库,所以我将感谢您的任何建议
GMapRoute route = new GMapRoute(routePoints);
route.Shape = new Path() { Stroke = new SolidColorBrush(Colors.Blue), StrokeThickness = 3 };
gmapControl.Markers.Add(route);