[GIS] VectorLayer Feature setStyle makes features disappear in OpenLayers 4

featuresopenlayersvector-layer

After I have already displayed my map I want to highlight certain features.
For starters I am trying to highlight all features like this:

public highlightMapFeatures() {
    this.map.getLayers().forEach(function (lyr) {
      if (lyr.type === 'VECTOR') {

        lyr.getSource().forEachFeature(function(feature) {
          let style = new ol.style.Style({
            stroke: new ol.style.Stroke({ color: '#ff00ff',
              width: 2 }),
          });
          feature.setStyle(style);
      }
    });

But what happens is, that all my features disappear.
Do I have to redraw them? I should be so simple.

Best Answer

A stroke will not do for a dot shown on the map. It needs some kind of shape e.g. Circle. If we define the style like this, the features do not disappear:

let style = new ol.style.Style({
            image: new ol.style.Circle({ // add this
              stroke: new ol.style.Stroke({
                color: '#ff00ff'
              }),
              radius: 5
            }),
          });
Related Question