检查路线是否包含具有特定坐标的点

时间:2018-09-21 20:26:25

标签: c# openstreetmap gmap.net


我将GMap.net与OpenStreetMap porvider一起使用,以在两个标记之间创建路线。有什么方法可以了解路线 _route 是否包含标记 TargetPoint ?或者最好对位于 traces 列表中的 MapRoute 对象执行相同的操作。
下面是我的代码:

public partial class Routes : Form
{
    internal readonly GMapOverlay _objects = new GMapOverlay("objects");
    GMapRoute _route = new GMapRoute("NewRoute");
    List<MapRoute> traces = new List<MapRoute>(); 
    PointLatLng TargetPoint = new PointLatLng(59.9362361841233, 30.3181350231171);

    public Routes()
    {
        InitializeComponent();
        gMapControl.MapProvider = GMapProviders.OpenStreetMap;
        gMapControl.Manager.Mode = AccessMode.ServerAndCache;

        //center map on moscow
        gMapControl.Position = new PointLatLng(59.939095, 30.315868);
        gMapControl.MaxZoom = 40;
        gMapControl.Zoom = 16;

        gMapControl.Overlays.Add(_objects);

        _objects.Markers.Add(new GMarkerGoogle(new PointLatLng(59.9375314747945, 30.312352180481), GMarkerGoogleType.green_small));
        _objects.Markers.Add(new GMarkerGoogle(new PointLatLng(59.9367306579015, 30.3139400482178), GMarkerGoogleType.green_small));

        foreach (var marker in _objects.Markers)
            _halts.Add(marker.Position);
        InitRoute();
    }

    private void InitRoute()
    {
            RoutingProvider rp = gMapControl.MapProvider as RoutingProvider;
            rp = GMapProviders.OpenStreetMapRivc; // use OpenStreetMap if provider does not implement routing
            for (int i = 0; i < _halts.Count - 1; i++)
            {
                MapRoute route = rp.GetRoute(_halts[i], _halts[i + 1], false, false, (int) gMapControl.Zoom, true);
                traces.Add(route);
            }
            _route.IsHitTestVisible = true;
            foreach (var trace in traces)
                _route.Points.AddRange(trace.Points.Where(x => !_route.Points.Contains(x)));
            _objects.Routes.Add(_route);

        gMapControl.ZoomAndCenterRoute(_route);
    }

谢谢!

0 个答案:

没有答案