0

I'm changing the stroke color of my features when they are selected like follows:

  var select = new Select({
    condition: click
  });
  select.on('select', function (e) {
    e.selected.forEach(function (feature) {
      feature.getStyle().getStroke().setColor([r, g, b, 1]);
    });
  });

It is working but when the map is translated, the deselected feature doesn't change its stroke.

I tried to use also the e.deselected property to set the default stroke color but it didn't work

  • Features have separate styles when selected and not selected. You should use the style option in ol.interaction.Select to set the style for selected features. – Mike Nov 3 '18 at 12:26
1

As @Mike suggested you should be using select interaction's style option unless you have some reason not to.

var select = new Select({
    condition: click,
    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: [255,0,0,1],
        })
    })
});

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.