ThinkGeo.com    |     Documentation    |     Premium Support

Zoom and Pan methods do not work

The following codes fail to update the map.

        WinMap.PanByDegreesAndScreenDistanceAsync(180f, 200);
        WinMap.RefreshAsync();

        WinMap.ZoomToAsync(_scales[currentIndex + 1]);
        WinMap.RefreshAsync();

In v10 you had to refresh the map in order for the display to update. Here it seems to have the opposite effect. If I remove the RefreshAsync(), it appears to work fine.

I am seeing other conflicts with code that subsequently does a RefreshAsync() particularly on different overlays. It’s basically like they cancel themselves out.

What are the rules for when to use and not to use RefreshAsync()?

Another confusing point is that I saw this code in the NavigationMap.cs of HowDoI…

await mapView.RefreshAsync(); // Cancel the ongoing rendering

The user comment says Cancel the ongoing rendering, but the help context of the command is specifically the opposite…

“Refreshes all the existing overlays and map tools”

So what does it actually do???

Yep, you don’t need to call RefreshAsync() in the above scenario.

  • In v10 , pan/zoom methods didn’t actually redraw the map. You always had to call Refresh() afterward to force the update.
  • In v14 , those async methods (like ZoomToAsync ) already update the map in real time as they animate. (For example, you can let ZoomToAsync run for 5s so have a 5s animation.) And you don’t need to force the refresh.

So the general guideline is:

  • Use RefreshAsync() when you make changes to overlays, layers, or tools that don’t automatically trigger a redraw.
  • Don’t call RefreshAsync() right after pan/zoom methods, since they already handle the refresh.

About the Cancellation: all the async method can be cancelled, you can do it through the passed in CancellationToken or mapView.CancellationTokenSource. And it will be automatically cancelled when whenever kicking off a new rendering by either calling a method (such as RefreshAsync() or ZoomToAsync) or start panning /zooming the map. As for the comment you noticed in NavigationMap.cs , the method itself does “refresh all overlays and map tools” as the help text says. The reason the comment says “cancel the ongoing rendering” is because any new render call (whether RefreshAsync() or a pan/zoom) will stop whatever rendering is currently happening. That comment could definitely be clearer—we’ll get it updated.

And yep, async has changed everything, v14 and v10 are quite different now.

Hi Ben,

Okay, starting to get a bit clearer.

I think you misunderstood my comment about cancelling. Here’s what I was referring to via example.

My user clicks a check box to show the grid feature layer. The following occurs:

I build a legend. At the end of that code, I do AdornmentOverlay.RefreshAsync()

The next piece of code is to display the layer where I do a CultureOverlay.RefreshAsync()

The result is that the legend displays, but the grid does not until I zoom or pan. That’s what I meant about odd behavior and one refresh seemingly cancelling the other.

So when you do Overlay.RefreshAsync(), did you add await? Be sure to use await especially when you have 2 or more async methods in the same function.

After creating CultureOverlay, make sure to call await mapView.RefreshAsync() or await mapView.RefreshAsync(CultureOverlay) at least once, which initialize the overlay.

Please send over the code to us if you still see issues.

Yes, I was starting to figure out that not awaiting was causing problems. I need to do a lot more testing, but hoping this is the reason.

Visual Studio should give you a warning if not awaiting an async method. You can start from getting rid of all the warnings.