Custom Icons - any help available

Topics: Windows Forms
Mar 10, 2011 at 4:50 PM


I've a nice windows forms application (vb 2008) making use of this excellent GMap.NET control.

However, I've not managed to get my head round 'Custom Markers' to be able to have a sequence of numbered icons one for each marker, each marker image being a .png 32x32 so as to be compatible with google maps.

What I'm trying to do with this control can be seen on an example I've put up on google maps here


Mar 20, 2011 at 11:11 AM
Edited Mar 20, 2011 at 12:03 PM

hi TonyS


Although not really a true answer to your problem it might give a start

I made a class derived from radioman's GMapMarker that can use any image for the marker

But what you could do is instead add a text property and a drawstring to put the text on top of the image


heres a quick example ( im sure it could be written better but it works )

Imports GMap.NET
Imports GMap.NET.WindowsForms

Public Class TextMarker
    Inherits GMapMarker

    Protected _MarkerImage As Image = My.Resources.Resources.mappointer
    Protected _Text As String = ""
    Protected Font As New Font("Consolas", 11, FontStyle.Bold)

    Public Property Image() As Image
            Return _MarkerImage
        End Get
        Set(ByVal value As Image)
            _MarkerImage = value
        End Set
    End Property

    Public Property Text As String
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

    Public Bearing As System.Nullable(Of Single)

    Public Sub New(ByVal p As PointLatLng)
        ' This call is required by the designer.

        ' Add any initialization after the InitializeComponent() call.

        Size = New System.Drawing.Size(_MarkerImage.Width, _MarkerImage.Height)
    End Sub

    Public Overrides Sub OnRender(ByVal g As Graphics)
        If _MarkerImage IsNot Nothing Then
            g.DrawImage(_MarkerImage, Me.LocalPosition)
        End If

         'Make some adjustments to the position here depending on your image
        CenterTextAt(g, _Text, Me.LocalPosition.X + _MarkerImage.Width, Me.LocalPosition.Y + _MarkerImage.Height)
    End Sub

    Public Sub CenterTextAt(ByVal gr As Graphics, ByVal txt As String, ByVal x As Single, ByVal y As Single)
        ' Make a StringFormat object that centers.
        Dim sf As New StringFormat
        sf.LineAlignment = StringAlignment.Center
        sf.Alignment = StringAlignment.Center

        ' Draw the text.
        gr.DrawString(txt, Font, Brushes.Black, x, y, sf)
    End Sub

End Class

then when you assign the marker

 Dim loc = Mapform.currentMarker.Position

        Dim m As New TextMarker(loc)

        m.Image = image

        m.Text = "1"



hope this helps

Apr 10, 2011 at 12:25 AM

Thank you i8sy,

I'll look into incorporating your class into my project - Seems a much more elegant solutions than mine (graphically designing 80+ numbered icons!)