Merge pull request #13195 from ahocevar/box-selection
Use getFeaturesInExtent
This commit is contained in:
@@ -68,6 +68,11 @@ const dragBox = new DragBox({
|
|||||||
map.addInteraction(dragBox);
|
map.addInteraction(dragBox);
|
||||||
|
|
||||||
dragBox.on('boxend', function () {
|
dragBox.on('boxend', function () {
|
||||||
|
const extent = dragBox.getGeometry().getExtent();
|
||||||
|
const boxFeatures = vectorSource
|
||||||
|
.getFeaturesInExtent(extent)
|
||||||
|
.filter((feature) => feature.getGeometry().intersectsExtent(extent));
|
||||||
|
|
||||||
// features that intersect the box geometry are added to the
|
// features that intersect the box geometry are added to the
|
||||||
// collection of selected features
|
// collection of selected features
|
||||||
|
|
||||||
@@ -76,11 +81,6 @@ dragBox.on('boxend', function () {
|
|||||||
// be added directly to the collection
|
// be added directly to the collection
|
||||||
const rotation = map.getView().getRotation();
|
const rotation = map.getView().getRotation();
|
||||||
const oblique = rotation % (Math.PI / 2) !== 0;
|
const oblique = rotation % (Math.PI / 2) !== 0;
|
||||||
const candidateFeatures = oblique ? [] : selectedFeatures;
|
|
||||||
const extent = dragBox.getGeometry().getExtent();
|
|
||||||
vectorSource.forEachFeatureIntersectingExtent(extent, function (feature) {
|
|
||||||
candidateFeatures.push(feature);
|
|
||||||
});
|
|
||||||
|
|
||||||
// when the view is obliquely rotated the box extent will
|
// when the view is obliquely rotated the box extent will
|
||||||
// exceed its geometry so both the box and the candidate
|
// exceed its geometry so both the box and the candidate
|
||||||
@@ -92,13 +92,15 @@ dragBox.on('boxend', function () {
|
|||||||
const geometry = dragBox.getGeometry().clone();
|
const geometry = dragBox.getGeometry().clone();
|
||||||
geometry.rotate(-rotation, anchor);
|
geometry.rotate(-rotation, anchor);
|
||||||
const extent = geometry.getExtent();
|
const extent = geometry.getExtent();
|
||||||
candidateFeatures.forEach(function (feature) {
|
boxFeatures.forEach(function (feature) {
|
||||||
const geometry = feature.getGeometry().clone();
|
const geometry = feature.getGeometry().clone();
|
||||||
geometry.rotate(-rotation, anchor);
|
geometry.rotate(-rotation, anchor);
|
||||||
if (geometry.intersectsExtent(extent)) {
|
if (geometry.intersectsExtent(extent)) {
|
||||||
selectedFeatures.push(feature);
|
selectedFeatures.push(feature);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
selectedFeatures.extend(boxFeatures);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user