[GIS] OpenLayers 3.5.0, clear highlighted feature after removing feature from source

javascriptopenlayersvector

I want the user to be able to delete the highlighted feature. This works well, but the feature is not cleared until I move the pointer outside the feature geometry.

I am using the OL 3.5.0 library.

This is the code:

var selectPointerMove_Highlight = new ol.interaction.Select({
  condition: ol.events.condition.pointerMove
  });
map.addInteraction(selectPointerMove_Highlight);

var selectClick_Delete = new ol.interaction.Select({
  condition: ol.events.condition.click
  });
map.addInteraction(selectClick_Delete);

selectClick_Delete.getFeatures().on('change:length', function(e) {
  var feature = e.target.item(0);
  vectorSource.removeFeature(feature);
  selectClick_Delete.getFeatures().clear();
  selectPointerMove_Highlight.getFeatures().clear();
  });

Here is a JSFiddle to show the behaviour. I would expect the highlight to vanish after the clear function is called.

http://jsfiddle.net/goldrydigital/5azhb1o3/

Edit:

I tried a map.renderSync() to force a re-render of the map, but that didn't do it.

Best Answer

Take a look at this fiddle.

I've made some modifications, basically I remove the highlight interaction (on removefeature) and put it back on pointermove event.