Skip to content

Commit 842e836

Browse files
authored
feat: add line filter for reducing line clutter (#265)
1 parent c01148d commit 842e836

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/control/cad.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class CadControl extends Control {
3636
* @param {Function} [options.drawCustomSnapLines] Allow to draw more snapping lines using selected corrdinaites.
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.lineFilter] An optional filter for the generated snapping lines
40+
* array (takes the lines and cursor coordinate as arguments and returns the new line array)
3941
* @param {Number} [options.nbClosestFeatures] Number of features to use for snapping (closest first). Default is 5.
4042
* @param {Number} [options.snapTolerance] Snap tolerance in pixel
4143
* for snap lines. Default is 10.
@@ -146,6 +148,11 @@ class CadControl extends Control {
146148
*/
147149
this.filter = options.filter || (() => true);
148150

151+
/**
152+
* Filter the generated line list
153+
*/
154+
this.lineFilter = options.lineFilter || null;
155+
149156
/**
150157
* Interaction for snapping
151158
* @type {ol.interaction.Snap}
@@ -656,7 +663,7 @@ class CadControl extends Control {
656663
snapLinesOrder,
657664
} = this.properties;
658665

659-
const lines = [];
666+
let lines = [];
660667
const helpLinesOrdered = [];
661668
const helpLines = {
662669
[ORTHO_LINE_KEY]: [],
@@ -706,6 +713,10 @@ class CadControl extends Control {
706713
}
707714
});
708715

716+
if (typeof this.lineFilter === 'function') {
717+
lines = this.lineFilter(lines, coordinate);
718+
}
719+
709720
// We snap on intersections of lines (distance < this.snapTolerance) or on all the help lines.
710721
const intersectFeatures = getIntersectedLinesAndPoint(
711722
coordinate,

0 commit comments

Comments
 (0)