In this chapter, we will cover the following topics:
Controls allow us to navigate around the map, play with layers, zoom in or out, and perform actions, such as editing features, measuring distances, and so on. In essence, controls allow us to interact.
OpenLayers comes with controls that are visually represented on the map through DOM elements and can be styled with CSS. Such controls, such as Attribution, FullScreen, and Zoom, fall under this category. These types of controls are subclasses of ol.control.Control.
There are also other kinds of controls that are invisible to the user, but they provide just as important interactions. Controls, such as KeyboardPan, Select, and PinchZoom, are of this type. These types of controls are part of the ol.interaction object.
There are also other helper methods that one could consider a type of control, such as the ol.Geolocation class that provides HTML5 geolocation capabilities.
Controls can be activated or deactivated as desired. Many controls or interactions are already included on a map by default to cover common interactions that a user may be accustomed to from usage across other mapping applications. Custom controls can be created too, which we will cover in the Creating a custom control recipe, in Chapter 7, Beyond the Basics.
Controls listen for events, such as a click or tap. This event management is accomplished through the help of the Google Closure library. For example, the goog.events.listen subscriber method is used to register for a click event (goog.events.EventType.CLICK) on a DOM element, such as the Zoom button.
Let's take a look at some recipes that will help us understand the controls better.