0

removeFeature() function works great but not so much when trying to remove a lot of features/markers from the source as it only removes single feature. There was a function removeFeatures([]) in OL2 that does this but removed in OL4.

Is there a work around to achieve this?

features.forEach(function(feature, ind, array){
      if(feature.id == selectedFeature)
      {
        // slow removing process as it removes a single feature from the source...
        tFeature.removeFeature(feature);
      }
    });

Was hoping to do something like this instead of removing a feature as it iterates through the source.

var removeF = [];
features.forEach(function(feature, ind, array){
 if(feature.id == selectedFeature)
 {
   // push every features that needs to be removed..
    removeF.push(feature);
 }
});
// Remove it in one go..
tFeature.removeFeatures(removeF );
  • There is no built-in function in ol to bulk remove. I tried to remove 28539 features with the loop as you said. It takes 435 milliseconds. – himyata Jun 19 '18 at 7:19
  • Yeah I agree that there is in a built-in method to do it, but is there a better solution? 435ms is too much and very inefficient way of removing that much of features. – nCore Jun 19 '18 at 7:26

Your Answer

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

Browse other questions tagged or ask your own question.