Overlay disappears

Oct 5, 2009 at 9:42 AM

Hello,

I have some overlays (as png file). With button press i show desired overlay. (With some help of Radioman i managed to show an overlay) But when i click the map the overlay disappears.  I also can not get the overlay on the desired position. It always shows up at the left uppercorner (0,0). Finally i want to zoom my overlay at the same value as my map.  All possible? If yes, how?

 

This is what i have so far:

 

 

 

 

 

 

 

 

 

 

 

 

 

<font size="2">

 

</font>

<font size="2">

strLatMap1 =

</font>

 

"51.873165"

<font size="2">

strLongMap1 =

</font>

 

"4.354719"

<font size="2">

 

</font>

 

Dim strLat As String = strLatMap1.Replace(".", ","

)<font size="2">

 

</font>

 

Dim strLong As String = strLongMap1.Replace(".", ","

)<font size="2">

 

</font>

 

Dim myImage As Image = Image.FromFile("c:\rene-links.png"

)<font size="2">

 

</font>

 

Dim

myPointX = GMap1.Location.X<font size="2">

 

</font>

 

Dim

myPointY = GMap1.Location.Y<font size="2">

 

</font>

 

Dim myRectangle As New

Drawing.Rectangle(myPointX, myPointY, myImage.Width, myImage.Height)<font size="2">

 

</font>

 

Dim myPoint As New GMap.NET.PointLatLng(CDec(strLat), CDec

(strLong))<font size="2">

 

</font>

 

Dim myCustomMarker As New

GMap.NET.WindowsForms.GMapMarker(myPoint)

g.DrawImage(myImage, myRectangle)

myCustomMarker.OnRender(g)

<font size="2">

topOverlay =

</font>

 

New GMap.NET.WindowsForms.GMapOverlay(Me.GMap1, "TopOverlay"

)

topOverlay.Markers.Add(myCustomMarker)

<font size="2">

 

</font>

 

 

When i include the last to lines the image only shows for fraction of second....

 

Thanks

 

 

 

Coordinator
Oct 5, 2009 at 11:41 AM

please try read what you post ;}

Oct 5, 2009 at 11:49 AM

Which tags do i need to show proper code??? :-)

 

Coordinator
Oct 5, 2009 at 11:51 AM

forget tags, push button and paste code ;}

Oct 5, 2009 at 12:14 PM

Better?

strLatMap1 = "51.873165"
strLongMap1 = "4.354719"
Dim strLat As String = strLatMap1.Replace(".", ",")
Dim strLong As String = strLongMap1.Replace(".", ",")
Dim myImage As Image = Image.FromFile("c:\rene-links.png")
Dim myPointX = GMap1.Location.X
Dim myPointY = GMap1.Location.Y
Dim myRectangle As New Drawing.Rectangle(myPointX, 

myPointY, myImage.Width, myImage.Height)

Dim myPoint As New GMap.NET.PointLatLng(CDec(strLat), CDec _(strLong))
GMap1.CurrentPosition = myPoint
Dim myCustomMarker As New GMap.NET.WindowsForms.GMapMarker(myPoint)
g = Graphics.FromHwnd(GMap1.Handle)
g.DrawImage(myImage, myRectangle)
myCustomMarker.OnRender(g)
topOverlay = New GMap.NET.WindowsForms.GMapOverlay(Me.GMap1, "TopOverlay")
topOverlay.Markers.Add(myCustomMarker)
GMap1.Overlays.Add(topOverlay)
Coordinator
Oct 5, 2009 at 12:19 PM

perfect in style!

..well your custom marker should be something like that in the beginning:

 

class myCustomMarker : public GMapMarker
{
    void OnRender(...)
    {
       // ... draw your picture here
    }
}

 

 

Oct 5, 2009 at 1:00 PM

Radioman,

Is there a compleet functional sample (C#) of what i want to accomplish?

Better for me is VB, but probably no vb samples available.

 

 

Hein

 

 

Coordinator
Oct 5, 2009 at 1:13 PM

 

class myCustomMarker : GMapMarker
{
      Image img;
      public myCustomMarker(PointLatLng p)
         : base(p)
      {
         img = new Bitmap(@"D:\md\Pictures\figure_5.jpg");
      }

      public override void OnRender(Graphics g)
      {
          g.DrawImageUnscaledAndClipped(img, new System.Drawing.Rectangle(base.LocalPosition.X, base.LocalPosition.Y, img.Width, img.Height));
      }
}


// ...

GMapOverlay top = new GMapOverlay(MainMap, "top");
MainMap.Overlays.Add(top);       

myCustomMarker cm = new myCustomMarker(MainMap.CurrentPosition);
top.Markers.Add(cm);

 

 

Oct 5, 2009 at 2:54 PM

Radioman,

I really don't know what i am doing wrong, but:

1) Adding the last two lines of code will cause the image to disappear just after showing it.

2) Can not get the image to stay when clicking the map

3) get the image on a dedired position.

 

Any suggestions left?

 

Hein

 

Coordinator
Oct 5, 2009 at 4:37 PM
class myCustomMarker : GMapMarker
{
      Image img;
      public myCustomMarker(PointLatLng p)
         : base(p)
      {
         img = new Bitmap(@"D:\md\Pictures\figure_5.jpg");
      }

