Skip to content

Commit

Permalink
feat: applied suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
itoxiq committed Dec 20, 2023
1 parent e9a99ce commit e9525b5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface TerraDrawModeRegisterConfig {
onFinish: (finishedId: string) => void;
project: Project;
unproject: Unproject;
coordinatePrecision: number;
}

export type TerraDrawModeState =
Expand Down
7 changes: 2 additions & 5 deletions src/modes/base.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export enum ModeTypes {
export type BaseModeOptions<T extends CustomStyling> = {
styles?: Partial<T>;
pointerDistance?: number;
coordinatePrecision?: number;
};

export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
Expand All @@ -61,7 +60,7 @@ export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {

protected behaviors: TerraDrawModeBehavior[] = [];
protected pointerDistance: number;
protected coordinatePrecision: number;
protected coordinatePrecision!: number;
protected onStyleChange!: StoreChangeHandler;
protected store!: GeoJSONStore;
protected setDoubleClickToZoom!: TerraDrawModeRegisterConfig["setDoubleClickToZoom"];
Expand All @@ -76,8 +75,6 @@ export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
options && options.styles ? { ...options.styles } : ({} as Partial<T>);

this.pointerDistance = (options && options.pointerDistance) || 40;

this.coordinatePrecision = (options && options.coordinatePrecision) || 9;
}

type = ModeTypes.Drawing;
Expand Down Expand Up @@ -134,7 +131,7 @@ export abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
project: this.project,
unproject: this.unproject,
pointerDistance: this.pointerDistance,
coordinatePrecision: this.coordinatePrecision,
coordinatePrecision: config.coordinatePrecision,
});
} else {
throw new Error("Can not register unless mode is unregistered");
Expand Down
9 changes: 2 additions & 7 deletions src/terra-draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ class TerraDraw {
}) {
this._adapter = options.adapter;

const coordinatePrecision = this._adapter.getCoordinatePrecision();

this._mode = new TerraDrawStaticMode({
coordinatePrecision,
});
this._mode = new TerraDrawStaticMode();

// Keep track of if there are duplicate modes
const duplicateModeTracker = new Set();
Expand All @@ -97,8 +93,6 @@ class TerraDraw {
}
duplicateModeTracker.add(currentMode.mode);
modeMap[currentMode.mode] = currentMode;
// ovveride the coordinate precision of the mode
modeMap[currentMode.mode].setCoordinatePrecision(coordinatePrecision);
return modeMap;
}, {});

Expand Down Expand Up @@ -259,6 +253,7 @@ class TerraDraw {
onSelect: onSelect,
onDeselect: onDeselect,
onFinish: onFinish,
coordinatePrecision: this._adapter.getCoordinatePrecision(),
});
});
}
Expand Down
1 change: 1 addition & 0 deletions src/test/mock-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export function getMockModeConfig(mode: string) {
unproject: jest.fn(),
setDoubleClickToZoom: jest.fn(),
onFinish: jest.fn(),
coordinatePrecision: 9,
};
}

0 comments on commit e9525b5

Please sign in to comment.