ThinkGeo.com    |     Documentation    |     Premium Support

Popoverlay Error

I tried the latest beta version of Thinkgeo, but there has been a change to the Popupoverlay.
Because of this change the popups don’t show in the right position anymore.
They are far away from the position I use to show the popup (see image).

Beta version 14.3.0-beta060 was working just fine. Sinds version beta061 there seems to be a problem.
I’ve used my code for the popups since version 12.x

Can you please look in to this?

Regards,
Guido van den Boom

Hi Guido,

We did make some changes about marker rotation between beta60 and beta61 (setting Popup’s RenderTransform in OnApplyTemplate()) , but I couldn’t figure how that will bring in an issue. It works fine in our test program as well. Can you share me some of your code? Also does it go back to the correct place when you pan/zoom the map?

Thanks,
Ben

Hi Ben,

Please find my code below (as I mentioned worked for many years since version 12).
I deleted some DIM rows, so you don’t have to worry about that.

Panning is not a problem, but when I zoom in/out the popups seem to hold on to the position in the map, not the coördinates of the actual position.

I hope you can download the file through the link. I created a little video showing what is happening.

https://wetransfer.com/downloads/e28a19acb55e130c92f7a33850774c1d20250226074508/2c469cc50dbe6973b2204771e1c839ce20250226074531/dc9d6e?t_exp=1740815108&t_lsid=6be413c3-bbdb-48f8-bf39-61e1679383f4&t_network=email&t_rid=ZW1haWx8NjdiZWM2ODUwMmI0Mzc4ZjAwNjQ5NDM0&t_s=download_link&t_ts=1740555931

Private Sub AddPopups()
    Dim Popupoverlay As PopupOverlay

    Popupoverlay = New PopupOverlay With {.Name = "Popups_Meten"}
    mapView2.Overlays.Add(Popupoverlay)

    Dim PConv As ProjectionConverter = New ProjectionConverter(proj28992, 3857)
    mapView2.TrackOverlay.TrackShapeLayer.Open()

    Dim TrackFeatures = mapView2.TrackOverlay.TrackShapeLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns)

    For Each feature In TrackFeatures
        Dim ReturnShape As BaseShape
        PConv.Open()
        ReturnShape = PConv.ConvertToExternalProjection(feature.GetShape())
        PConv.Close()
        Dim shapeWKT As String = ReturnShape.GetWellKnownText()

        If shapeWKT.ToString.Contains("POINT") Then
            dX = CType(ReturnShape, PointShape).X
            dY = CType(ReturnShape, PointShape).Y

            Dim specifier As String = "0.###"
            Dim sCulture As New CultureInfo("en-UK")

            sPopup = "x=" & Math.Round(dX, 2).ToString(specifier, sCulture) & " y=" & Math.Round(dY, 2).ToString(specifier, sCulture)

        ElseIf shapeWKT.ToString.Contains("POLYGON") Then
            Try
                dOpp = CType(ReturnShape, AreaBaseShape).GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters)
                dOmtrek = CType(ReturnShape, AreaBaseShape).GetPerimeter(GeographyUnit.Meter, DistanceUnit.Meter)

                sPopup = "Oppervlakte=" & Math.Round(dOpp, 2) & " m² (Omtrek=" & Math.Round(dOmtrek, 2) & "m¹)"
            Catch ex As Exception
                dOpp = 0
                dOmtrek = 0
            End Try
        ElseIf shapeWKT.ToString.Contains("LINESTRING") Then
            Try
                dlength = CType(ReturnShape, LineBaseShape).GetLength(GeographyUnit.Meter, DistanceUnit.Meter)
                sPopup = "L=" & Math.Round(dlength, 2) & " m¹"

            Catch ex As Exception
                dlength = 0
            End Try
        End If

        Dim popup = New Popup(feature.GetShape().GetCenterPoint()) With {
            .Content = sPopup }
        Popupoverlay.Popups.Add(popup)
    Next

    mapView2.TrackOverlay.TrackShapeLayer.Close()
    mapView2.RefreshAsync()
End Sub

I hope you can reproduce the problem and solve it.

Regards,
Guido van den Boom

Hi Guido,

Thanks for the code and video. I still cannot recreate it but found a potential place that might lead to this issue. I’ve fixed it in beta076, please pull the latest and have another try?

Thanks,
Ben

Hi Ben,

I tried beta076, but unfortunately still the same issue. When zooming in and out the popup does not stay on the same place on the map, but sort of wanders across the map.
I hope you have an idea what changed between version 060 en 061.

