Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/control/cad.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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 @@ -145,6 +147,11 @@ class CadControl extends Control {
*/
this.filter = options.filter || null;

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

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

const lines = [];
let lines = [];
const helpLinesOrdered = [];
const helpLines = {
[ORTHO_LINE_KEY]: [],
Expand Down Expand Up @@ -707,6 +714,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