-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to remove feature silently in ol.source.Vector. #15643
Add an option to remove feature silently in ol.source.Vector. #15643
Conversation
📦 Preview the website for this branch here: https://deploy-preview-15643--ol-site.netlify.app/. |
I'm not sure this really fixes #15642. Please see my #15642 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! From an API consistency perspective, it would make sense to add a removeFeatures()
method, instead of adding a silent
option to removeFeature()
. Would you be able/willing to change this pull request accordingly? Then we had a sensible counterpart to addFeatures()
.
3115fb9
to
51ae7b4
Compare
I've added a first simple version of removeFeatures/removeFeature. |
I think going the other way around would be easier, something like --- a/src/ol/source/Vector.js
+++ b/src/ol/source/Vector.js
@@ -1093,6 +1093,20 @@ class VectorSource extends Source {
}
}
+ removeFeatures(features) {
+ const removedFeatures = [];
+ for (let i = 0, ii = features.length; i < ii; ++i) {
+ const removedFeature = this.removeFeatureInternal(features[i]);
+ if (!removedFeature) {
+ continue;
+ }
+ removedFeatures.push(removedFeature);
+ }
+ if (removedFeatures.length > 0) {
+ this.changed();
+ }
+ }
+
/**
* Remove feature without firing a `change` event.
* @param {FeatureType} feature Feature.
@@ -1113,9 +1127,11 @@ class VectorSource extends Source {
delete this.idIndex_[id.toString()];
}
delete this.uidIndex_[featureKey];
- this.dispatchEvent(
- new VectorSourceEvent(VectorEventType.REMOVEFEATURE, feature),
- );
+ if (this.hasListener(VectorEventType.REMOVEFEATURE)) {
+ this.dispatchEvent(
+ new VectorSourceEvent(VectorEventType.REMOVEFEATURE, feature),
+ );
+ }
return feature;
} |
Be able to remove multiple features from vector source without triggering events.
51ae7b4
to
c9de02a
Compare
I've done the asked changes, but in this way, I've to duplicated the whole Or I can migrate:
Into Edit: |
I have to apologize, I somehow managed to garble the diff I had posted above. I edited the post to show the correct diff. That said, there should be no duplicated code. The change is essentially this new removeFeatures(features) {
const removedFeatures = [];
for (let i = 0, ii = features.length; i < ii; ++i) {
const removedFeature = this.removeFeatureInternal(features[i]);
if (!removedFeature) {
continue;
}
removedFeatures.push(removedFeature);
}
if (removedFeatures.length > 0) {
this.changed();
}
} And to make if (this.hasListener(VectorEventType.REMOVEFEATURE)) {
this.dispatchEvent(
new VectorSourceEvent(VectorEventType.REMOVEFEATURE, feature),
);
} |
I've edited my post above. But I can't call only edit |
Looks like you have messed up something. This is what I had in mind: ahocevar@1e14403 |
add514f
to
2eb7ba4
Compare
Thanks, but again, If I only apply your changes, the And features will be only partially removed / broken. |
Oh, sorry again, you're right. The code you marked above can simply be moved from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that's what you did. Beautiful! Thanks for the contribution.
For #15642
Be able to remove a feature from vector source without triggering events. Useful to batch remove features.