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 targetNode = evt.target; if (isChild) { evt.stopPropagation(); targetNode = targetNode.parentNode; } if (_this.selectedLayer) { _this.selectedLayer.classList.remove('active...