ThinkGeo.com    |     Documentation    |     Premium Support

Centerpoint+Currentscale problem

Hello,

I run into an issue with the introduced ‘Centerpoint’ and ‘CurrentScale’.
During loading of my application the ‘mapview_loaded’ function is executed.
At the end I have a function ‘ZoomNederland()’ which zooms in on my country, so the user starts with our country centered on the screen.

The function is:
Public Sub ZoomNederland()
Me.CenterPoint = New PointShape(600000, 6820000)
Me.CurrentScale = 2000000
Me.RefreshAsync()
End Sub

When the code is executed from mapview_loaded I see the aerial photo a split second and then the screen becomes blank. The center coördinates are way of from the coördinates of The Netherlands.
So you might think the centerpoint in the function is wrong, but when I execute the function from a button (top left in picture), the same function is called and the aerial photo is nicely centered.

What could cause this issue? Can some code after mapview_loaded change the centerpoint?

Regards,
Guido van den Boom

Hi Guido,

The ZoomNederland() is calling RefreshAsync() without await, it means if I do something like:

ZoomNederland()
DoOtherThing()

DoOtherThing() will be called before RefreshAsync() is completed, so if I change some map settings in DoOtherThing(), the RefreshAsync() will be kind of messed up and not running as expected.

I suggest:

  1. Make ZoomNederland async

Public Async Function ZoomNederlandAsync() As Task
’ …
Await RefreshAsync()
End Function

  1. await ZoomNederlandAsync like following, this will guarantee DoOtherThing() runs after ZoomNederlandAsync

    await ZoomNederlandAsync()
    DoOtherThing()

  2. Add await to your _Loaded event, such as

Private Async Sub MapView_Loaded(sender As Object, e As RoutedEventArgs)

Have a try see if it helps.

Thanks,
Ben

Hi Ben,

I changed the functions to Async and added Await but that did not help.
Then I deleted the RefreshAsync, so I only have ZoomNederlandAsync, still the same.

This is the last call I make in mapview_loaded. The centerpoint and scale are set.
Thinkgeo calculated the CurrentExtent.

Then I press F8 in Visual Studio and the application becomes visible, but still with an empty space.
The next thing I do is start a function with an immediate break.
As you can see some values have changed, especially the CenterPoint and CurrentExtent.
Somewhere the values have been recalculated.

With the next call to ZoomNederlandAsync the CenterPoint is set again, the CurrentExtent is calculated correctly and the aerial photo is visible.

So no more RefreshAsync. Any idea ?

Regards,
Guido van den Boom

Guido,

So the map is modified after mapview_loaded. Can you hook up the
MapView.CurrentExtentChanged += MapView_CurrentExtentChanged;

Put a breakpoint in MapView_CurrentExtentChanged, check the callstack and find out which method riggers the event. I have a feeling some other code was modifying the map.

Thanks,
Ben

Ben,

I did all that !

  1. After setting the currentscale in mapview2_loaded, I get this result (Call stack at the bottom).

  2. The next breakpoint is the ‘End Function’ of mapview2_loaded, as before. When I press F8 the next break in CurrentExtendChanged is this:
    The only things I notice are MapViewBase.PkQ= and MapViewBase.Centerpoint.set.


    For your reference, this is the complete Call Stack from picture 2.

However, one again, after this I press the button that calls ZoomNederlandAsync, and the aerial photo appears.

Honestly, I’m at a loss.

Regards,
Guido van den Boom

Hi @Ben, just letting you know that I also run into this issue.
I am not setting it with Centerpoint + Currentscale, but rather with CurrentExtent.
CurrentExtentChanged seems to throw out a garbage data randomly at the beginning.

> Agk.Viewer.Presentation.dll!Agk.Viewer.Presentation.ViewerMainViewModel.Map_CurrentExtentChanged(object sender, ThinkGeo.UI.Wpf.CurrentExtentChangedMapViewEventArgs e) Line 1300
ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.MapViewBase.OnCurrentExtentChanged(ThinkGeo.UI.Wpf.CurrentExtentChangedMapViewEventArgs e)
ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.MapViewBase.CenterPoint.set(ThinkGeo.Core.PointShape value)
ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.MapViewBase.IkQ=(object sender, System.EventArgs e)
WindowsBase.dll!System.Windows.Threading.DispatcherTimer.FireTick(object unused)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state)
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)

Just confirming this also happens in the latest Beta 009

Hi @G_Vandenboom and @Julian_Thoms,

Thanks for the information! I found it’s because the map is resized, thus the CenterPoint/CurrentExtent is accordingly updated.