I went back to beta060 and then it works again. The picture is what I expect to see.

Regards,
Guido van den Boom

Hi Guido,

Built another one for you. Please pull beta077 and let me know if that works.

Thanks,
Ben

Hi Ben,

I’m sorry to inform you that beta077 is also not the solution.
I think it’s weird that the popup does not maintain it’s position in relation to the map.
I convert from 3857 to 28992 and vice versa, has something changed in the converson?

Regards,
Guido van den Boom

HI Guido,

Beta077 reverted the popup related change between beta60 and beta61. So there must be something else leading to this issue. It could because of the projection but I cannot tell from the code you sent over. Any chance you can send us a demo project to recreate it?

Thanks,
Ben

Hi Ben,

I don’t know how to create a demo project. I’m a pretty novice programmer and many functions we use are created by a colleague in several DLL’s.

I checked all the values in the Watch section in Visual Studio. Those are all correct and exactly the same whether I use beta060 or beta061+. So projection is not the issue.

I created another video for you because the same problem occurs in SimpleMarkerOverlay.
In the video I select an address (but I can also use coördinates) and Zoom to that address with the function below. This works fine and perfectly zooms in and centers the location (both address and coördinates).

When I’m zoomed in on the address and press ‘Place marker’ it starts the function ‘PlaatsMarker’ and the marker is placed on the wrong spot again and behaves like the popup.
It’s like the popup and marker are not using the right Srid or the coördinates are scrambled.

Does this help you? If you do need a demo project, can you give me a startproject (VB.NET).

Sub ZoomToAddress(ByVal markerinfo As cAdresZoeken_MarkerInfo)
    mapView2.ZoomToAsync(markerinfo.Point, 1000)
    mapView2.RefreshAsync()
End Sub

Sub PlaatsMarker(ByVal markerInfo As cAdresZoeken_MarkerInfo)
    Dim simpleMarkerOverlay As SimpleMarkerOverlay
    Try
        simpleMarkerOverlay = mapView2.Overlays("simpleMarkerOverlay")
    Catch ex As Exception
        simpleMarkerOverlay = New SimpleMarkerOverlay()
        mapView2.Overlays.Add("simpleMarkerOverlay", simpleMarkerOverlay)
    End Try

    Dim marker = New Marker(markerInfo.Point) With {
            .ImageSource = New BitmapImage(New Uri("/Resources/AQUA.png", UriKind.RelativeOrAbsolute)),
            .Width = 20,
            .Height = 34,
            .YOffset = -17
        }

    If markerInfo.Adres.Length > 0 Then marker.ToolTip = markerInfo.Adres
    simpleMarkerOverlay.Markers.Add(marker)
    simpleMarkerOverlay.RefreshAsync()
    mapView2.RefreshAsync()
End Sub

Regards,
Guido van den Boom

Hi Guido,

Here I created a VB demo for you. It’s using beta077 running on .net 8, It creates a “Hello World” popup every time finished tracking a shape.

PopupsDemo.zip (5.3 KB)

Please update it and recreate your issue.

Thanks,
Ben

Hi Ben,

I think I was able to reproduce the issue in your demo project.
In our project my colleague added some mapview settings. One of these settings is causing an issue since version 061. I hope this helps to find the problem and a solution.

2025-02-27_18-43-09

In this video you can see the issue in your demo project:

This is the MapView_Loaded function with the issue in your demo project:

