Let's deactivate zoom and pan with the keyboard and also the rotate when doing Alt + Shift + mouse drag.
For this, do the following:
<div id="map" class="map"></div> the attribute tabIndex with a value 0 to make it focusable.keyboard option to false in the interactions property of the ol.Map object.altShiftDragRotate option. Try different actions with the left, right, up, and down arrows or with the plus and minus keys.Here you just saw an example to deactivate some default behaviors.
By changing keyboard options to false, we make the application unable to respond to keyboard interaction with pan and zoom.
After reviewing the ol.interaction.defaults function itself, you also learn that each map already embedded nine ol.interaction by default, and for keyboard, the switch works for all keyboard interactions.
Let's see exactly what each of those interactions does at the functional level more than at the code level. We already introduced them in Chapter 2, Key Concepts in OpenLayers, so you should not be lost.
ol.interaction.DoubleClickZoom: This interaction allows users to zoom by double-clicking. You can set the duration to change animation time and delta when you want to change the zoom delta.ol.interaction.DragPan: It allows to you to pan by dragging the map. You can set panning behavior by setting the kinetic property.ol.interaction.DragRotate: This interaction makes the map rotate when you combine both the Alt and Shift keys together to rotate the map image. You can change it by changing the condition property.ol.interaction.DragZoom: It enables you to draw a temporary rectangle when pressing the Shift key with the keyboard. Then, this rectangle is used to zoom on the selected region of the rectangle. You can change the condition for the behavior with a condition, but you can also choose a style when drawing. The most interesting part in this component, other than its behavior, is that it inherits from ol.interaction.DragBox. It means that we will be able to reuse the drawing rectangle behavior for other purposes and not only for zooming like here. Later in the chapter, we shall see how.ol.interaction.PinchRotate: On mobile devices, one of the main interactions is the pinch. In the OpenLayers 3 library's case, it is supported by default. The name itself is enough to understand that this component has a behavior similar to DragZoom, but when pinching. You can set the threshold property if your application requires to change sensitivity for rotating the map.ol.interaction.PinchZoom: As the previous component, it relies on the pinch but in order to zoom. It's like when you are browsing on mobile, but instead of getting only a lens effect, you really make a zoom in your map. You change the animation duration, setting the same duration property in the component.ol.interaction.KeyboardPan: Its role is to manage map browsing using only the keyboard. It needs to make the map focusable by adding a tabIndex attribute at your map div level. To get the focus for the map, you need to use the tab key. Then, panning can be controlled using the up, down, left, and right keys. The option pixelDelta enables you to set the translation in pixels when pushing on the keys. By default, it value is 128 pixels. It is also possible to set the now usual condition property.ol.interaction.KeyboardZoom: Its goal is similar to the previous component except that it applies when you use the keys plus and minus instead. This interaction can be set just as for DoubleClickZoom with the delta property and also the condition too.ol.interaction.MouseWheelZoom: As its name implies, this interaction is related to the use of the mouse wheel to zoom in or zoom out. The only custom behavior you can set for this interaction is the duration of the animation by default to 250 milliseconds.After this more verbose part, it's time to see the missing interactions.