Marker Mouse Click Events with GMap.NET.WindowsForms

Dec 18, 2009 at 3:36 PM

Hi guys,

I am using WindowsForms in vb.net, is it possible to fire off an event when a user clicks on a marker?

I made a custom marker with the following code...

Imports GMap.NET.WindowsForms
Imports System.Drawing
Namespace GMap.NET.WindowsForms.Markers
    Public Class GMapMarkerRect
        Inherits GMapMarker
        Public Pen As Pen
        Public Sub New(ByVal p As Global.GMap.NET.PointLatLng)
            MyBase.New(p)
            Pen = New Pen(Brushes.Red, 5)
            Size = New Size(55, 55)
        End Sub

        Public Overrides Sub OnRender(ByVal g As System.Drawing.Graphics)
            If IsMouseOver = True Then
                g.DrawRectangle(Pens.Blue, New System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - Size.Height / 2, Size.Width, Size.Height))
            Else
                g.DrawRectangle(Pens.Red, New System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - Size.Height / 2, Size.Width, Size.Height))
            End If
        End Sub
    End Class
End Namespace
any help would be great...
Coordinator
Dec 18, 2009 at 6:43 PM

it should work already

Dec 28, 2009 at 5:26 PM

How so, i have nowhere to specify the event.

Coordinator
Dec 31, 2009 at 3:22 PM

MainMap.OnMouseClick += ...

Jan 19, 2010 at 5:21 PM

Hi Radioman and all!

For the past couple of days I've been doing a test integration of GMaps.net into a Windows mobile 6 application written in VB.net. 

I too am also stuck trying to get marker click events to occur.  I've made sure all markers have a .size value set but the events aren't occuring.

I don't entirely understand what you mean by "MainMap.OnMouseClick +=" ? 

Here's a working bare-bones copy of my code:

Public Class Form1

    Private WithEvents gm As New GMapControl
    Private gmo As New GMap.NET.WindowsForms.GMapOverlay(gm, "pins")

    Private Sub gm_OnMarkerClick(ByVal item As GMap.NET.WindowsForms.GMapMarker) Handles gm.OnMarkerClick
        ' This event never happens...
        MsgBox(item.ToolTipText)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim iMenuHeight As Integer = 26

        gm.Parent = Me
        gm.Top = 0
        gm.Width = Screen.PrimaryScreen.WorkingArea.Width
        gm.Height = Screen.PrimaryScreen.WorkingArea.Height - iMenuHeight
        gm.MapType = GMap.NET.MapType.GoogleMap
        gm.CurrentPosition = New GMap.NET.PointLatLng(52.059457, 1.155624)
        gm.MinZoom = 5
        gm.MaxZoom = 19
        gm.Zoom = 8
        gm.MarkersEnabled = True
        gm.Visible = True

        LoadMarkers()
        gm.ZoomAndCenterMarkers("pins")
    End Sub


    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        gm.Dispose()
        gm = Nothing

        Application.Exit()
    End Sub

    Private Sub LoadMarkers()
        Dim p As GMap.NET.PointLatLng
        Dim m As GMap.NET.WindowsForms.GMapMarker

        ' Test marker
        p = New GMap.NET.PointLatLng(52.059457, 1.155624)
        m = New GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(p)
        m.Visible = True
        m.Size = New System.Drawing.Size(100, 100)
        m.ToolTipText = "A marker"
        m.TooltipMode = GMap.NET.WindowsForms.MarkerTooltipMode.Never
        gmo.Markers.Add(m)

        gm.Overlays.Add(gmo)
    End Sub
End Class
Any help would be greatly appreciated.
Cheers
Simon.
Coordinator
Jan 19, 2010 at 5:33 PM

i mean MainMap.OnMarkerClick += new MarkerClick(MainMap_OnMarkerClick);

..but that for mobile is disabled, be welcome to enable it ;}

Jan 19, 2010 at 6:25 PM

Thanks for the quick reply: That explains it then! 

I also tried the following when the Click event fires:

For Each m As GMap.NET.WindowsForms.GMapMarker In gmo.Markers
            If m.IsMouseOver = True Then
                MsgBox("MouseOver " & m.ToolTipText)
            End If
        Next
 
But this doesn't seem to work either?  Am I doing something wrong?
Jan 19, 2010 at 7:27 PM
Edited Jan 20, 2010 at 10:13 AM

Maybe related to this "problem"(?):  When I tap on the map I'm always returned the same 'CurrentPosition' details  i.e.: 

MsgBox(gm.CurrentPosition.Lat & "," & gm.CurrentPosition.Lng)

(I'm always returned a the same value!)

Simon.