Guido, from the screenshot, your map is changed from 1246x2558 to 1114x2552, is that as expected? You can hook up MapView.SizeChanged event and find what code causes the resizing. (This event will be raised when initializing the control, so you can skip the first and check what raised the event for the 2nd time).

Even the map resizes a bit, the center point should not be changed all the way from (600000, 6820000) to (-40461177, 19742762) for your case. I have no clue, but I added some debug info to the latest build (14.4.0 - beta10), can you pull the latest and add the following code to your application:

ThinkGeoDebugger.LogType = ThinkGeoLogType.Interaction;
ThinkGeoDebugger.LogLevel = ThinkGeoLogLevel.All;

And you should then see something like following in the output window:

ThinkGeo Message - 11:25:35.0923248: Resizing: ResizeMode: PreserveScale, Width: 1038, Height: 700.6666666666666, Center: (-10336000, 5260000), CurrentScale: 37000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 11:25:35.2167153: Resizing: ResizeMode: PreserveScale, Width: 1037.3333333333333, Height: 700.6666666666666, Center: (-10336000, 5260000), CurrentScale: 37000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 11:25:35.8525669: Resize_Tick Before Updating: ResizeMode: PreserveScale, Width: 1037.3333333333333, Height: 700.6666666666666, Center: (-10336000, 5260000), CurrentScale: 37000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 11:25:39.0248909: Resize_Tick After Updated: ResizeMode: PreserveScale, Width: 1037.3333333333333, Height: 700.6666666666666, Center: (-10469790.899975136, 5260000), CurrentScale: 37000000, Unit: Meter, Rotation: 0

Please send these logs to me.

Thanks,
Ben

Hi ben, here are the logs

ThinkGeo Message - 04:59:10.8280596: Resizing: ResizeMode: PreserveScale, Width: 812, Height: 603, Center: (638496,8125, 5357795), CurrentScale: 147295,100497512, Unit: Meter, Rotation: 0
ThinkGeo Message - 04:59:11.3650251: Resize_Tick Before Updating: ResizeMode: PreserveScale, Width: 812, Height: 603, Center: (638496,8125, 5357795), CurrentScale: 147295,100497512, Unit: Meter, Rotation: 0
ThinkGeo Message - 04:59:11.3725450: Resize_Tick After Updated: ResizeMode: PreserveScale, Width: 812, Height: 603, Center: (-26743739,0008105, 19382499,5402509), CurrentScale: 147295,100497512, Unit: Meter, Rotation: 0

Hi Ben, here are my logs.

I use DevExpress with all sorts of panels, so I can imagine the size changes a lot.

This is my log right after mapview_loaded:
ThinkGeo Message - 10:36:11.3506194: Resizing: ResizeMode: PreserveScale, Width: 2552, Height: 1082, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 10:36:11.4161243: Resizing: ResizeMode: PreserveScale, Width: 2552, Height: 1114, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 10:36:12.6167937: Resize_Tick Before Updating: ResizeMode: PreserveScale, Width: 2552, Height: 1114, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 10:36:24.6221892: Resize_Tick After Updated: ResizeMode: PreserveScale, Width: 2552, Height: 1114, Center: (-40461177,001401, 19742762,5572991), CurrentScale: 2000000, Unit: Meter, Rotation: 0

Then I press ZoomNederlandAsync (the aerial photo becomes visible, but no log information).

