How to determine Latitudes and Longitudes between intersection of points Gmap.net C#

890 views Asked by At

I have a route/polygon named "BBB"(figure1,figure2) in my GMap .Net Windows form Application.I am drawing route/polygon from mouse and storing all latitudes and longitudes into List<PointLatLng>.What i want is set of Latitudes and Longitudes between two intersecting points(latitude and longitude).

Note: I have all Latitudes and Longitudes of route/polygon "BBB"(figure1,figure2) as well as "CCC"(figure1,figure2).

please let me know if something is not clear.Is there any Library or Api ?

Code: Some Code for Idea

    List<PointLatLng> ListOfDragLatLang = new List<PointLatLng>();
    PointLatLng StartingLatLng = new PointLatLng();
    PointLatLng EndingLatLng = new PointLatLng();
   // polygons
    GMapPolygon polygon;

    readonly GMapOverlay top = new GMapOverlay();
    internal readonly GMapOverlay objects = new GMapOverlay("objects");//for storing markers 
    internal readonly GMapOverlay routes = new GMapOverlay("routes");// for storing routes
    internal readonly GMapOverlay polygons = new GMapOverlay("polygons");//for storing polygons

 public bool IsErasorCursorVisible { get => _IsErasorCursorVisible; set => _IsErasorCursorVisible = value; }
    public bool IsPencilCursorVisible { get => _IsPencilCursorVisible; set => _IsPencilCursorVisible = value; }
    public bool IsNormalCursorVisible { get => _IsNormalCursorVisible; set => _IsNormalCursorVisible = value; }
private void MainMap_MouseUp(object sender, MouseEventArgs e)
    {
        PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);
        lblLatitude.Text = OnMouse.Lat.ToString();
        lblLongitude.Text = OnMouse.Lng.ToString();

            if (IsPencilCursorVisible && IsDrawing)
            {

                EndingLatLng = MainMap.FromLocalToLatLng(e.X, e.Y);
                ListOfDragLatLang.Add(StartingLatLng);
                IsDragging = false;
                IsDrawing = false;
                MainMap.DragButton = MouseButtons.Right;

                //polygon = new GMapPolygon(ListOfDragLatLang, txtZoneName.Text);
                //polygon.LocalPoints.AddRange(ListOfPoints);
                //polygon.Stroke = new Pen(Color.Black, 3);
                //polygon.IsHitTestVisible = true;
                //polygon.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                //polygons.Polygons.Add(polygon);
                //MainMap.UpdatePolygonLocalPosition(polygon);
                lblTotalPolygonsAdded.Text = polygons.Polygons.Count.ToString();

                for (int i = 0; i < ListOfDragLatLang.Count; i++)
                {
                        AddPinPointToPolygon(ListOfDragLatLang[i], i, txtZoneName.Text);                        
                }
                RegenerateRoute(txtZoneName.Text);

                GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(ListOfDragLatLang.Sum(c => c.Lat) / ListOfDragLatLang.Count, ListOfDragLatLang.Sum(c => c.Lng) / ListOfDragLatLang.Count), GMarkerGoogleType.orange_dot);
                marker.ToolTip = new GMapBaloonToolTip(marker);
                marker.ToolTipText = txtZoneName.Text;
                marker.ToolTipMode = MarkerTooltipMode.Always;

                marker.IsVisible = true;
                marker.Tag = txtZoneName.Text;
                objects.Markers.Add(marker);
                MainMap.UpdateMarkerLocalPosition(marker);
                MainMap.UpdatePolygonLocalPosition(polygon);




            }
    }

private void MainMap_MouseDown(object sender, MouseEventArgs e)
    {
        PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);

        if (e.Button == MouseButtons.Left)
        {
            if (IsPencilCursorVisible && IsDrawing)
            {
                StartingLatLng = OnMouse;
                ListOfDragLatLang.Add(StartingLatLng);
                ListOfPoints.Add(new GPoint(e.X, e.Y));
                IsDragging = true;
                MainMap.DragButton = MouseButtons.Middle;

                currentRoute = new GMapRoute(txtZoneName.Text);
                currentRoute.Stroke = new Pen(Color.Black, 3);
                currentRoute.IsHitTestVisible = true;
                routes.Routes.Add(currentRoute);
                MainMap.UpdateRouteLocalPosition(currentRoute);
                //polygon = new GMapPolygon(ListOfDragLatLang,txtZoneName.Text);
                //polygon.LocalPoints.AddRange(ListOfPoints);
                //polygon.Stroke = new Pen(Color.Black, 3);
                //polygon.IsHitTestVisible = true;
                //polygon.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                //polygons.Polygons.Add(polygon);
                //MainMap.UpdatePolygonLocalPosition(polygon);

            }

        }


    }

    private void MainMap_MouseMove(object sender, MouseEventArgs e)
    {
        PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);

        lblLatitude.Text = OnMouse.Lat.ToString();
        lblLongitude.Text = OnMouse.Lng.ToString();

        if (e.Button == MouseButtons.Left)
        {
            if (IsPencilCursorVisible && IsDrawing)
            {


                if (MainMap.IsMouseOverPolygon)
                {
                    MainMap.Cursor = MainCursor;
                }
                else
                {
                    MainMap.Cursor = PencilCursor;
                }
                IsDragging = true;
                ListOfPoints.Add(new GPoint(e.X, e.Y));
                ListOfDragLatLang.Add(OnMouse);
                lblTotalLatLng.Text = ListOfDragLatLang.Count.ToString();
                currentRoute.Points.Add(OnMouse);
                MainMap.UpdateRouteLocalPosition(currentRoute);
                //polygon.Points.Add(OnMouse);
                //MainMap.UpdatePolygonLocalPosition(polygon);


            }
            else
            {
                PointLatLng pnew = MainMap.FromLocalToLatLng(e.X, e.Y);

                if (CurentRectMarker == null)
                {
                    return;
                }

                int? pIndex = (int?)CurentRectMarker.Tag;
                if (pIndex.HasValue)
                {

                    if (pIndex < currentRoute.Points.Count)
                    {
                        currentRoute.Points[pIndex.Value] = pnew;
                        MainMap.UpdateRouteLocalPosition(currentRoute);
                    }
                    //if (pIndex < polygon.Points.Count)
                    //{
                    //    polygon.Points[pIndex.Value] = pnew;
                    //    MainMap.UpdatePolygonLocalPosition(polygon);
                    //}
                }

                if (currentMarker.IsVisible)
                {
                    currentMarker.Position = pnew;
                }
                CurentRectMarker.Position = pnew;

                if (CurentRectMarker.InnerMarker != null)
                {
                    CurentRectMarker.InnerMarker.Position = pnew;
                }

            }
            MainMap.Refresh();

        }
    }

Figure 1

enter image description here

Figure 2 enter image description here

Question:How to get the Latitudes and Longitudes of yellow color edge in figure 2 between intersecting point "A" and "B"?

1

There are 1 answers

0
Ben On

Assuming your List is in the correct order

Find the index of the coordinate at point A and B in your List and then create a new list using all points that are between the two indexes.