ThinkGeo.com    |     Documentation    |     Premium Support

Problem with FeatureLayerWpfDrawingOverlay (?)

Hello,

From version 14.4.0-beta049 to 14.4.0-beta050 something changed in ThinkGeo which crashes my software. Problem still exists in latest beta091.
I can’t figure out what I’m doing wrong in my code.

At first the update to version beta050 completely crashed my app without throwing an exception in debug mode in Visual Studio.
I changed my startup sequence of the application and know I get an exception as you can see in the picture.
As far as I can tell it has got something to do with FeatureLayerWpfDrawingOverlay.

Strange thing is now, that after the exception occurs the application continues and seems to be working just fine. So in version beta049 no exceptions, since version beta050 the exceptions exist.

After some more research I discovered that commenting out the last row does NOT result in the exception. So when I do not add MapLabelOverlay tot the overlays collection everything is working fine.
Nowhere else in my code I add this overlay to the collection.

Any idea what might cause this exception?

Private Shared MapLabelOverlay As FeatureLayerWpfDrawingOverlay
Private Shared MapLabelLayer As InMemoryFeatureLayer

 function mapView_Loaded ()
       EnsureBackGroundOverlay()
       Me.MapTools.Logo.Visibility = Visibility.Hidden
       Me.ExtentOverlay = New MyExtentInteractiveOverlay(Me)
       MapLabelOverlay.Name = "MapLabelOverlay"
       MapLabelLayer.Name = "LabelLayer"
       MapLabelOverlay.FeatureLayers.Add(MapLabelLayer)

       Me.Overlays.Add(MapLabelOverlay)       ' Add the label overlay
end function

The Stack Trace is in the picture.

Kind regards,
Guido van den Boom

Hi Guido,

It seems it’s the overlay was not correctly initialized. I guess it’s because you were calling mapView.RefreshAsync() in EnsureBackGroundOverlay(), but mapView.RefreshAsync() is not awaited, meaning the MapLabelOverlay added later will not be initialized correctly. Can you instead avoid calling mapView.RefreahAsync() in EnsureBackGroundOverlay(), but call mapView.RefreshAsync() after Me.Overlays.Add(MapLabelOverlay) see if it works?

If the above doesn’t work, please send us the code EnsureBackGroundOverlay() of and we can dig in.

Also just FYI: you will not see the exception if the overlay.ThrowingExceptionMode is set to SuppressException; It will also eat the exception if you leave the overlay to ThrowException, but set e.Handler = true in the overlay.ThrowingException event.

Thanks,
Ben

Hi Ben,

There is no RefreshAsync in EnsureBackGroundOverlay. I provided the full function at the bottom.
I should have given you more information. I copied part of the class FYI like the variables, first part of mapview_loaded and EnsureBackGroundOverlay. I commented out adding MapLabelOverlay and replaced it with TestWpfDrawingOverlay for this test.

Things I noticed:

  1. With version 049 there is no issue with this code. Starting with version 050 until present I get the exceptions
  2. As you can see there are LayerOverlays added to the Overlays collection which don’t cause issues.
  3. As soon as I change the type for TestWpfDrawingOverlay to FeatureLayerWpfDrawingOverlay in this code the exceptions occurs.
  4. There is no RefreshAsync in EnsureBackGroundOverlay. Also not in the functions that are being used in EnsureBackGroundOverlay.
  5. Commenting out EnsureBackGroundOverlay does not solve it.
  6. Although MapLabelOverlay is not added to the OverlayCollection refreshing using Me.RefreshAsync(MapLabelOverlay) does not result in an error.

Maybe featureLayerWpfDrawingOverlay is not supposed to be added to Overlays collection?
Any thoughts on this ?

The class is setup like this:

Public Class cBtgMapView
Inherits ThinkGeo.UI.Wpf.MapView
Implements IDisposable

' One overlay for all backgrounds
Private Shared MapBackgroundOverlay As Overlay

