[GIS] How to stop select interaction without unselecting all features

openlayers

I use interaction:

var select = new ol.interaction.Select({
    layers: [my_layer],
    style: new ol.style.Style({
            fill: new ol.style.Fill({
             color: '#A00000'
         }),
             stroke: new ol.style.Stroke({
             color: '#000000'
         })
            })});

for selecting features on my_layer:

 var map = new ol.Map({
        target: 'map',
        interactions: ol.interaction.defaults().extend([select]),
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          }),
          my_layer,
          vector]});

Now, I want to measure distance between points using sniped code from:
http://openlayers.org/en/v3.1.0/examples/measure.html
To avoid selecting features during measure process I have to remove select interaction from the map

map.removeInteraction(select);

But this removes selection from the selected features too.
How to avoid this problem about unselection after removeInteraction(select)?
Or maybe can I add any condition in this interaction to stop selecting features during measuring?

Best Answer

Try this:

this.select = new ol.interaction.Select({
                    filter: function(layer){
                        return enableSelection;
                    },
                    toggleCondition: function(layer){
                        return !enableSelection;
                    }
                });

Set enableSelection=trye; for normal use of Select interaction.
Set enableSelection=trye; to freeze selection.