Private Async Sub MapView_Loaded(sender As Object, e As RoutedEventArgs)
    ' Set the map's unit of measurement to meters (Spherical Mercator)
    MapView.MapUnit = GeographyUnit.Meter


    ' Add Cloud Maps as a background overlay
    Dim thinkGeoCloudVectorMapsOverlay As New ThinkGeoCloudVectorMapsOverlay With {
        .ClientId = "AOf22-EmFgIEeK4qkdx5HhwbkBjiRCmIDbIYuP8jWbc~",
        .ClientSecret = "xK0pbuywjaZx4sqauaga8DMlzZprz0qQSjLTow90EhBx5D8gFd2krw~~",
        .MapType = ThinkGeoCloudVectorMapsMapType.Light}

    MapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay)

    ' Set the map extent
    MapView.CurrentExtent = New RectangleShape(-10786436, 3918518, -10769429, 3906002)


    '==================================================================================
    ' ONE OF THESE MIGHT CAUSE THE PROBLEM

    MapView.ZoomLevelSnappingMode = ThinkGeo.Core.ZoomLevelSnappingMode.SnapUp
    MapView.MapTools.PanZoomBar.PanPercentage = 10
    MapView.CurrentExtent = New RectangleShape(352221, 7098248, 829188, 6516103)

    MapView.StretchMode = MapViewStretchMode.ShowNewTilesOnStart
    MapView.DefaultOverlaysRenderSequenceType = OverlaysRenderSequenceType.Sequential
    MapView.MapTools.Logo.Visibility = Visibility.Hidden

    MapView.MinimumScale = 1
    MapView.IsManipulationEnabled = True
    '==================================================================================



    ' Create the layer that will store the drawn shapes
    Dim featureLayer As New InMemoryFeatureLayer()

    ' Add styles for the layer
    featureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyle.CreateSimpleCircleStyle(GeoColors.Blue, 8, GeoColors.Black)
    featureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColors.Blue, 4, True)
    featureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColors.Blue, GeoColors.Black)
    featureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

    ' Add the layer to a LayerOverlay
    Dim layerOverlay As New LayerOverlay()
    layerOverlay.Layers.Add("featureLayer", featureLayer)
    MapView.Overlays.Add("layerOverlay", layerOverlay)

    AddHandler MapView.TrackOverlay.TrackEnded, AddressOf TrackOverlay_TrackEnded
    popupOverlay = New PopupOverlay()
    MapView.Overlays.Add(popupOverlay)

    Await MapView.RefreshAsync()
End Sub

Regards,
Guido van den Boom

Hi Guido,

I see the issue with package beta67 and newer, but you said the issue was brought in since beta61. So I am not sure if it’s the same issue you met at the very beginning. Can you recreate the issue with beta61?

Thanks,
Ben

Hi Ben,

I think its the issue with beta67. I couldn’t reproduce with 61 en 65 also worked.
That’s because both WPF and Core were the same version.

When 61 failed I only changed WPF back to 61, but Core was still on a higher version (No idea which one, because I thought they would both change when I change WPF version).
WPF 61 + Core 77 works for me now in my application.

WPF 77 + Core 77 still fails.

So I think you found the issue.

Regards,
Guido van den Boom

Hi Guido,

That’s why I couldn’t find any clue between beta60 and 61. :slight_smile: All right, the issue now has been fixed in beta 78, pull the latest and have another try.

Thanks,
Ben

Hi Ben,

I’m sorry about that !
I did not realize Core and WPF versions could be different.
Will try tomorrow, it’s 10 pm here :wink:

Regards,
Guido

No problem! Have a good night!

Hi Ben,

The problem is solved with version 078, thanx !
What was the problem?

Regards,
Guido

Hi Guido,

It’s an issue brought in beta067 that the event canvas malfunctions when MapView.IsManipulationEnabled is set to true. Since this property must be enabled to support multi-touch on touch screens, I have fixed the issue so that it no longer affects normal usage.

And here I see a couple potential improvements in your code:

  1. instead of finding the shape’s type based on its WKT, which is heavy, you can directly get its type using the following method:

    Dim shapeType = ReturnShape.GetWellKnownType()
    
      If shapeType = WellKnownType.Point Then
      ElseIf shapeType = WellKnownType.Polygon Or shapeType = WellKnownType.Multipolygon Then
      ElseIf shapeType = WellKnownType.Line Or shapeType = WellKnownType.Multiline Then
    
  2. Put the pConv.Open/Close outside the loop for better performance

    Dim PConv As ProjectionConverter = New ProjectionConverter(proj28992, 3857)
    PConv.Open()
    
    For Each feature In TrackFeatures
    Next
    
    PConv.Close()
    

I’m also not sure why you converted the shape from EPSG:28992 to EPSG:3857 before calculating its length or area. If the feature is already in the 28992 projection and located in the corresponding region (the Netherlands), it’s more accurate to compute the length and area using that projection. EPSG:3857 as a global projection sacrifices some data accuracy when comes to area/length.

Thanks,
Ben

Hi Ben,

Thank you for you improvements ! I will definitely use them.

I think the answer to all you questions is ‘Because I’m a hobby programmer’.
I’m a Projectmanager who accidently knows a little bit about programming, and now I have created this Geographical Visual Database using ThinkGeo & Azure databases :wink:

It could definitely use an experienced programmer to optimize the code !
But I have not found budget yet to do so.

Regards,
Guido

Hi Guido,

Maybe you don’t need a programmer as now you have Chat GPT :slight_smile:

Happy Coding!

Thanks,
Ben