Skip to content

Commit aa160a4

Browse files
committed
feat: add extentFilter property in CAD control
1 parent 5401e83 commit aa160a4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/control/cad.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ import {
3333
class CadControl extends Control {
3434
/**
3535
* @param {Object} [options] Tool options.
36-
* @param {Function} [options.drawCustomSnapLines] Allow to draw more snapping lines using selected corrdinaites.
36+
* @param {Function} [options.drawCustomSnapLines] Allow to draw more snapping lines using selected coordinates.
3737
* @param {Function} [options.filter] Returns an array containing the features
3838
* to include for CAD (takes the source as a single argument).
39+
* @param {Function} [options.extentFilter] An optional spatial filter for the features to snap with. Returns an ol.Extent which will be used by the source.getFeaturesinExtent method.
3940
* @param {Function} [options.lineFilter] An optional filter for the generated snapping lines
4041
* array (takes the lines and cursor coordinate as arguments and returns the new line array)
4142
* @param {Number} [options.nbClosestFeatures] Number of features to use for snapping (closest first). Default is 5.
@@ -148,6 +149,13 @@ class CadControl extends Control {
148149
*/
149150
this.filter = options.filter || (() => true);
150151

152+
/**
153+
* Filter the features spatially.
154+
*/
155+
this.extentFilter =
156+
options.extentFilter ||
157+
(() => [-Infinity, -Infinity, Infinity, Infinity]);
158+
151159
/**
152160
* Filter the generated line list
153161
*/
@@ -282,9 +290,10 @@ class CadControl extends Control {
282290
const sortByDistance = (a, b) => dist(a) - dist(b);
283291

284292
let features = this.source
285-
.getFeatures()
286-
.filter(this.filter)
287-
.filter((f) => !currentFeatures.includes(f))
293+
.getFeaturesInExtent(this.extentFilter())
294+
.filter(
295+
(feature) => this.filter(feature) && !currentFeatures.includes(feature),
296+
)
288297
.sort(sortByDistance)
289298
.slice(0, nbFeatures);
290299

0 commit comments

Comments
 (0)