Click here to Skip to main content
15,921,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I have a track of a route of points with a marker at each coordinate and I would like to show a tooltip when I move over a certain marker.

I was hoping to get an event like marker.OnMouseHover and returning the gmarkeritem selected but that only work when I only have one marker with istestvisible = true;

If somebody has an idea, this will be really helpfull.
Thank you very much in advance.

Best regards.
MiQi.

What I have tried:

I have tried the following:

GMapControl map;
GMapMarker currentMarker = new GMapMarker((map.position);
currentMarker.IsVisible = true;
currentMarker.IsHitTestVisible = true;
top.Markers.Add(currentMarker);
map.Overlays.Add(top);

GMapMarker markerPosition = new GMapMarker(50, 50);  new location to mark/pin.
markerPosition.IsVisible = true;
markerPosition.IsHitTestVisible = true;

GMapOverlay top = new GMapOverlay("top");

top.Markers.Add(markerPosition.marker);

private void map_OnMarkerEnter(GMapMarker item)
{
  item.ToolTipMode = MarkerTooltipMode.Always;
}

private void map_OnMarkerLeave(GMapMarker item)
{
   item.ToolTipMode = MarkerTooltipMode.OnMouseOver;
}


Only the 'currentMarker' marker is trapped by the events defined above.
The ones added on the fly are not detected. They are correctly drawn but not possible to catch them via the mouse hover / mouse mouse / mouse click.

I even have tried to use a method like this:

public bool isHitTest(Point pt)
{
 var position = map_.FromLatLngToLocal(point_);
 var rc = new Rectangle( LocalPosition.X, LocalPosition.Y, rectSize, rectSize);
 if (rc.Contains(pt))
   return true;

}
Posted
Updated 19-Nov-21 11:01am

1 solution

it's been a year from question, but if I understood well, you should see an example on the gmap.net github, it's pretty straightforward...
something like this:
C#
var gmarker = new GMapMarker(new PointLatLng);
gmarker.Offset = new System.Windows.Point();
gmarker.Zindex = 55;
//Marker is UserControl
gmarker.Shape = new Marker(gmapControl, gmarker);

//this is code behind of Marker.xaml
public class Marker
{
  private Popup _popup;
  private Label _label;
  private GMapMarker _marker;
  private GMapControl _gMapControl; 
  
  public Marker(GMapControl gMapControl, GMapMarker marker)
  {
            InitializeComponent();
            _marker = marker;
            _popup = new Popup();
            _label = new Label();
            _gMapControl = gMapControl;
            //this will be the tooltip shown along mouse
            //you can put an image if you like
            _popup.Placement = PlacementMode.Mouse;
            {
                _label.Background = Brushes.MintCream;
                _label.Foreground = Brushes.Black;
                _label.BorderBrush = Brushes.Gray;
                _label.BorderThickness = new Thickness(1);
                _label.Padding = new Thickness(2);
                _label.FontSize = 12;
                //this will show marker coordinates
                _label.Content = $"{_marker.Position.Lat}, {_marker.Position.Lng}";
            }
            _popup.Child = _label;
   }
  protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            _marker.ZIndex -= 10000;
            _popup.IsOpen = false;
            //fill with sort of original color
            var c =Color.FromArgb(230, 149, 149, 149);
            var brush = new SolidColorBrush(c);
            marker.Fill = brush;
        }

        protected override void OnMouseEnter(MouseEventArgs e)
        {
            base.OnMouseEnter(e);
            //this will bring marker in front of other
            _marker.ZIndex += 10000;
            //show tooltip
            _popup.IsOpen = true;
            //color the marker when it is hovered
            marker.Fill = Brushes.Red;
        }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900