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

Removing layers dynamically

Now that we can add layers dynamically with our layer tree, it's time to add the capability of removing layers. For this task, we create a button that's designated to removing a selected layer, and add some logic to select a single layer in the layer tree. You can see this example if you look for ch03_deletelayer.

Extending a constructor

First of all, we need to make the layers selectable, and we can do this by registering further events to the layer elements in the constructor function. To make it simple and clear, we create a utility method to add this event type to the layer element:

layerTree.prototype.addSelectEvent = function (node, isChild) { var _this = this; node.addEventListener('click', function (evt) { var ...

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