Skip to content

Commit

Permalink
fix: ensure coordinate precision is set via the config to the adapter (
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLMilner authored Dec 22, 2023
1 parent 47555a8 commit 0407295
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modes/base.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
this._styles =
options && options.styles ? { ...options.styles } : ({} as Partial<T>);
this.pointerDistance = (options && options.pointerDistance) || 40;
this.coordinatePrecision = 9;
}

type = ModeTypes.Drawing;
Expand Down Expand Up @@ -124,6 +123,7 @@ export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
this.setCursor = config.setCursor;
this.onStyleChange = config.onChange;
this.onFinish = config.onFinish;
this.coordinatePrecision = config.coordinatePrecision;

this.registerBehaviors({
mode: config.mode,
Expand All @@ -139,6 +139,10 @@ export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
}

validateFeature(feature: unknown): feature is GeoJSONStoreFeatures {
if (this._state === "unregistered") {
throw new Error("Mode must be registered");
}

return isValidStoreFeature(feature);
}

Expand Down
2 changes: 2 additions & 0 deletions src/modes/circle/circle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ describe("TerraDrawCircleMode", () => {
fillOpacity: 0.5,
},
});
circleMode.register(getMockModeConfig("circle"));

expect(
circleMode.validateFeature({
Expand Down Expand Up @@ -532,6 +533,7 @@ describe("TerraDrawCircleMode", () => {
fillOpacity: 0.5,
},
});
circleMode.register(getMockModeConfig("circle"));

expect(
circleMode.validateFeature({
Expand Down
2 changes: 2 additions & 0 deletions src/modes/freehand/freehand.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ describe("TerraDrawFreehandMode", () => {
closingPointOutlineColor: "#111111",
},
});
freehandMode.register(getMockModeConfig("freehand"));

expect(
freehandMode.validateFeature({
Expand Down Expand Up @@ -573,6 +574,7 @@ describe("TerraDrawFreehandMode", () => {
closingPointOutlineColor: "#111111",
},
});
freehandMode.register(getMockModeConfig("freehand"));

expect(
freehandMode.validateFeature({
Expand Down
2 changes: 2 additions & 0 deletions src/modes/greatcircle/great-circle.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ describe("TerraDrawGreatCircleMode", () => {
lineStringColor: "#ffffff",
},
});
greatCircleMode.register(getMockModeConfig("greatcircle"));

expect(
greatCircleMode.validateFeature({
Expand All @@ -655,6 +656,7 @@ describe("TerraDrawGreatCircleMode", () => {
lineStringColor: "#ffffff",
},
});
greatCircleMode.register(getMockModeConfig("greatcircle"));

expect(
greatCircleMode.validateFeature({
Expand Down
2 changes: 2 additions & 0 deletions src/modes/linestring/linestring.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ describe("TerraDrawLineStringMode", () => {
lineStringColor: "#ffffff",
},
});
lineStringMode.register(getMockModeConfig("linestring"));

expect(
lineStringMode.validateFeature({
Expand All @@ -900,6 +901,7 @@ describe("TerraDrawLineStringMode", () => {
lineStringColor: "#ffffff",
},
});
lineStringMode.register(getMockModeConfig("linestring"));

expect(
lineStringMode.validateFeature({
Expand Down
4 changes: 4 additions & 0 deletions src/modes/point/point.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ describe("TerraDrawPointMode", () => {
},
});

pointMode.register(getMockModeConfig("point"));

expect(
pointMode.validateFeature({
id: "ed030248-d7ee-45a2-b8e8-37ad2f622509",
Expand All @@ -300,6 +302,8 @@ describe("TerraDrawPointMode", () => {
},
});

pointMode.register(getMockModeConfig("point"));

expect(
pointMode.validateFeature({
id: "ed030248-d7ee-45a2-b8e8-37ad2f622509",
Expand Down
2 changes: 2 additions & 0 deletions src/modes/polygon/polygon.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ describe("validateFeature", () => {
fillOpacity: 0.5,
},
});
polygonMode.register(getMockModeConfig("polygon"));

expect(
polygonMode.validateFeature({
Expand Down Expand Up @@ -1480,6 +1481,7 @@ describe("validateFeature", () => {
fillOpacity: 0.5,
},
});
polygonMode.register(getMockModeConfig("polygon"));

expect(
polygonMode.validateFeature({
Expand Down
2 changes: 2 additions & 0 deletions src/modes/rectangle/rectangle.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ describe("TerraDrawRectangleMode", () => {
fillOpacity: 0.5,
},
});
rectangleMode.register(getMockModeConfig("rectangle"));

expect(
rectangleMode.validateFeature({
Expand Down Expand Up @@ -545,6 +546,7 @@ describe("TerraDrawRectangleMode", () => {
fillOpacity: 0.5,
},
});
rectangleMode.register(getMockModeConfig("rectangle"));

expect(
rectangleMode.validateFeature({
Expand Down
3 changes: 3 additions & 0 deletions src/modes/render/render.mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,21 @@ describe("TerraDrawRenderMode", () => {
describe("validateFeature", () => {
it("validates points", () => {
const renderMode = new TerraDrawRenderMode(options);
renderMode.register(getMockModeConfig("arbitary"));

expect(renderMode.validateFeature(createMockPoint())).toBe(true);
});

it("validates linestrings", () => {
const renderMode = new TerraDrawRenderMode(options);
renderMode.register(getMockModeConfig("arbitary"));

expect(renderMode.validateFeature(createMockLineString())).toBe(true);
});

it("validates polygons", () => {
const renderMode = new TerraDrawRenderMode(options);
renderMode.register(getMockModeConfig("arbitary"));

expect(renderMode.validateFeature(createMockPolygonSquare())).toBe(true);
});
Expand Down

0 comments on commit 0407295

Please sign in to comment.