Disable panning on the view

This device does not support 3D.

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(evt){
  // prevents panning with the mouse drag event
  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){
  // prevents panning with the arrow keys
  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.

Sample search results

TitleSample

There were no match results from your search criteria.