terra-draw 1.7.0 → 1.9.0

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
@@ -1,3 +1,4 @@
1
+ import { LineString, Polygon, Position } from "geojson";
1
2
  import { StoreChangeHandler, GeoJSONStore, GeoJSONStoreFeatures, FeatureId } from "./store/store";
2
3
  export type HexColor = `#${string}`;
3
4
  export type HexColorStyling = HexColor | ((feature: GeoJSONStoreFeatures) => HexColor);
@@ -78,6 +79,17 @@ export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationCont
78
79
  valid: boolean;
79
80
  reason?: string;
80
81
  };
82
+ export interface Snapping {
83
+ toLine?: boolean;
84
+ toCoordinate?: boolean;
85
+ toCustom?: (event: TerraDrawMouseEvent, context: {
86
+ currentId?: FeatureId;
87
+ currentCoordinate?: number;
88
+ getCurrentGeometrySnapshot: () => (Polygon | LineString) | null;
89
+ project: Project;
90
+ unproject: Unproject;
91
+ }) => Position | undefined;
92
+ }
81
93
  export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped";
82
94
  export interface TerraDrawCallbacks {
83
95
  getState: () => TerraDrawModeState;
@@ -120,6 +132,7 @@ export declare const SELECT_PROPERTIES: {
120
132
  readonly SELECTION_POINT: "selectionPoint";
121
133
  };
122
134
  export declare const COMMON_PROPERTIES: {
135
+ readonly CURRENTLY_DRAWING: "currentlyDrawing";
123
136
  readonly EDITED: "edited";
124
137
  readonly CLOSING_POINT: "closingPoint";
125
138
  readonly SNAPPING_POINT: "snappingPoint";
@@ -1,5 +1,4 @@
1
- import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
2
- import { Position } from "geojson";
1
+ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor, Snapping } from "../../common";
3
2
  import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
4
3
  import { BehaviorConfig } from "../base.behavior";
5
4
  import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
@@ -29,10 +28,6 @@ interface InertCoordinates {
29
28
  strategy: "amount";
30
29
  value: number;
31
30
  }
32
- interface Snapping {
33
- toCoordinate?: boolean;
34
- toCustom?: (event: TerraDrawMouseEvent) => Position | undefined;
35
- }
36
31
  interface TerraDrawLineStringModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
37
32
  snapping?: Snapping;
38
33
  pointerDistance?: number;
@@ -1,8 +1,7 @@
1
- import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor, Project, Unproject } from "../../common";
2
- import { Polygon, Position } from "geojson";
1
+ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor, Snapping } from "../../common";
3
2
  import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling, PointerEvents } from "../base.mode";
4
3
  import { BehaviorConfig } from "../base.behavior";
