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.

1 Answer 1


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(){


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.