I am playing with MapControl
in UWP, and I would like to forbid the looping in the horizontal scrolling with a left mouse click, I would like my widget be like map not like a globe and map rotating with a right click, I have looked in Internet and cannot find any hint.

- 38,440
- 7
- 70
- 91

- 510
- 4
- 14
-
So you want the map not to be movable at all? – Martin Zikmund Jan 18 '18 at 20:14
-
Movable but with a border, without this endless loop – Andrey Mazur Jan 18 '18 at 20:16
2 Answers
You can use the CenterChanged
and ZoomChanged
events of the MapControl
to observe the map position changes.
In the handler for these events you can then use the GetLocationFromOffset
method to retrieve the location of the corners of the current view and Center
to retrieve the current center location and if you the view left your "boundary", you can just force the map back using TrySetViewBoundsAsync
method.

- 38,440
- 7
- 70
- 91
You can disable the rotation capability of the map by setting the RotateInteractionMode property - see:
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.maps.mapinteractionmode
You may also want to disable TiltInteractionMode.
Disabling panning wraparound behavior is harder - there is no direct support for this. You can listen to the view changed or changing events as suggested above and then force the view back, but it will be tricky to pick the right bounds to prevent wrapping but still allow normal navigation, and you'll also probably see some view jittering when you hit this condition.

- 1,772
- 8
- 13