Skip to content

Commit

Permalink
Merge pull request #86 from JamesLMilner/freehand-closing-point
Browse files Browse the repository at this point in the history
feat: prevent creating points around closing point
  • Loading branch information
JamesLMilner authored Sep 18, 2023
2 parents e3f4422 + d28b076 commit 3e5a725
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/modes/freehand/freehand.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ export class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<FreehandPolygon
private minDistance: number;
private keyEvents: TerraDrawFreehandModeKeyEvents;
private cursors: Required<Cursors>;
private preventPointsNearClose: boolean;

constructor(options?: {
styles?: Partial<FreehandPolygonStyling>;
minDistance?: number;
preventPointsNearClose?: boolean;
keyEvents?: TerraDrawFreehandModeKeyEvents | null;
cursors?: Cursors;
}) {
Expand All @@ -65,6 +67,9 @@ export class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<FreehandPolygon
this.cursors = defaultCursors;
}

this.preventPointsNearClose =
(options && options.preventPointsNearClose) || true;

this.minDistance = (options && options.minDistance) || 20;

// We want to have some defaults, but also allow key bindings
Expand Down Expand Up @@ -142,6 +147,12 @@ export class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<FreehandPolygon

if (closingDistance < this.pointerDistance) {
this.setCursor(this.cursors.close);

// We want to prohibit drawing new points at or around the closing
// point as it can be non user friendly
if (this.preventPointsNearClose) {
return;
}
} else {
this.setCursor(this.cursors.start);
}
Expand Down

0 comments on commit 3e5a725

Please sign in to comment.