I need to execute some code when the user finishes to zoom in/out the map. Its ZoomLevelChanged
event is raised as the user zooms in or out, so it is not a solution for me (mainly because the code i want to execute is a pretty expensive operation). Any ideas?
Asked
Active
Viewed 370 times
0

S. Matthews
- 355
- 2
- 9

Alex
- 3,689
- 1
- 21
- 32
-
2Maybe set a timer when the user *starts* zooming, and if the event is called again, reset the timer. After the timer reaches say, 3 seconds, you can assume that they have finished zooming. – Mike Eason Aug 25 '16 at 07:10
-
@MikeEason not the cleanes way i can think of but, i think it might work – Alex Aug 26 '16 at 07:32
2 Answers
2
If the performance is the main issue here, you can "rerender" your map elements only when the zoom level changes from one integer to another (1->2, 2->3 and so on) (skiping the part after coma). As far as I know the maximum value for ZoomLevel
is 20 (for 2D
) mode. So I think it must be smooth enough for the user not to notice.
Some code:
public int ZoomLevel {get; set;} = initialZoomLevel;
private void OnZoomLevelChanged(object sender, EventArgs args)
{
if((int)Map.ZoomLevel!=ZoomLevel)
{
//Rerender stuff
}
}
-
I actualy already did this. and you are right. It is smooth enough for user not to notice – Alex Aug 26 '16 at 07:40
0
I believe a better solution 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
// If necessary, check that zoom level is different
DoExpensiveOperation();
}
}
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.
Good luck!!

S. Matthews
- 355
- 2
- 9