Custom Icons - any help available

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

Hi,

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 http://maps.google.com/maps/ms?hl=en&ie=UTF8&msa=0&msid=209997516383144128030.00049dc6d2a778d50d48b&t=h&z=11

 

Mar 20, 2011 at 10:11 AM
Edited Mar 20, 2011 at 11:03 AM

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
        Get
            Return _MarkerImage
        End Get
        Set(ByVal value As Image)
            _MarkerImage = value
        End Set
    End Property

    Public Property Text As String
        Get
            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)
        MyBase.New(p)
        ' This call is required by the designer.
        InitializeComponent()

        ' 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)
        sf.Dispose()
    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"

        Mapform.POIs.Markers.Add(m)

 

hope this helps

Apr 9, 2011 at 11:25 PM

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!)

Rgds

TonyS