Skip to content

Commit

Permalink
fix: ensure that coordinate precision is limited when dragging a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLMilner committed Jul 25, 2023
1 parent 4a20411 commit b7da22a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/modes/select/behaviors/drag-feature.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FeaturesAtMouseEventBehavior } from "./features-at-mouse-event.behavior
import { Position } from "geojson";
import { SelectionPointBehavior } from "./selection-point.behavior";
import { MidPointBehavior } from "./midpoint.behavior";
import { limitPrecision } from "../../../geometry/limit-decimal-precision";

export class DragFeatureBehavior extends TerraDrawModeBehavior {
constructor(
Expand Down Expand Up @@ -100,8 +101,16 @@ export class DragFeatureBehavior extends TerraDrawModeBehavior {
this.dragPosition[1] - mouseCoord[1],
];

const updatedLng = coordinate[0] - delta[0];
const updatedLat = coordinate[1] - delta[1];
// Keep precision limited when calculating new coordinates
const updatedLng = limitPrecision(
coordinate[0] - delta[0],
this.config.coordinatePrecision
);

const updatedLat = limitPrecision(
coordinate[1] - delta[1],
this.config.coordinatePrecision
);

// Ensure that coordinates are valid
if (
Expand All @@ -113,7 +122,7 @@ export class DragFeatureBehavior extends TerraDrawModeBehavior {
return false;
}

updatedCoords[i] = [updatedLng, coordinate[1] - delta[1]];
updatedCoords[i] = [updatedLng, updatedLat];
}

// Set final coordinate identical to first
Expand Down

0 comments on commit b7da22a

Please sign in to comment.