bindTo method is extremely powerful and makes many seemingly advanced tasks quite easy to accomplish. Let's set up an HTML checkbox element that we can use to control the visibility of a map layer.
<div id="map">and the
<input type="checkbox" id="visible" checked> Toggle Layer Visibility
This will add a new HTML element, a checkbox, to our web page and we will use this to turn our layer on and off.
var visible = new ol.dom.Input(document.getElementById('visible')); visible.bindTo('checked', layer, 'visible');
This code creates a ...