Disable panning on the view
This sample demonstrates how to disable panning on a MapView instance. To disable panning, you must call the stopPropagation()
method on the event objects of the gesture events that trigger view panning.
Since you can pan the view in two ways, you need to call stopPropagation()
in two different contexts. First, you must prevent the default panning behavior by stopping it on the drag event.
view.on("drag", function(evt){
evt.stopPropagation();
});
Since you can also pan a view with arrow keys, you can disable that behavior by listening to the key-down event and calling stopPropagation()
on the event object only when the arrow keys are pressed. You can use the String.slice() method to check if any of the Arrow
keys were pressed.
view.on("key-down", function(evt){
var keyPressed = evt.key;
if(keyPressed.slice(0,5) === "Arrow"){
evt.stopPropagation();
}
});
Try panning the view by dragging the mouse or by using the arrow keys.