Restricting pointermove interactions to two layers in openlayers 3

In openlayers version v3.6 running in Chrome on Ubuntu

I have create a map with several layers (foo, bar, beltch) in it using the syntax:


I would like to limit interactions to the layers foo and bar The api documents at suggest using the following syntax

var selectPointerMove = new ol.interaction.Select({

But I seem to get events for all layers, I have checked the examples and nothing seem to cover this area unless I have overlooked something.

Does anybody have any suggestions


Use filter instead of layers. And make sure you set a layer property to compare later.

var layerFeatures = new ol.layer.Vector({
    name: 'selectable',
    source: sourceFeatures

var hoverInteraction = new ol.interaction.Select({
    filter: function(feature, layer){
        if(layer.get('name') === 'selectable')
            return true;

Source: stackoverflow