The last section for this chapter is about the OpenLayers' Collection
class, ol.Collection
. As mentioned, the Collection
class is not a super class like Observable
and Object
, but it is an integral part of the relationship model. Many classes in OpenLayers make use of the Collection
class to manage one-to-many relationships.
At its core, the Collection
class is a JavaScript array with additional convenience methods. It also inherits directly from the Object
class and inherits the functionality of both Observable
and Object
. This makes the Collection
class extremely powerful and we will use it many times in the rest of this book.
A collection is created just like any other class, just use the new operator:
var collection = new ol.Collection();
The Collection
constructor takes one optional argument, an array that is used to initially populate the collection with elements. The elements in the array can be of any type, but if you are using the collection...