How can I change marker image on a marker click

Topics: Windows Forms
Apr 7, 2013 at 8:10 PM
Let say I have 200 markers with custom images on the Gmap. I click one of the marker to signal a 'status' change on this marker/position. I want to be able to just change image and tooltip on the clicked marker.

I can catch the marker click but how to change marker image and tooltip..
Apr 8, 2013 at 7:23 AM
customMarker.Image = images.MyImage;
Apr 8, 2013 at 7:59 AM
Edited Apr 8, 2013 at 8:00 AM
In the gmap_markerclick subroutine I get the ITEM that I clicked on. The marker is one of ~200 markers in the same layer. I want to avoid to delete/redraw all 200 markers to reflect the status change my marker click imposes.

How can I loop trough the marker collection in a layer to find a particular item.tag and change custom image.


On the item, I cant find image property ?
Apr 8, 2013 at 8:26 AM
void MainMap_OnMarkerClick(GMapMarker item, MouseEventArgs e)
{
  var customMarker = item as CustomMarker;
  customMarker.Image = images.MyImage;
}
Apr 8, 2013 at 4:01 PM
Thank you Radioman !

And for you who want to acomplish the same with VB here is my code.

Private Sub GMap1_OnMarkerClick(ByVal item As GMap.NET.WindowsForms.GMapMarker, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GMap1.OnMarkerClick
            Dim customMarker = TryCast(item, GMapMarkerImage)
            customMarker.markerimage = My.Resources.floodg
            customMarker.tooltiptext = "Rapporterad tömd"

            GMap1.Invalidate()
End Sub


Public Class GMapMarkerImage
Inherits GMap.NET.WindowsForms.GMapMarker
Private img As Image

''' <summary>
''' The image to display as a marker.
''' </summary>
Public Property MarkerImage() As Image
    Get
        Return img
    End Get
    Set(ByVal value As Image)
        img = value
    End Set
End Property


Public Sub New(ByVal p As PointLatLng, ByVal image As Image)
    MyBase.New(p)
    img = image
    Size = img.Size
    Offset = New System.Drawing.Point(-Size.Width / 2, -Size.Height / 2)
End Sub

Public Overrides Sub OnRender(ByVal g As Graphics)
    g.DrawImage(img, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height)
End Sub
End Class
May 14, 2015 at 3:29 AM
Thank You hjojohan
good help for me