1

I am using gmap.net and I am trying to delete the polygons on my map. When I do .Clear() , they're deleted but when I click again on the map, the old polygons I just cleared appear again on the map. Also when I click the to add a 3rd marker , somehow the 1st marker is connected to the 3rd one. Is there a way to make it that the 1st one isn't connected to any other marker in the polygon except for the 2nd marker?

Here's how it looks like for the markers: enter image description here

enter image description here

The first one is always connected to the rest of the markers

For the polygon: Here's how it looks like at first enter image description here

And this is what happens after clearing the overlays then clicking again to add a marker enter image description here

I'll have to launch my program again so it fully deletes the polygon

My code

private void gMapControl1_Load(object sender, EventArgs e) //map load
        {
            map.MapProvider = GoogleSatelliteMapProvider.Instance;
            GMaps.Instance.Mode = AccessMode.ServerOnly;
            map.Position = new GMap.NET.PointLatLng(my home coords inserted here);
            map.DragButton = MouseButtons.Left;
            map.MinZoom = 5;
            map.MaxZoom = 100;
            map.Zoom = 20;

        }




private void deletea_Click(object sender, EventArgs e) //Delete all button
        {
            map.Overlays.Clear();
            map.Refresh();
            map.Update();
        }




GMapOverlay polygons = new GMapOverlay("polygons");
        List<PointLatLng> points = new List<PointLatLng>();
        GMapPolygon polygon;
        public void map_MouseClick(object sender, MouseEventArgs e) //add marker and polygon by click
        {
            if (e.Button == MouseButtons.Left)
            {
                GMapOverlay o = new GMapOverlay("o");
                double lat1, lon1;
                lat1 = map.FromLocalToLatLng(e.X, e.Y).Lat;
                lon1 = map.FromLocalToLatLng(e.X, e.Y).Lng;
                var m = new GMarkerGoogle(new PointLatLng(lat1, lon1), GMarkerGoogleType.red);
                map.Overlays.Add(o);
                o.Markers.Add(m);
                points.Add(new PointLatLng(map.FromLocalToLatLng(e.X, e.Y).Lat,   map.FromLocalToLatLng(e.X, e.Y).Lng));
                if (points.Count > 0)
                {
                    polygon = new GMapPolygon(points, "Poly");
                    polygon.Fill = new SolidBrush(Color.FromArgb(0, Color.Red));
                    polygon.Stroke = new Pen(Color.Red, 1);
                    polygons.Polygons.Add(polygon);
                }
                map.Overlays.Add(polygons);
                map.Invalidate();
                map.Update();
            }

smfa3
  • 11
  • 1

0 Answers0