Disable panning on the view
Note: Support for 3D on mobile devices may vary, view the system requirements for more information.
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(event){
// prevents panning with the mouse drag event
event.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(event){
// prevents panning with the arrow keys
var keyPressed = event.key;
if(keyPressed.slice(0,5) === "Arrow"){
event.stopPropagation();
}
});
Try panning the view by dragging the mouse or by using the arrow keys.