terra-draw 0.0.1-alpha.67 → 0.0.1-alpha.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/common.d.ts CHANGED
@@ -45,6 +45,10 @@ export type GetLngLatFromEvent = (event: PointerEvent | MouseEvent) => {
45
45
  lng: number;
46
46
  lat: number;
47
47
  } | null;
48
+ export type OnFinishContext = {
49
+ mode: string;
50
+ action: string;
51
+ };
48
52
  export interface TerraDrawModeRegisterConfig {
49
53
  mode: string;
50
54
  store: GeoJSONStore;
@@ -53,12 +57,19 @@ export interface TerraDrawModeRegisterConfig {
53
57
  onChange: StoreChangeHandler;
54
58
  onSelect: (selectedId: string) => void;
55
59
  onDeselect: (deselectedId: string) => void;
56
- onFinish: (finishedId: string) => void;
60
+ onFinish: (finishedId: string, context: OnFinishContext) => void;
57
61
  project: Project;
58
62
  unproject: Unproject;
59
63
  coordinatePrecision: number;
60
64
  }
61
- type ValidationContext = Pick<TerraDrawModeRegisterConfig, "project" | "unproject" | "coordinatePrecision">;
65
+ export declare enum UpdateTypes {
66
+ Commit = "commit",
67
+ Provisional = "provisional",
68
+ Finish = "finish"
69
+ }
70
+ type ValidationContext = Pick<TerraDrawModeRegisterConfig, "project" | "unproject" | "coordinatePrecision"> & {
71
+ updateType: UpdateTypes;
72
+ };
62
73
  export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) => boolean;
63
74
  export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped";
64
75
  export interface TerraDrawCallbacks {
@@ -1,5 +1,5 @@
1
1
  import { BehaviorConfig, TerraDrawModeBehavior } from "./base.behavior";
2
- import { HexColor, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, TerraDrawModeRegisterConfig, TerraDrawModeState, TerraDrawMouseEvent } from "../common";
2
+ import { HexColor, OnFinishContext, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, TerraDrawModeRegisterConfig, TerraDrawModeState, TerraDrawMouseEvent, Validation } from "../common";
3
3
  import { FeatureId, GeoJSONStore, GeoJSONStoreFeatures, StoreChangeHandler } from "../store/store";
4
4
  export type CustomStyling = Record<string, string | number | ((feature: GeoJSONStoreFeatures) => HexColor) | ((feature: GeoJSONStoreFeatures) => number)>;
5
5
  export declare enum ModeTypes {
@@ -11,6 +11,7 @@ export declare enum ModeTypes {
11
11
  export type BaseModeOptions<T extends CustomStyling> = {
12
12
  styles?: Partial<T>;
13
13
  pointerDistance?: number;
14
+ validation?: Validation;
14
15
  };
15
16
  export declare abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
16
17
  protected _state: TerraDrawModeState;
@@ -20,6 +21,7 @@ export declare abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
20
21
  get styles(): Partial<T>;
21
22
  set styles(styling: Partial<T>);
22
23
  protected behaviors: TerraDrawModeBehavior[];
24
+ protected validate: Validation | undefined;
23
25
  protected pointerDistance: number;
24
26
  protected coordinatePrecision: number;
25
27
  protected onStyleChange: StoreChangeHandler;
@@ -41,7 +43,7 @@ export declare abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
41
43
  abstract stop(): void;
42
44
  abstract cleanUp(): void;
43
45
  abstract styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
44
- onFinish(finishedId: FeatureId): void;
46
+ onFinish(finishedId: FeatureId, context: OnFinishContext): void;
45
47
  onDeselect(deselectedId: FeatureId): void;
46
48
  onSelect(selectedId: FeatureId): void;
47
49
  onKeyDown(event: TerraDrawKeyboardEvent): void;
@@ -17,7 +17,7 @@ interface Cursors {
17
17
  interface TerraDrawCircleModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
18
18
  keyEvents?: TerraDrawCircleModeKeyEvents | null;
19
19
  cursors?: Cursors;
20
- minimumRadiusKilometers?: number;
20
+ startingRadiusKilometers?: number;
21
21
  }
22
22
  export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePolygonStyling> {
23
23
  mode: string;
@@ -26,13 +26,12 @@ export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePol
26
26
  private currentCircleId;
27
27
  private keyEvents;
28
28
  private cursors;
29
- private minimumRadiusKilometers;
29
+ private startingRadiusKilometers;
30
30
  /**
31
31
  * Create a new circle mode instance
32
32
  * @param options - Options to customize the behavior of the circle mode
33
33
  * @param options.keyEvents - Key events to cancel or finish the mode
34
34
  * @param options.cursors - Cursors to use for the mode
35
- * @param options.minimumRadiusKilometers - Minimum radius for the circle
36
35
  * @param options.styles - Custom styling for the circle
37
36
  * @param options.pointerDistance - Distance in pixels to consider a pointer close to a vertex
38
37
  */
@@ -61,6 +60,6 @@ export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePol
61
60
  /** @internal */
62
61
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
63
62
  validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
64
- private createCircle;
63
+ private updateCircle;
65
64
  }
66
65
  export {};
@@ -20,7 +20,6 @@ interface Cursors {
20
20
  }
21
21
  interface TerraDrawLineStringModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
22
22
  snapping?: boolean;
23
- allowSelfIntersections?: boolean;
24
23
  pointerDistance?: number;
25
24
  keyEvents?: TerraDrawLineStringModeKeyEvents | null;
26
25
  cursors?: Cursors;
@@ -30,7 +29,6 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
30
29
  private currentCoordinate;
31
30
  private currentId;
32
31
  private closingPointId;
33
- private allowSelfIntersections;
34
32
  private keyEvents;
35
33
  private snappingEnabled;
36
34
  private cursors;
@@ -38,6 +36,7 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
38
36
  private snapping;
39
37
  constructor(options?: TerraDrawLineStringModeOptions<LineStringStyling>);
40
38
  private close;
39
+ private updateGeometries;
41
40
  /** @internal */
42
41
  registerBehaviors(config: BehaviorConfig): void;
43
42
  /** @internal */
@@ -21,7 +21,6 @@ interface Cursors {
21
21
  close?: Cursor;
22
22
  }
23
23
  interface TerraDrawPolygonModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
24
- allowSelfIntersections?: boolean;
25
24
  snapping?: boolean;
26
25
  pointerDistance?: number;
27
26
  keyEvents?: TerraDrawPolygonModeKeyEvents | null;
@@ -31,7 +30,6 @@ export declare class TerraDrawPolygonMode extends TerraDrawBaseDrawMode<PolygonS
31
30
  mode: string;
32
31
  private currentCoordinate;
33
32
  private currentId;
34
- private allowSelfIntersections;
35
33
  private keyEvents;
36
34
  private snappingEnabled;
37
35
  private snapping;
@@ -49,6 +47,7 @@ export declare class TerraDrawPolygonMode extends TerraDrawBaseDrawMode<PolygonS
49
47
  stop(): void;
50
48
  /** @internal */
51
49
  onMouseMove(event: TerraDrawMouseEvent): void;
50
+ private updatePolygonGeometry;
52
51
  /** @internal */
53
52
  onClick(event: TerraDrawMouseEvent): void;
54
53
  /** @internal */