After that I change the size of the map and then this is the log:
ThinkGeo Message - 10:40:27.8934297: Resizing: ResizeMode: PreserveScale, Width: 2314, Height: 1114, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 10:40:28.3978460: Resize_Tick Before Updating: ResizeMode: PreserveScale, Width: 2314, Height: 1114, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 10:40:28.4067456: Resize_Tick After Updated: ResizeMode: PreserveScale, Width: 2314, Height: 1114, Center: (709802,02404024, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0

Hi @G_Vandenboom and @Julian_Thoms,

Thank you guys for the log! They are really helpful!

I fixed the issue in the latest beta (14.4.0-beta011), please have a try.

Also just remind you guys the map has different Resizing mode; there’s a sample in the HowDoI where you can see the difference between the 3 Resizing Mode. You might want to try PreserveScaleAndCenter.

Thanks,
Ben

Hi Ben, thanks, that Beta fixed it!
Also that Resizing Mode is way better than the other one - why isn’t it the default? :smiley:

Thanks!

Hi Ben,

I’m sorry to inform you that this is not the solution for me :frowning:
I upgraded to beta012, but nothing changed.

This is my log from beta012:
ThinkGeo Message - 09:14:46.9347380: Resizing: ResizeMode: PreserveScale, Width: 2552, Height: 1113, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 09:14:46.9821957: Resizing: ResizeMode: PreserveScale, Width: 2552, Height: 1114, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 09:14:48.2782744: Resize_Tick Before Updating: ResizeMode: PreserveScale, Width: 2552, Height: 1114, Center: (600000, 6820000), CurrentScale: 2000000, Unit: Meter, Rotation: 0
ThinkGeo Message - 09:14:48.2896954: Resize_Tick After Updated: ResizeMode: PreserveScale, Width: 2552, Height: 1114, Center: (-40139547,6557915, 19051259,4642388), CurrentScale: 2000000, Unit: Meter, Rotation: 0

And changing the mapresize setting crashes my application with a System.NullReferenceException

Regards,
Guido van den Boom

Yeah, sadly the same issue also still happens to me, I don’t know why it didnt happen when I tried it yesterday…

ThinkGeo Message - 12:01:54.9678034: Resizing: ResizeMode: PreserveScale, Width: 832, Height: 603, Center: (0, 0), CurrentScale: 243121526,391922, Unit: Meter, Rotation: 0
ThinkGeo Message - 12:01:59.8119627: Resizing: ResizeMode: PreserveScale, Width: 812, Height: 603, Center: (638480,75, 5357773), CurrentScale: 150441,574559204, Unit: Meter, Rotation: 0
ThinkGeo Message - 12:02:04.6693234: Resize_Tick Before Updating: ResizeMode: PreserveScale, Width: 812, Height: 603, Center: (638480,75, 5357773), CurrentScale: 150441,574559204, Unit: Meter, Rotation: 0
ThinkGeo Message - 12:02:04.6820554: Resize_Tick After Updated: ResizeMode: PreserveScale, Width: 812, Height: 603, Center: (-26743401,0041272, 20025507,2314698), CurrentScale: 150441,574559204, Unit: Meter, Rotation: 0

Actually I have a pointer for you @Ben, I know why it worked yesterday, I changed the ResizeMode.
On PreserveScale this bug appears, changing it to MapResizeMode.PreserveScaleAndCenter fixes it.

@G_Vandenboom can you test if this fixes the issue on your end as well?

@Julian_Thoms, @Ben,
I tried that this morning, but setting the MapResizeMode to any value (PreserveExtent or PreserveScaleAndCenter) results in a System.NullReferenceException error and crashes my application.

This is the CallStack if it helps:

@G_Vandenboom @Julian_Thoms

I recreated that exception and figured it out. Please pull the latest beta013 and give it a try.

I was able to reproduce the exception when resizing the map in PreserveScaleAndCenter or PreserveExtent mode before the map is refreshed. The issue occurs because overlays are only initialized when the map is drawn (e.g., via map.RefreshAsync() ), if the map is resized before any refresh, it triggers a call to Overlay.Transform(RectangleShape targetExtent) , but the overlay hasn’t been initialized yet, which causes the exception.

In fact, I’m not very sure it will fix the other issue that the map will disappear after initialization in PreserveScale mode. Can you guys let me know if it still exists on your side?

@Julian_Thoms, I think you are right, it should be better to default it to PreserveScaleAndCenter :slight_smile: . we’ll make it happen after making sure there’s no issues around resizing.

FYI: there’s another user asking the similar question here: ThinkGeo 14.3.0 Map Initialization Exception - ThinkGeo UI for Desktop / WPF - ThinkGeo Discussion Forums

Thanks,
Ben

@Ben

I can confirm I can set the MapResizeMode now in mapview_loaded without exceptions !
When I set the MapResizeMode to PreserveScaleAndCenter or PreserveExtent the map does not disappear anymore. I get to see the aerial photo perfectly :wink:

When I set the MapResizeMode to PreserveScale or I do not set the MapResizeMode (default setting) then the map still disappears.

For me the PreserveScale is the prefered option, but I can live with PreserveScaleAndCenter for now.
Thank you !!

Update: I don’t know if it is the MapResizeMode or something else, but zooming in and out is not smooth anymore. The screen flashes white with every zoom step. Before the aerial photo zoomed in or out and then became sharper.

Regards,
Guido

That’s great, Guido! Can you make sure you’ve removed the following code? The log slows everything down. Let me know if the performance is still bad without the logs.

ThinkGeoDebugger.LogType = ThinkGeoLogType.Interaction;
ThinkGeoDebugger.LogLevel = ThinkGeoLogLevel.All;

We’ll keep working on PreserveScale.

Hi Ben,
I removed the ThinkGeoDebugger code lines, but still te flashes exist.
I create a short movie with the two versions. Version 25.5.125.0 of my application uses Thinkgeo 14.3.0.
The second part of the video uses the latest Beta013.

Link to the video flashing.mp4