      public override void OnRender(Graphics g)
      {
          g.DrawImageUnscaledAndClipped(img, new System.Drawing.Rectangle(base.LocalPosition.X, base.LocalPosition.Y, img.Width, img.Height));
      }
}


// ...

GMapOverlay top = new GMapOverlay(MainMap, "top");
MainMap.Overlays.Add(top);       

myCustomMarker cm = new myCustomMarker(MainMap.CurrentPosition);
top.Markers.Add(cm);

Oct 5, 2009 at 4:45 PM

Radioman,

With this code an can not get things working properly.

Maybe difference from VB and C#...

Do you know of any user of your control who is working in VB? Maybe he /she can help me out..

When i am not mistaken, the last 2 lines of code makes a new instance of myCustomMarker and gives it the name cm and adds it to the toplayers marker?

 

Hein

 

Coordinator
Oct 5, 2009 at 5:14 PM

...

Oct 5, 2009 at 6:04 PM

... means cannot help anymore?

I feel like i am almost there, but just the finishing touch is missing.

Do you still have contact with Mindstorms? I see he is programming in VB also.

Maybe he can help me out.

Or maby jumping to C# is an options (:-)....

 

Thanks anyway

 

Oct 5, 2009 at 6:31 PM
Edited Oct 5, 2009 at 6:34 PM

 

Friend Class myCustomMarker
	Inherits GMapMarker

Private img As Image Public Sub New(ByVal p As PointLatLng) MyBase.New(p) img = New Bitmap("D:\md\Pictures\figure_5.jpg") End Sub Public Overrides Sub OnRender(ByVal g As Graphics) g.DrawImageUnscaledAndClipped(img, New System.Drawing.Rectangle(MyBase.LocalPosition.X, MyBase.LocalPosition.Y, img.Width, img.Height)) End Sub
End Class Private top As GMapOverlay = New GMapOverlay(MainMap, "top") MainMap.Overlays.Add(top) Dim cm As myCustomMarker = New myCustomMarker(MainMap.CurrentPosition) top.Markers.Add(cm)
You couold also add an image property to the custum maker so that you could assinge any image to it.
Cheers

 

 

Oct 6, 2009 at 8:36 AM

Thanks Azlan,

This works great!! Now i know the purpose of OOP.....

Is it also possible to Zoom the picture in the same way as the map?

 

Thanks again... :-)

Hein

 

 

Coordinator
Oct 6, 2009 at 10:36 AM

perfect! ..about zooming, you need to know exactly scale for that, complex stuff...

Oct 6, 2009 at 12:01 PM

Radioman, Azlan,

What i do is:

I make overlay in drawing software. I zoom in your map until i have reached desired zoomlevel. I resize my drawing (overlay)  until it fits in the map.

So i guess scale is not really issue, or am i wrong? Maybe i have to use the .ScaleTransForm(ZoomFactor, Zoomfactor) of the graphics object (overlay)???

Hein

 

Coordinator
Oct 6, 2009 at 1:29 PM

well if you get exactly match for coordinates, or it isn't important?

Oct 6, 2009 at 4:29 PM

Radioman,

I just finished little program to determine lat and lng for left uppercorner of overlay.

So getting exact coördinates is solved.

Hein

 

Coordinator
Oct 6, 2009 at 5:02 PM

great ;}

Oct 7, 2009 at 9:27 AM

Radioman, Azlan,

Now i have to questions left. First: Is there a build-in option to zoom the layer in same value as map or do i have to use the zoomfunction of VB .Net?

Second: How do i add image property? (OOP s new for me....)

 

Thanks for you support!

Hein

 

Coordinator
Oct 7, 2009 at 10:54 AM

noone can learn for you ;}

Oct 10, 2009 at 9:26 AM

HeinR1965,

Hope the following code can help you:

Define the MyCustomMarker as following:

Public Class MyCustomMarker
    Inherits GMapMarker
    Private img As Image
   
    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)
        MyBase.New(p)
       
    End Sub
   
    Public Overloads Overrides Sub OnRender(ByVal g As Graphics)
        g.DrawImageUnscaledAndClipped(img, New System.Drawing.Rectangle(MyBase.LocalPosition.X, MyBase.LocalPosition.Y, img.Width, img.Height))
    End Sub
   
End Class

 

Then use it in following way:

Dim top As New GMapOverlay(gMapControl1, "top")
gMapControl1.Overlays.Add(top)

Dim cm As New MyCustomMarker(gMapControl1.CurrentPosition)
cm.MarkerImage = New Bitmap("C:\Gmap.net\PostData\zoomin.png")
top.Markers.Add(cm)

gMapControl1.Overlays.Add(top)

 

Oct 12, 2009 at 2:40 PM

Sumvel,

 

I already had a solution, but yours is much simpler and clear.

 

Thanks, works great...

 

Hein

Oct 13, 2009 at 10:27 AM

No problem, HeinR1965. We can chat for more communication if you are interested.

Nov 25, 2009 at 12:28 PM

Hi there again,

Any help for scaling/zooming overlay around here?

I am stuck.....

 

Thanx in advance

Coordinator
Nov 28, 2009 at 6:43 PM

scale objects, not overlay