joshb
joshb

Reputation: 5220

Windows 10 UWP MapControl moved event

When the user is manually moving the map, I'd like to evaluate some criteria and optionally do something when they're finished. I can't seem to find the right MapControl event to hook into for this.

I've tried using CenterChanged, but it fires constantly while the map is moving and degrades performance.

Which MapControl event can I use to know when the user has finished moving the map?

Upvotes: 2

Views: 1435

Answers (3)

S. Matthews
S. Matthews

Reputation: 355

I know I'm about a year too late on this, but in case anyone runs into this question... I'm pretty sure the right way to do this is to listen to the LoadingStatusChanged event, then take action when you get back MapLoadingStatus.Loaded.

public void LoadingStatusChangedEventHandler(MapControl sender, Object o)
{
    if (sender.LoadingStatus == MapLoadingStatus.Loaded)
    {
        // The map has stopped moving and finished rendering
        DoSomething();
    }
}

I know the documentation for that event isn't great, but there's a little more information at this code sample, and you may be able to find even more on the git repo.

Upvotes: 3

Fernando Marcos
Fernando Marcos

Reputation: 29

As I would agree with you that I'd prefer some kind of delayed event, I also prefer verbose controls and rather filter the events myself. From your solution, instead of firing a periodic timer every second, just restart it when the event fires. When the event stops firing, the timer will tick and you'll get the final value:

DispatcherTimer mapCenterTimer = new DispatcherTimer();
mapCenterTimer.Tick += (object sender, object e) =>
{
  mapCenterTimer.Stop();
  ViewModel.MapCenter = MyMapControl.Center;
};
mapCenterTimer.Interval = TimeSpan.FromMilliseconds(500); // map idle for .5 seconds
MyMapControl.CenterChanged += (map, args) => { mapCenterTimer.Stop(); mapCenterTimer.Start(); };

Upvotes: -1

joshb
joshb

Reputation: 5220

I ended up using a timer to check the map center every second and update my view model accordingly. It feels like a hack to me but it's much more performant than using CenterChanged. The DispatchTimer is used to allow the timer to run on the UI thread so it has access to the MapControl.

DispatcherTimer mapCenterTimer = new DispatcherTimer();
mapCenterTimer.Tick += (object sender, object e) =>
{
  ViewModel.MapCenter = MyMapControl.Center;
};
mapCenterTimer.Interval = new TimeSpan(0, 0, 1); // fire every second
mapCenterTimer.Start();

It sure would be nice if the MapControl exposed some sort of ManualMoveComplete event for those of us who want to take action when a user has finished moving the map. I've created a request for it here on uservoice: https://binglistens.uservoice.com/forums/283355-ideas/suggestions/9494889-add-a-centermanuallychanged-event-to-mapcontrol

Upvotes: 1

Related Questions