Skip to content

Commit

Permalink
fix: ensure that closing points for polygons are update on click
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLMilner committed Mar 19, 2023
1 parent 9849bce commit 25c0886
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/modes/polygon/polygon.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class TerraDrawPolygonMode extends TerraDrawBaseDrawMode<PolygonStyling>
private allowSelfIntersections: boolean;
private keyEvents: TerraDrawPolygonModeKeyEvents;
private snappingEnabled: boolean;
private isClosed = false;

// Behaviors
private snapping!: SnappingBehavior;
Expand Down Expand Up @@ -191,15 +190,7 @@ export class TerraDrawPolygonMode extends TerraDrawBaseDrawMode<PolygonStyling>
currentPolygonCoordinates[0],
currentPolygonCoordinates[0],
];

if (!this.isClosed) {
this.isClosed = true;
}
} else {
if (this.isClosed) {
this.isClosed = false;
}

updatedCoordinates = [
...currentPolygonCoordinates.slice(0, -2),
[event.lng, event.lat],
Expand Down Expand Up @@ -384,6 +375,11 @@ export class TerraDrawPolygonMode extends TerraDrawBaseDrawMode<PolygonStyling>
{ id: this.currentId, geometry: updatedPolygon.geometry },
]);
this.currentCoordinate++;

// Update closing points straight away
if (this.closingPoints.ids.length) {
this.closingPoints.update(updatedPolygon.geometry.coordinates[0]);
}
}
}
}
Expand Down

0 comments on commit 25c0886

Please sign in to comment.