Merge pull request #11597 from MoonE/select-interaction-performance

Improved performance when removing feature with only one Select
This commit is contained in:
Andreas Hocevar
2020-09-30 13:09:49 +02:00
committed by GitHub
+13 -15
View File
@@ -391,26 +391,24 @@ class Select extends Interaction {
* @private * @private
*/ */
restorePreviousStyle_(feature) { restorePreviousStyle_(feature) {
const key = getUid(feature); const interactions = this.getMap().getInteractions().getArray();
const selectInteractions = /** @type {Array<Select>} */ (this.getMap() for (let i = interactions.length - 1; i >= 0; --i) {
.getInteractions() const interaction = interactions[i];
.getArray() if (
.filter(function (interaction) { interaction !== this &&
return (
interaction instanceof Select && interaction instanceof Select &&
interaction.getStyle() && interaction.getStyle() &&
interaction.getFeatures().getArray().indexOf(feature) !== -1 interaction.getFeatures().getArray().lastIndexOf(feature) !== -1
); ) {
})); feature.setStyle(interaction.getStyle());
if (selectInteractions.length > 0) { return;
feature.setStyle( }
selectInteractions[selectInteractions.length - 1].getStyle() }
);
} else { const key = getUid(feature);
feature.setStyle(originalFeatureStyles[key]); feature.setStyle(originalFeatureStyles[key]);
delete originalFeatureStyles[key]; delete originalFeatureStyles[key];
} }
}
/** /**
* @param {import("../Feature.js").FeatureLike} feature Feature. * @param {import("../Feature.js").FeatureLike} feature Feature.