mercredi 27 mai 2015

Gmap.net marker removal

So I reaching out to you guys in hopes to stop coming back to square one every time. I am using the GMap.NET code for maps and markers. Adding markers and doing anything with the map hasn't been the problem its removing a single marker from the map I am having issues with. I researched everywhere on Google to remove a marker from the map but removing a marker doesn't seem to be a hot topic.

Here is the snippet from the code I use to add.

private void AddMarker_ButtonClick(object sender, AddMarkerEventArgs e)
    {
        DBDictAdd("Marker", " ",e.Latitude, e.Longitude, true, "192.168.1.1");
        m_dbMarkers.Insert(_table, dbmarkertable);
        dbmarkertable.Clear();
        GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(e.Latitude, e.Longitude),
              GMarkerGoogleType.green);
        marker.ToolTip = new GMapRoundedToolTip(marker);
        marker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
        marker.ToolTipText = (marker.Position.ToString());
        markersOverlay.Markers.Add(marker);
    }

As you can see I am using SQLite to store the ID and other information into the database for markers. I am using the database approach because I will need to store more information with the marker location. This part of the code works.

The problem I am having is calling the marker information so I can remove it. I know these 2 calls exist.

markersOverlay.Markers.Remove();
markersOverlay.Markers.RemoveAt();

I have used the remove at command but I had to do it manually and noticed using the removeat(0) command takes it from the first entry of that array every time.

This is what I have tried so far:

private void uxRemoveMarkerButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Select the marker to remove.");
            uxGmap.OnMarkerClick += new MarkerClick(uxGmap_OnMarkerClick);

        }

        private void uxGmap_OnMarkerClick(object sender, EventArgs e)
        {
            //int? mID = null;
            //DataTable da = m_dbMarkers.GetDataTable("SELECT * from markers");
            //GMapMarker marker = null;
            //PointLatLng p = new PointLatLng(lat, lng);
            //foreach (GMapMarker m in markersOverlay.Markers)
            //{
            //    if (m.Position == p)
            //        marker = m;
            //}
            //markersOverlay.Markers.Remove(marker);
            //MessageBox.Show("done");
            //foreach (DataRow dr in da.Rows)
            //{
            //    if (Convert.ToDouble(dr[3]) == lat)
            //    {
            //        MessageBox.Show(dr[3].ToString());
            //        //mID = Convert.ToInt32(dr[0]);
            //    }
            //}
            //markersOverlay.Markers.IndexOf(marker);

            //mID= Convert.ToInt32(m_dbMarkers.ExecuteScalar("SELECT ID FROM markers"));
            //m_dbMarkers.Delete(_table, String.Format("markers.ID = {0} ", mID));
            //markersOverlay.Markers.RemoveAt(mID);
            //MessageBox.Show(mID.ToString());
            uxGmap.OnMarkerClick -= new MarkerClick(uxGmap_OnMarkerClick);

        }

Any suggestions or guidance on how I can get the marker ID or marker itself when I click on it to actually remove it from the map?

Aucun commentaire:

Enregistrer un commentaire