O'Reilly logo

Mastering OpenLayers 3 by Gábor Farkas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required