[GIS] How to get the change event of a layer in OL3 using ol.control.LayerSwitcher

javascriptopenlayers

I'm using OpenLayers 3 with the ol.control.LayerSwitcher plugin and wanted to know how I can get it when I change a layer on the switcher. I was searching a lot on the internet and I can not find a solution to this.
The idea is to change a layer using the ol.control.LayerSwitcher plugin to perform an action such as an alert.

If someone could give me a help or an alternative to this. If you know of another alternative that does not use ol.control.LayerSwitcher and determine the change event of a specific layer, I would like to know.

Best Answer

Find the answer and the solution is:

var layer_country = new ol.layer.Tile({
    title: 'Countries',
    source: new ol.source.TileWMS({
        url: 'http://demo.opengeo.org/geoserver/wms',
        params: {'LAYERS': 'ne:ne_10m_admin_1_states_provinces_lines_shp'},
        serverType: 'geoserver'
    })
});
// Evento change del layer layer_country.
layer_country.on('change:visible', function(){
    alert("Countries");
});

Link