Building the toolbar

In the first example, called ch05_toolbar, we create the constructor function for our management system and add some methods to it to add and remove controls. We don't need any styling at this point. Firstly, we create the constructor:

var toolBar = function (options) { 'use strict'; if (!(this instanceof toolBar)) { throw new Error('toolBar must be constructed with the new keyword.'); } else if (typeof options === 'object' && options.map && options.target && options.layertree) { if (!(options.map instanceof ol.Map)) { throw new Error('Please provide a valid OpenLayers 3 map object.'); } this.map = options.map; this.toolbar = document.getElementById(options.target); this.layertree = options.layertree; this.controls = new ol.Collection(); ...

Get Mastering OpenLayers 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.