Custom icons for markers

Jun 8, 2009 at 11:39 PM

I would like to be able to use local icon images in my windows app using the Gmap control but gave not been able to find a way.

Is there any sample code out there please

Regards

 

BTW - I LOVE this control

Jun 9, 2009 at 3:00 AM

Look at the source code in the Markers folder of WindowsForms. The GoogleMakerGreen class is something you can implement yourself really easily, and use your own image or pull it from the Resource cache like the demo does.

If you don't want a Marker but want an actual image ... you could probably do it AS a marker because there would be no difference ...

Jun 9, 2009 at 8:48 PM
Edited Jun 9, 2009 at 8:49 PM

Thanks Untameable.  I finally figured out how to do this also after you tip to check out the Markers folder.

Jun 10, 2009 at 10:39 PM

Thanks Untamable - that was a big help

Below is my code for the next guy with issues.....

 

Public Class GMapMarker_Custom

    Inherits GMapMarker

    Dim IconPath As String
    Dim myImage As Image

    Public Sub New(ByVal p As PointLatLng, ByVal Unit_Name As String)


        MyBase.New(p)
        IconPath = Get_GIS_Icon(Unit_Name)
        myImage = Image.FromFile(IconPath)

    End Sub

    Public Overloads Overrides Sub OnRender(ByVal g As Graphics)

        g.DrawImageUnscaled(myImage, LocalPosition.X - 10, LocalPosition.Y - 34)

    End Sub

End Class

Jun 11, 2009 at 5:32 AM

use Offset and Size instead of (- 10, - 34)

Sep 20, 2010 at 12:07 PM

hello 

i got some problem when i use my own image based on the GoogleMakerGreen  class

g.DrawImageUnscaled(Resources.marker, LocalPosition.X, LocalPosition.Y);

i added my image  to Resource and replace Resources.marker in the above line

i can show my own image, but it's only too big than the origin one in GoogleMakerGreen  

my image is same size as image in the GoogleMakerGreen  class (i just changed the color)

i also tried to fix the size instead of the origin way 

from

Size = new System.Drawing.Size(Resources.marker.Width, Resources.marker.Height);

to

Size = new System.Drawing.Size(20,34);

but it still doesn't work

thanks

Sep 20, 2010 at 1:24 PM

marker.Size != Image.Size, you can resize the image itself or pass width and height to render function g.DrawImage

Feb 21, 2012 at 11:27 PM
Edited Feb 21, 2012 at 11:42 PM

I've been giving this a try, but haven't been successful.

I copied the code kindly posted by neoterra, with a minor amendment to avoid an error because there's no reference to Get_GIS_Icon

   Public Class GMapMarker_Custom

        Inherits GMapMarker

        'Dim IconPath As String
        Dim myImage As Image

        Public Sub New(ByVal p As GMap.NET.PointLatLng, ByVal Unit_Name As String)


            MyBase.New(p)
            myImage = Image.FromFile("C:\temp1\test1.tiff")

        End Sub

        Public Overloads Overrides Sub OnRender(ByVal g As Graphics)

            g.DrawImageUnscaled(myImage, LocalPosition.X - 10, LocalPosition.Y - 34)

        End Sub

    End Class

but that doesn't show how or in what order we're supposed to use them- this is what I tried

        Dim mapcentre As GMap.NET.PointLatLng
        Dim g1 As Graphics
        Dim i1 As Image
        Dim nm1 As New GMapMarker_Custom(mapcentre, "test")

        mapcentre = New GMap.NET.PointLatLng(50.8380341400355, -0.777969360351563)
        i1 = Image.FromFile("C:\temp\test1.tiff")
        g1 = Graphics.FromImage(i1)
        nm1.Position = mapcentre
        nm1.OnRender(g1)
        nm1.IsVisible = True

        GMapControl1.Position = mapcentre

        GMapControl1.Refresh()

When I run this, I don't get any errors but nothing happens either.
Also, I'm puzzled by how I pass a pre-formed graphics object to OnRender.

Can anyone tell me where I'm going wrong please?

Best regards and many thanks for your effors

Feb 22, 2012 at 7:33 AM

wtf ;/, check the demos source, OnRender is called by the system, just add the marker to your overlay

Feb 22, 2012 at 8:57 AM

Thanks Radioman - much appreciated