Private Shared MapHighlightOverlay As New LayerOverlay()
Private Shared MapFilteredOverlay As New LayerOverlay()
Private Shared MapSelectedOverlay As New LayerOverlay()
Private Shared MapObjectsOverlay As New LayerOverlay()
Private Shared TestWpfDrawingOverlay As New LayerOverlay()
' Add label overlay for line measurements
Private Shared MapLabelOverlay As New FeatureLayerWpfDrawingOverlay
Private Shared MapLabelLayer As New InMemoryFeatureLayer

Private Async Sub mapView_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
    Me.MapTools.Logo.Visibility = Visibility.Hidden
    EnsureBackGroundOverlay()

    MapHighlightOverlay.Name = "HighLightOverlay"
    MapFilteredOverlay.Name = "FilteredOverlay"
    MapSelectedOverlay.Name = "SelectedOverlay"
    rectangleOverlay.Name = "SelectionOverlayRectangle"
    rectangleLayer.Name = "SelectionRectangle"
    MapLabelOverlay.Name = "MapLabelOverlay"
    MapLabelLayer.Name = "LabelLayer"

    MapLabelOverlay.FeatureLayers.Add(MapLabelLayer)

    Me.Overlays.Add(MapBackgroundOverlay)
    Me.Overlays.Add(MapHighlightOverlay)
    Me.Overlays.Add(MapFilteredOverlay)
    Me.Overlays.Add(MapSelectedOverlay)
    Me.Overlays.Add(rectangleOverlay)
    'Me.Overlays.Add(MapLabelOverlay)   ' Add the label overlay
    Me.Overlays.Add(TestWpfDrawingOverlay)

    Await Me.RefreshAsync()

    'ThinkGeoDebugger.LogType = ThinkGeoLogType.All
    'ThinkGeoDebugger.LogLevel = ThinkGeoLogLevel.All

End Sub

Private Async Sub EnsureBackGroundOverlay(Optional info As BackgroundInfo = Nothing)
    ' Bepaal gewenst overlaytype
    Dim wantWmts As Boolean = (info IsNot Nothing AndAlso info.Type = BackgroundType.Wmts)

    Dim needNew As Boolean = False
    If MapBackgroundOverlay Is Nothing Then
        needNew = True
    ElseIf wantWmts AndAlso Not TypeOf MapBackgroundOverlay Is WmtsOverlay Then
        needNew = True
    ElseIf Not wantWmts AndAlso Not TypeOf MapBackgroundOverlay Is LayerOverlay Then
        needNew = True
    End If

    If needNew Then
        If MapBackgroundOverlay IsNot Nothing Then
            Me.Overlays.Remove(MapBackgroundOverlay)
        End If
        Dim usedInfo = If(info, New BackgroundInfo())
        MapBackgroundOverlay = BackgroundBuilder.CreateOverlay("BackgroundOverlay", usedInfo)
        Me.Overlays.Add(MapBackgroundOverlay)
    Else
        If info IsNot Nothing Then
            BackgroundBuilder.ApplyOverlayTiles(MapBackgroundOverlay, info)
            BackgroundBuilder.ApplyOverlayCache(MapBackgroundOverlay, info)
        End If
    End If
End Sub

Hi Guido,

Between 49 and 50, the only change is to initialize the Overlay when adding it to the MapView’s Overlay Collection. I couldn’t recreate it on my side but seems on your end, the initialization kicks off FeatureLayerWpfDrawingOverlay.Transform which then throws the exception because the required data was not collected.

We’ve added some null check in the code and it will not throw the exception anymore. Please pull the latest (ThinkGeo.UI.Wpf-beta096) and have another try.

Thanks,
Ben

Hi Ben,

Unfortunately this doesn’t solve the issue. With wpf 096 and core 095 I still get the exception.

For now I just comment out adding MapLabelOverlay to the collection. It seems to be working, although
isn’t it strange that I can RefreshAsync (MapLabelOverlay) while it has not been added to the collection?

Thanks,
Guido