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(); } else { throw new Error('Invalid parameter(s) provided.'); } };
Similar to the layer tree, we use the use strict
paradigm...