Map provider Overlays override exception

Topics: Bugs, Help
Aug 1, 2012 at 6:08 PM

Been setting up a map within Visual Basic 2010 Express and can plot, cache, change providers, works a treat. Currently trying to setup a new map provider and ther seems to be an issue with the override of the overlays property. Wend the line gProvider = myMapTest.Instance is reached a StackOverflowException occurs where the error detail is "Unable to evaluate expression" to identify the cause and the error is flagged within the property statement of the WMSProvider class I have. This occurs with a minimal class that inherits from either GMapProvider or one of the other existing providers so does not appear to be related to any of the other code within the class. The code is not erroring with a unique provider ID error (which occurs if the code errors before the property get of the new guid can be reached). If the Overlay Property statement is removed the code runs but does not return any map tiles.

Public Class myMapTest
    Inherits GMapProvider
    Private myGUID As Object = Nothing
    Private myName As String = "myMapTest"
    Public Shared ReadOnly Instance As myMapTest
    Public Overrides ReadOnly Property Id() As Guid
        Get
            If myGUID Is Nothing Then
                myGUID = New Guid("b330a7e1-04c6-479b-ade1-f159b7986491")
            End If
            Return myGUID
        End Get
    End Property
    Public Overrides ReadOnly Property Name As String
        Get
            Return myName
        End Get
    End Property
    Private myOverlays As Object = Nothing
    Public Overrides ReadOnly Property Overlays As GMap.NET.MapProviders.GMapProvider()
        Get
            If myOverlays Is Nothing Then
                myOverlays = Instance.Overlays
            End If
            Return myOverlays
        End Get
    End Property

    Public Overrides ReadOnly Property Projection As GMap.NET.PureProjection
        Get
            Return Projections.LKS92Projection.Instance
        End Get
    End Property

    Public Shared ReadOnly UrlFormat As String = "http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.jpg"
    Public Overrides Function GetTileImage(ByVal pos As GMap.NET.GPoint, ByVal zoom As Integer) As GMap.NET.PureImage
        Dim myURL As String
        myURL = MakeTileImageUrl(pos, zoom, String.Empty)
        Return GetTileImageUsingHttp(myURL)
    End Function
    Private Function MakeTileImageUrl(ByVal pos As GPoint, ByVal zoom As Integer, ByVal language As String) As String
        Return String.Format(UrlFormat, zoom, pos.Y, pos.X)
    End Function
    Shared Sub New()
        Instance = New myMapTest
    End Sub
    Private Sub New()
    End Sub

End Class

Coordinator
Aug 1, 2012 at 6:19 PM

check the c# code, i don't know vb, you should add this to the overlays

Aug 1, 2012 at 7:24 PM

Thanks for the quick response. The code ends up recursive, which creates the stackoverflow becasue of the Instance.Overlays being returned, which leaves me puzzled as to what I can return because the base class is not a GMapProvider object. As I understand the Overlays override needs to return the current created class inctance and not the Overlays sub collection, but the VB code does not recognise the base class inheritance as a convertible class to return as a GMapProvider.

 

Aug 1, 2012 at 8:22 PM

After more than 10 hours trying to figure out how to make it work in VB I'm stumped :-( It seems like it should be possible to do, is there anyone who has managed to create a provider within VB that inherits from GMapProvider ?

Coordinator
Aug 2, 2012 at 5:36 AM

try some reflector and convert the code

Aug 2, 2012 at 7:10 AM

hello KarlT123,

i've tried the same, but still does not work. Same Code in C# works like a charme. I think it is a threading problem. If you get a solution tell me/us. :)

bye EDE

Coordinator
Aug 2, 2012 at 7:45 AM

it's just a syntax stuff, if you know vb, there should be no problems

Aug 2, 2012 at 12:05 PM
 

I have coded in VB for around 15 years and the inheritance employed within VB.Net does not appear to pass through to C# in the way the class is used in C# within the map code for providers. Using the following code runs without error but returns no map tiles because it does not point to the "this" class instance.

    Private myMapProvider As GMapProvider()
    Public Overrides ReadOnly Property Overlays As GMap.NET.MapProviders.GMapProvider()
        Get
            Return myMapProvider
        End Get
    End Property

I think the problem is that Overlays override (specified in the c#) is specified as return an array of GMapProvider rather than a single instance, which creates the problem for VB.

Using the equivalent VB code below does not work because MyClass is not accesible in the same direct way as "this" is witihin C# and lacks a direct cast option

    Private myMapProvider As GMapProvider()
    Public Overrides ReadOnly Property Overlays As GMap.NET.MapProviders.GMapProvider()
        Get
            If myMapProvider Is Nothing Then
                myMapProvider = MyClass
            End If
            Return myMapProvider
        End Get
    End Property

Using a work around will not allow a cast of a non array to an array and because GMapProvider is MustInherit with no constructor so you can't create a base to add to in the first place. Otherwise the DirectCast would perform the code equivalent of "this" and revert the new class back into a GMapProvider.

    Private myMapProvider As GMapProvider()
    Public Overrides ReadOnly Property Overlays As GMap.NET.MapProviders.GMapProvider()
        Get
            If myMapProvider Is Nothing Then
                myMapProvider = DirectCast(Instance, GMapProvider)
            End If
            Return myMapProvider
        End Get
    End Property

At this point I am starting to conclude that it is not just syntax stuff but a base incompatibility between the way GMap is written in C# and compatibility with VB.Net. when trying to create a map provider. Otherwise the code works a real treat and is pretty amazing :-)

Aug 2, 2012 at 12:21 PM

The solution would appear to be to make the constructor for GMapProvider visible to VB

Aug 2, 2012 at 12:23 PM

Is the equivalent to 'this' in VB 'me'???

 

Michael

Aug 2, 2012 at 12:26 PM

Private m_overlays As GMapProvider()
Public Overrides ReadOnly Property Overlays() As GMapProvider()
	Get
		If m_overlays Is Nothing Then
			m_overlays = New GMapProvider() {Me}
		End If
		Return m_overlays
	End Get
End Property

Aug 2, 2012 at 12:34 PM

Think that works - at least it managed to get a 404 this time. Cool, hat tip to MBDTeam.

Aug 2, 2012 at 12:44 PM

http://codeconverter.sharpdevelop.net/SnippetConverter.aspx

 

makes life easier ;-)

 

Michael

Aug 2, 2012 at 4:02 PM

Yep, certainly works a treat. Well, cool ! :-)