Adding layers dynamically

Now that we have a basic layer tree, it's time to add some logic when adding layers. In this example, called ch03_addlayer, we will extend our code so far with some layer requesting and WMS metadata fetching capabilities. We will add every additional method to the object's prototype for the sake of clarity and performance.

Creating the interface

To keep things simple, we first hard code some forms in the HTML part. We will be able to add layers by filling out and submitting these forms. This will only need some event listeners in the JavaScript code. As these forms are quite verbose, we will only discuss the most important parts here. You can see the full code in the example's HTML file:

<div id="addwms" class="toggleable" ...

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.