Skip to content

Commit

Permalink
feat: add line filter for reducing line clutter (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac authored May 10, 2024
1 parent c01148d commit 842e836
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/control/cad.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CadControl extends Control {
* @param {Function} [options.drawCustomSnapLines] Allow to draw more snapping lines using selected corrdinaites.
* @param {Function} [options.filter] Returns an array containing the features
* to include for CAD (takes the source as a single argument).
* @param {Function} [options.lineFilter] An optional filter for the generated snapping lines
* array (takes the lines and cursor coordinate as arguments and returns the new line array)
* @param {Number} [options.nbClosestFeatures] Number of features to use for snapping (closest first). Default is 5.
* @param {Number} [options.snapTolerance] Snap tolerance in pixel
* for snap lines. Default is 10.
Expand Down Expand Up @@ -146,6 +148,11 @@ class CadControl extends Control {
*/
this.filter = options.filter || (() => true);

/**
* Filter the generated line list
*/
this.lineFilter = options.lineFilter || null;

/**
* Interaction for snapping
* @type {ol.interaction.Snap}
Expand Down Expand Up @@ -656,7 +663,7 @@ class CadControl extends Control {
snapLinesOrder,
} = this.properties;

const lines = [];
let lines = [];
const helpLinesOrdered = [];
const helpLines = {
[ORTHO_LINE_KEY]: [],
Expand Down Expand Up @@ -706,6 +713,10 @@ class CadControl extends Control {
}
});

if (typeof this.lineFilter === 'function') {
lines = this.lineFilter(lines, coordinate);
}

// We snap on intersections of lines (distance < this.snapTolerance) or on all the help lines.
const intersectFeatures = getIntersectedLinesAndPoint(
coordinate,
Expand Down

0 comments on commit 842e836

Please sign in to comment.