Skip to content

Commit

Permalink
avoid duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-000 committed Mar 26, 2023
1 parent 5c505ee commit 13bae97
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/box-selection.js
Expand Up @@ -84,7 +84,11 @@ dragBox.on('boxend', function () {

const boxFeatures = vectorSource
.getFeaturesInExtent(extent)
.filter((feature) => feature.getGeometry().intersectsExtent(extent));
.filter(
(feature) =>
!selectedFeatures.getArray().includes(feature) &&
feature.getGeometry().intersectsExtent(extent)
);

// features that intersect the box geometry are added to the
// collection of selected features
Expand Down Expand Up @@ -127,12 +131,9 @@ dragBox.on('boxstart', function () {
const infoBox = document.getElementById('info');

selectedFeatures.on(['add', 'remove'], function () {
const names = selectedFeatures
.getArray()
.filter((feature, index, array) => array.indexOf(feature) === index)
.map((feature) => {
return feature.get('ECO_NAME');
});
const names = selectedFeatures.getArray().map((feature) => {
return feature.get('ECO_NAME');
});
if (names.length > 0) {
infoBox.innerHTML = names.join(', ');
} else {
Expand Down

0 comments on commit 13bae97

Please sign in to comment.