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

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


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?

  • 2
    To you have the same problem when calling select.setActive(false)?
    – tsauerwein
    Mar 2, 2015 at 9:10

1 Answer 1


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.
  • Please, add some explanation with your answer to understand solution
    – aldo_tapia
    Jan 9, 2017 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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