MarkerClick event not works

Topics: Windows Forms
Jan 18, 2013 at 9:34 AM

Hello!

I have got one problem, I want show tooltip with informations about marker when i click on this marker. There is my code:

 

GMapMarkerOwn gown = new GMapMarkerOwn(new PointLatLng(souradnice1, souradnice2), color);
gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick);
overlayOne.Markers.Add(gown);

 

 And event:

 

void gMapControl1_OnMarkerClick(GMapMarker item, MouseEventArgs e)
{
    MessageBox.Show(item.ToolTipText);
}

But this isn't works. Can someone help me? Many thanks

 

Coordinator
Jan 18, 2013 at 10:16 AM

you use custom marker, you have to set the Size property, because it determines the area of the mouse input

Jan 18, 2013 at 10:25 AM

Thank you very much radioman.

For example i set

gown.Size = Size.Add(new System.Drawing.Size(2, 2), new System.Drawing.Size(2, 2));

Event is now works but message is displaying again and again..to infinity. Any solution?

Jan 18, 2013 at 10:26 AM
Edited Jan 18, 2013 at 10:28 AM

And message box is empty.. :-(

Coordinator
Jan 18, 2013 at 10:41 AM

there is only one event per click, and you can show any text you want to ;}

Jan 18, 2013 at 11:02 AM

Ok, message is now position, but still the same again and again..wait..it's displayed 1446 times..and i have 1446 markers..but position is from one marker.. i don't understand it..

Coordinator
Jan 18, 2013 at 11:09 AM

maybe you add the same overlay 1446 times

Jan 18, 2013 at 11:31 AM

No, this is my method which displays the map after click button

 

private void ZobrazMapu()
     {
            gMapControl1.MapProvider = GMapProviders.CzechSatelliteMap;
            comboBox4.SelectedItem = "Czech Sat Map";
          
            gMapControl1.Zoom = 10;
            
            gMapControl1.Manager.Mode = AccessMode.ServerAndCache;//funguje
          
            Size siz = new System.Drawing.Size(610, 410);
            gMapControl1.ClientSize = siz;
            overlayOne = new GMapOverlay("OverlayOne");

            List<PointLatLng> route1 = new List<PointLatLng>();
            List<PointLatLng> route2 = new List<PointLatLng>();
            int poc = 0;
            foreach (string list in pole_souradnic)
            {
                if (!pole_souradnic[poc].Contains("GPS signal is not fixed!"))
                {
                    double souradnice1 = 0.0;
                    double souradnice2 = 0.0;
                    string a = pole_souradnic[poc].ToString().Split(',')[0];
                    string b = pole_souradnic[poc].ToString().Split(',')[1];

                    souradnice1 = double.Parse(a, CultureInfo.InvariantCulture);
                    souradnice2 = double.Parse(b, CultureInfo.InvariantCulture);
                   
                    route1.Add(new PointLatLng(souradnice1, souradnice2));
                    gMapControl1.ZoomAndCenterMarkers("OverlayOne");
                   
                    GMapMarkerOwn gown = new GMapMarkerOwn(new PointLatLng(souradnice1, souradnice2), zobrazenych_map);
                    gown.Size = Size.Add(new System.Drawing.Size(2, 2), new System.Drawing.Size(2, 2));
                    gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick);
                    overlayOne.Markers.Add(gown);
                    
                }
                if(port_open!=true)
                    poc++;
            }
            GMapRoute r = new GMapRoute(route1, "Route1");

            r.Stroke.Width = 1;
            r.Stroke.Color = getColor();
            
            gMapControl1.ZoomAndCenterRoute(r);
            overlayOne.Routes.Add(r);
            gMapControl1.Overlays.Add(overlayOne);
            gMapControl1.ZoomAndCenterMarkers("OverlayOne");
            
            zobrazenych_map++;
        }

Adding overlay is in the end of this code..

Coordinator
Jan 18, 2013 at 11:40 AM
Edited Jan 18, 2013 at 11:43 AM

 

for(int i = 0; i < 1446; i++)
{
  // you subscribe event in the loop 1446 times 
  gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick); 
}

you only need to do this once at the start

p.s. do not call gMapControl1.ZoomAndCenterMarkers("OverlayOne"); in the loop

Jan 18, 2013 at 11:42 AM
Edited Jan 18, 2013 at 11:45 AM

You're right, great :-) Thanks ^^

Jan 18, 2013 at 1:08 PM

And now..i am able to delete marker on click. But what I need to do to refresh route? I was thinking about delete whole route, but it's too hard.. Can i delete only one point from route acording to deleted marker?

Coordinator
Jan 18, 2013 at 1:13 PM

change the points and call map.UpdateRouteLocalPosition

Jan 18, 2013 at 1:40 PM

Nice, it's works fine :-)

Feb 25, 2013 at 9:24 AM
Edited Feb 25, 2013 at 3:19 PM
Hello, problem is back, i have more routes on map - for example 4, when i click on the marker, popup is displaying 4 times..as count of tracks..the same information about one point. Definition gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick); is deleted, now i defined event directly in properties of map. Some idea?
Coordinator
Feb 26, 2013 at 1:55 PM
nop ;}
Feb 27, 2013 at 3:35 PM
Problem solved.. gMapControl1.Overlays.Add(overlayOne); in loop :-)