Skip to content Skip to sidebar Skip to footer

Openlayers3 Same Style For Selected Features (only One Changed Property)?

I have an ol3 layer with a style definition. I would like to use the same style for the select interaction: style = function(feature, resolution) { var iconFont = 'FontAwesom

Solution 1:

Now I found a working solution:

You can add an additional argument (e.g. highlight [bool]) to the style function:

style = function(feature, resolution, highlight) {
...
}

and the instead of

new ol.interaction.Select({
                features: that.selectedFeatures,
                style: style
            })

you can use

new ol.interaction.Select({
                features: that.selectedFeatures,
                style: function(feature,resolution){
                     returnstyle(feature,resolution,true);
                }
            })

Solution 2:

A possible solution: Tell your function that ol.interaction.Select is active:

var style = function(ft, res, selecting){
  return [
    new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: '#ffcc33',
        width: selecting ? 4 : 2
      })
    })
  ];
};

var selecting = false;
selectInteraction.on('select', function(evt) {
    selecting = evt.selected.length > 0;
});

http://jsfiddle.net/jonataswalker/eepyne75/

Post a Comment for "Openlayers3 Same Style For Selected Features (only One Changed Property)?"