Now that we've seen the basics and made our first map with OpenLayers, let's take a step back and look at the big picture. OpenLayers is a software library based on an Object-oriented design principles, which means that it contains classes to encapsulate behavior, formal relationships between those classes, and standardized mechanisms for communication between objects. While OpenLayers contains many classes, there are just a few that form the foundation of the OpenLayers architecture. In this chapter, we will introduce these core components of the library and also two key concepts— events and observable properties—that are the basis for standardized communication between objects. Along the way, we'll use concrete examples and introduce some basic debugging techniques you can use to solve problems and explore the relationships between objects in a running application.
In this chapter, we will:
The OpenLayers library provides web developers with components useful to build web mapping applications. Following the principles of an Object-oriented design, these components are called classes. The relationship between all the classes in the OpenLayers library is part of the deliberate design, or architecture, of the library. There are two types of relationships that we, as developers using the library, need to know about: relationships between classes and inheritance between classes. We briefly talked about object-oriented programming in Chapter 1, Getting Started with OpenLayers and a more detailed discussion is included in Appendix A, Object-oriented Programming – Introduction and Concepts but for the purpose of this chapter, let's summarize the two types of relationships we are interested in:
We'll start our discussion of the key components of OpenLayers by focusing on the first of these—the relationship between classes. OpenLayers includes a lot of classes for our use, and we'll cover a lot of these in later chapters, but for now, we'll start by looking at the Map class—ol.Map.
Instances of the map class are at the center of every OpenLayers application. These objects are instances of the ol.Map class and they use instances of other classes to do their job, which is to put an interactive map onto a web page. Almost every other class in the OpenLayers is related to the Map class in some direct or indirect relationship. The following diagram illustrates the direct relationships that we are most interested in:

The preceding diagram shows the most important relationships between the Map class and other classes it uses to do its job. It tells us several important things:
view to refer to it. A view may be associated with multiple maps, however.Collection class and a layer may be associated with 0 or one Map class. The Map class has a member variable named layers that it uses to refer to this collection.Collection class and an overlay may be associated with 0 or one Map class. The Map class has a member variable named overlays that it uses to refer to this collection.ol.Collection (more on collections at the end of this chapter) and controls may be associated with 0 or one Map class. The Map class has a member variable named controls that it uses to refer to this collection.Collection class and an interaction may be associated with 0 or one Map class. The Map class has a member variable named interactions that it uses to refer to this collection.Although these are not the only relationships between the Map class and other classes, these are the ones we'll be working with the most. We've already seen some of these classes in action in the examples from the previous chapter. We'll do another example in a moment, but first let's introduce each of these new classes.
View class (ol.View) manages information about the current position of the Map class.If you are familiar with the programming concept of MVC (Model-View-Controller), be aware that the view class is not a View in the MVC sense. It does not provide the presentation layer for the map, rather it acts more like a controller (although there is not an exact parallel because OpenLayers was not designed with MVC in mind.)
Layer class (ol.layer.Base) is the base class for classes that provide data to the map to be rendered.Overlay class (ol.Overlay) is an interactive visual element like a control, but it is tied to a specific geographic position.Control class (ol.control.Control) is the base class for a group of classes that collectively provide the ability to a user to interact with the map. Controls have a visible user interface element (such as a button or a form input element) with which the user interacts.Interaction class (ol.interaction.Interaction) is the base class for a group of classes that also allow the user to interact with the map, but differ from controls in which they have no visible user interface element. For example, the DragPan interaction allows the user to click on and drag the map to pan around.