5
- import { FeatureId, GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
4
+ import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
6
5
  type TerraDrawPolygonModeKeyEvents = {
7
6
  cancel?: KeyboardEvent["key"] | null;
8
7
  finish?: KeyboardEvent["key"] | null;
@@ -35,17 +34,6 @@ interface Cursors {
35
34
  dragStart?: Cursor;
36
35
  dragEnd?: Cursor;
37
36
  }
38
- interface Snapping {
39
- toLine?: boolean;
40
- toCoordinate?: boolean;
41
- toCustom?: (event: TerraDrawMouseEvent, context: {
42
- currentId?: FeatureId;
43
- currentCoordinate?: number;
44
- getCurrentGeometrySnapshot: () => Polygon | null;
45
- project: Project;
46
- unproject: Unproject;
47
- }) => Position | undefined;
48
- }
49
37
  interface TerraDrawPolygonModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
50
38
  snapping?: Snapping;
51
39
  pointerDistance?: number;
@@ -1,4 +1,4 @@
1
- import { TerraDrawMouseEvent, Validation } from "../../../common";
1
+ import { Snapping, TerraDrawMouseEvent, Validation } from "../../../common";
2
2
  import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
3
3
  import { PixelDistanceBehavior } from "../../pixel-distance.behavior";
4
4
  import { MidPointBehavior } from "./midpoint.behavior";
@@ -6,6 +6,7 @@ import { SelectionPointBehavior } from "./selection-point.behavior";
6
6
  import { FeatureId } from "../../../store/store";
7
7
  import { CoordinatePointBehavior } from "./coordinate-point.behavior";
8
8
  import { CoordinateSnappingBehavior } from "../../coordinate-snapping.behavior";
9
+ import { LineSnappingBehavior } from "../../line-snapping.behavior";
9
10
  export declare class DragCoordinateBehavior extends TerraDrawModeBehavior {
10
11
  readonly config: BehaviorConfig;
11
12
  private readonly pixelDistance;
@@ -13,11 +14,13 @@ export declare class DragCoordinateBehavior extends TerraDrawModeBehavior {
13
14
  private readonly midPoints;
14
15
  private readonly coordinatePoints;
15
16
  private readonly coordinateSnapping;
16
- constructor(config: BehaviorConfig, pixelDistance: PixelDistanceBehavior, selectionPoints: SelectionPointBehavior, midPoints: MidPointBehavior, coordinatePoints: CoordinatePointBehavior, coordinateSnapping: CoordinateSnappingBehavior);
17
+ private readonly lineSnapping;
18
+ constructor(config: BehaviorConfig, pixelDistance: PixelDistanceBehavior, selectionPoints: SelectionPointBehavior, midPoints: MidPointBehavior, coordinatePoints: CoordinatePointBehavior, coordinateSnapping: CoordinateSnappingBehavior, lineSnapping: LineSnappingBehavior);
17
19
  private draggedCoordinate;
18
20
  private getClosestCoordinate;
19
21
  getDraggableIndex(event: TerraDrawMouseEvent, selectedId: FeatureId): number;
20
- drag(event: TerraDrawMouseEvent, allowSelfIntersection: boolean, validateFeature: Validation, snapping: boolean): boolean;
22
+ private snapCoordinate;
23
+ drag(event: TerraDrawMouseEvent, allowSelfIntersection: boolean, validateFeature: Validation, snapping: Snapping): boolean;
21
24
  isDragging(): boolean;
22
25
  startDragging(id: FeatureId, index: number): void;
23
26
  stopDragging(): void;
@@ -1,4 +1,4 @@
1
- import { TerraDrawMouseEvent, TerraDrawKeyboardEvent, TerraDrawAdapterStyling, HexColorStyling, NumericStyling, Cursor, Validation } from "../../common";
1
+ import { TerraDrawMouseEvent, TerraDrawKeyboardEvent, TerraDrawAdapterStyling, HexColorStyling, NumericStyling, Cursor, Validation, Snapping } from "../../common";
2
2
  import { BaseModeOptions, CustomStyling, TerraDrawBaseSelectMode } from "../base.mode";
3
3
  import { BehaviorConfig } from "../base.behavior";
4
4
  import { FeatureId, GeoJSONStoreFeatures } from "../../store/store";
@@ -17,7 +17,7 @@ type ModeFlags = {
17
17
  scaleable?: boolean;
18
18
  selfIntersectable?: boolean;
19
19
  coordinates?: {
20
- snappable?: boolean;
20
+ snappable?: boolean | Snapping;
21
21
  midpoints?: boolean | {
22
22
  draggable?: boolean;
23
23
  };
@@ -85,6 +85,7 @@ export declare class TerraDrawSelectMode extends TerraDrawBaseSelectMode<Selecti
85
85
  private scaleFeature;
86
86
  private dragCoordinateResizeFeature;
87
87
  private coordinatePoints;
88
+ private lineSnap;
88
89
  constructor(options?: TerraDrawSelectModeOptions<SelectionStyling>);
89
90
  updateOptions(options?: TerraDrawSelectModeOptions<SelectionStyling>): void;
90
91
  selectFeature(featureId: FeatureId): void;
@@ -45,7 +45,7 @@ export declare class GeoJSONStore<OnChangeContext extends Record<string, JSON> |
45
45
  updateProperty(propertiesToUpdate: {
46
46
  id: FeatureId;
47
47
  property: string;
48
- value: JSON;
48
+ value: JSON | undefined;
49
49
  }[], context?: OnChangeContext): void;
50
50
  updateGeometry(geometriesToUpdate: {
51
51
  id: FeatureId;