terra-draw 1.4.3 → 1.6.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/README.md CHANGED
@@ -17,10 +17,10 @@ Terra Draw centralizes map drawing logic and provides a host of out-of-the-box d
17
17
 
18
18
  Terra Draw works with your mapping library of choice via adapters. Please pick the adapter for the mapping library you are working with:
19
19
 
20
- * [terra-draw-maplibre-gl-js-adapter](https://www.npmjs.com/package/terra-draw-maplibre-gl-js-adapter)
20
+ * [terra-draw-maplibre-gl-adapter](https://www.npmjs.com/package/terra-draw-maplibre-gl-adapter)
21
21
  * [terra-draw-leaflet-adapter](https://www.npmjs.com/package/terra-draw-leaflet-adapter)
22
22
  * [terra-draw-google-maps-adapter](https://www.npmjs.com/package/terra-draw-googl-emaps-adapter)
23
- * [terra-draw-mapbox-gl-js-adapter](https://www.npmjs.com/package/terra-draw-mapbox-gl-js-adapter)
23
+ * [terra-draw-mapbox-gl-adapter](https://www.npmjs.com/package/terra-draw-mapbox-gl-adapter)
24
24
  * [terra-draw-google-maps-adapter](https://www.npmjs.com/package/terra-draw-google-maps-adapter)
25
25
  * [terra-draw-arcgis-adapter](https://www.npmjs.com/package/terra-draw-arcgis-adapter)
26
26
 
@@ -11,6 +11,7 @@ export type BaseAdapterConfig = {
11
11
  };
12
12
  export declare abstract class TerraDrawBaseAdapter implements TerraDrawAdapter {
13
13
  constructor(config: BaseAdapterConfig);
14
+ private _nextKeyUpIsContextMenu;
14
15
  protected _minPixelDragDistance: number;
15
16
  protected _minPixelDragDistanceDrawing: number;
16
17
  protected _minPixelDragDistanceSelecting: number;
@@ -26,7 +27,7 @@ export declare abstract class TerraDrawBaseAdapter implements TerraDrawAdapter {
26
27
  containerX: number;
27
28
  containerY: number;
28
29
  };
29
- protected getDrawEventFromEvent(event: PointerEvent | MouseEvent): TerraDrawMouseEvent | null;
30
+ protected getDrawEventFromEvent(event: PointerEvent | MouseEvent, isContextMenu?: boolean): TerraDrawMouseEvent | null;
30
31
  /**
31
32
  * Registers the provided callbacks for the current drawing mode and attaches
32
33
  * the necessary event listeners.
package/dist/common.d.ts CHANGED
@@ -26,6 +26,7 @@ export interface TerraDrawMouseEvent {
26
26
  containerY: number;
27
27
  button: "neither" | "left" | "middle" | "right";
28
28
  heldKeys: string[];
29
+ isContextMenu: boolean;
29
30
  }
30
31
  export interface TerraDrawKeyboardEvent {
31
32
  key: string;
@@ -48,12 +49,16 @@ export type OnFinishContext = {
48
49
  mode: string;
49
50
  action: string;
50
51
  };
52
+ export type OnChangeContext = {
53
+ origin: "api";
54
+ };
55
+ export type TerraDrawGeoJSONStore = GeoJSONStore<OnChangeContext | undefined, FeatureId>;
51
56
  export interface TerraDrawModeRegisterConfig {
52
57
  mode: string;
53
- store: GeoJSONStore;
58
+ store: TerraDrawGeoJSONStore;
54
59
  setDoubleClickToZoom: (enabled: boolean) => void;
55
60
  setCursor: SetCursor;
56
- onChange: StoreChangeHandler;
61
+ onChange: StoreChangeHandler<OnChangeContext | undefined>;
57
62
  onSelect: (selectedId: string) => void;
58
63
  onDeselect: (deselectedId: string) => void;
59
64
  onFinish: (finishedId: string, context: OnFinishContext) => void;
@@ -118,6 +123,14 @@ export declare const COMMON_PROPERTIES: {
118
123
  CLOSING_POINT: string;
119
124
  SNAPPING_POINT: string;
120
125
  COORDINATE_POINT: string;
126
+ COORDINATE_POINT_FEATURE_ID: string;
121
127
  COORDINATE_POINT_IDS: string;
122
128
  };
129
+ export declare const Z_INDEX: {
130
+ readonly LAYER_ONE: 10;
131
+ readonly LAYER_TWO: 20;
132
+ readonly LAYER_THREE: 30;
133
+ readonly LAYER_FOUR: 40;
134
+ readonly LAYER_FIVE: 50;
135
+ };
123
136
  export {};
@@ -1,7 +1,6 @@
1
- import { Project, Projection, Unproject } from "../common";
2
- import { GeoJSONStore } from "../store/store";
1
+ import { Project, Projection, TerraDrawGeoJSONStore, Unproject } from "../common";
3
2
  export type BehaviorConfig = {
4
- store: GeoJSONStore;
3
+ store: TerraDrawGeoJSONStore;
5
4
  mode: string;
6
5
  project: Project;
7
6
  unproject: Unproject;
@@ -10,7 +9,7 @@ export type BehaviorConfig = {
10
9
  projection: Projection;
11
10
  };
12
11
  export declare class TerraDrawModeBehavior {
13
- protected store: GeoJSONStore;
12
+ protected store: TerraDrawGeoJSONStore;
14
13
  protected mode: string;
15
14
  protected project: Project;
16
15
  protected unproject: Unproject;
@@ -1,6 +1,6 @@
1
1
  import { BehaviorConfig, TerraDrawModeBehavior } from "./base.behavior";
2
- import { HexColor, OnFinishContext, Projection, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, TerraDrawModeRegisterConfig, TerraDrawModeState, TerraDrawMouseEvent, Validation } from "../common";
3
- import { FeatureId, GeoJSONStore, GeoJSONStoreFeatures, StoreChangeHandler } from "../store/store";
2
+ import { OnChangeContext, HexColor, OnFinishContext, Projection, TerraDrawAdapterStyling, TerraDrawGeoJSONStore, TerraDrawKeyboardEvent, TerraDrawModeRegisterConfig, TerraDrawModeState, TerraDrawMouseEvent, Validation } from "../common";
3
+ import { FeatureId, 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 {
6
6
  Drawing = "drawing",
@@ -8,11 +8,29 @@ export declare enum ModeTypes {
8
8
  Static = "static",
9
9
  Render = "render"
10
10
  }
11
+ export declare const DefaultPointerEvents: {
12
+ readonly rightClick: true;
13
+ readonly contextMenu: false;
14
+ readonly leftClick: true;
15
+ readonly onDragStart: true;
16
+ readonly onDrag: true;
17
+ readonly onDragEnd: true;
18
+ };
19
+ type AllowPointerEvent = boolean | ((event: TerraDrawMouseEvent) => boolean);
20
+ export interface PointerEvents {
21
+ leftClick: AllowPointerEvent;
22
+ rightClick: AllowPointerEvent;
23
+ contextMenu: AllowPointerEvent;
24
+ onDragStart: AllowPointerEvent;
25
+ onDrag: AllowPointerEvent;
26
+ onDragEnd: AllowPointerEvent;
27
+ }
11
28
  export type BaseModeOptions<Styling extends CustomStyling> = {
12
29
  styles?: Partial<Styling>;
13
30
  pointerDistance?: number;
14
31
  validation?: Validation;
15
32
  projection?: Projection;
33
+ pointerEvents?: PointerEvents;
16
34
  };
17
35
  export declare abstract class TerraDrawBaseDrawMode<Styling extends CustomStyling> {
18
36
  protected _state: TerraDrawModeState;
@@ -21,12 +39,13 @@ export declare abstract class TerraDrawBaseDrawMode<Styling extends CustomStylin
21
39
  protected _styles: Partial<Styling>;
22
40
  get styles(): Partial<Styling>;
23
41
  set styles(styling: Partial<Styling>);
42
+ protected pointerEvents: PointerEvents;
24
43
  protected behaviors: TerraDrawModeBehavior[];
25
44
  protected validate: Validation | undefined;
26
45
  protected pointerDistance: number;
27
46
  protected coordinatePrecision: number;
28
- protected onStyleChange: StoreChangeHandler;
29
- protected store: GeoJSONStore;
47
+ protected onStyleChange: StoreChangeHandler<OnChangeContext | undefined>;
48
+ protected store: TerraDrawGeoJSONStore;
30
49
  protected projection: Projection;
31
50
  protected setDoubleClickToZoom: TerraDrawModeRegisterConfig["setDoubleClickToZoom"];
32
51
  protected unproject: TerraDrawModeRegisterConfig["unproject"];
@@ -35,6 +54,7 @@ export declare abstract class TerraDrawBaseDrawMode<Styling extends CustomStylin
35
54
  protected registerBehaviors(behaviorConfig: BehaviorConfig): void;
36
55
  constructor(options?: BaseModeOptions<Styling>, willCallUpdateOptionsInParentClass?: boolean);
37
56
  updateOptions(options?: BaseModeOptions<Styling>): void;
57
+ protected allowPointerEvent(pointerEvent: AllowPointerEvent, event: TerraDrawMouseEvent): boolean;
38
58
  type: ModeTypes;
39
59
  mode: string;
40
60
  protected setDrawing(): void;
@@ -68,3 +88,4 @@ export declare abstract class TerraDrawBaseSelectMode<Styling extends CustomStyl
68
88
  abstract selectFeature(featureId: FeatureId): void;
69
89
  abstract deselectFeature(featureId: FeatureId): void;
70
90
  }
91
+ export {};
@@ -93,7 +93,7 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
93
93
  /** @internal */
94
94
  onDrag(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
95
95
  /** @internal */
96
- onDragEnd(_: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
96
+ onDragEnd(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
97
97
  /** @internal */
98
98
  cleanUp(): void;
99
99
  /** @internal */
@@ -48,7 +48,7 @@ export declare class TerraDrawPointMode extends TerraDrawBaseDrawMode<PointModeS
48
48
  /** @internal */
49
49
  onDrag(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
50
50
  /** @internal */
51
- onDragEnd(_: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
51
+ onDragEnd(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
52
52
  registerBehaviors(config: BehaviorConfig): void;
53
53
  /** @internal */
54
54
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
@@ -1,6 +1,6 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor, Project, Unproject } from "../../common";
2
2
  import { Polygon, Position } from "geojson";
3
- import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling } from "../base.mode";
3
+ import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling, PointerEvents } from "../base.mode";
4
4
  import { BehaviorConfig } from "../base.behavior";
5
5
  import { FeatureId, GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
6
6
  type TerraDrawPolygonModeKeyEvents = {
@@ -50,6 +50,7 @@ interface TerraDrawPolygonModeOptions<T extends CustomStyling> extends BaseModeO
50
50
  snapping?: Snapping;
51
51
  pointerDistance?: number;
52
52
  keyEvents?: TerraDrawPolygonModeKeyEvents | null;
53
+ pointerEvents?: PointerEvents;
53
54
  cursors?: Cursors;
54
55
  editable?: boolean;
55
56
  showCoordinatePoints?: boolean;
@@ -102,7 +103,7 @@ export declare class TerraDrawPolygonMode extends TerraDrawBaseDrawMode<PolygonS
102
103
  /** @internal */
103
104
  onDrag(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
104
105
  /** @internal */
105
- onDragEnd(_: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
106
+ onDragEnd(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
106
107
  /** @internal */
107
108
  cleanUp(): void;
108
109
  /** @internal */
@@ -117,7 +117,7 @@ export declare class TerraDrawSelectMode extends TerraDrawBaseSelectMode<Selecti
117
117
  /** @internal */
118
118
  onDrag(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
119
119
  /** @internal */
120
- onDragEnd(_: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
120
+ onDragEnd(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
121
121
  /** @internal */
122
122
  onMouseMove(event: TerraDrawMouseEvent): void;
123
123
  /** @internal */
@@ -13,7 +13,7 @@ export type StoreValidation = {
13
13
  id?: FeatureId;
14
14
  } & ReturnType<Validation>;
15
15
  type StoreChangeEvents = "delete" | "create" | "update" | "styling";
16
- export type StoreChangeHandler = (ids: FeatureId[], change: StoreChangeEvents) => void;
16
+ export type StoreChangeHandler<OnChangeContext> = (ids: FeatureId[], change: StoreChangeEvents, context?: OnChangeContext) => void;
17
17
  export type FeatureId = string | number;
18
18
  export type IdStrategy<Id extends FeatureId> = {
19
19
  isValidId: (id: Id) => boolean;
@@ -27,7 +27,7 @@ export declare const defaultIdStrategy: {
27
27
  getId: <FeatureId>() => FeatureId;
28
28
  isValidId: (id: FeatureId) => boolean;
29
29
  };
30
- export declare class GeoJSONStore<Id extends FeatureId = FeatureId> {
30
+ export declare class GeoJSONStore<OnChangeContext extends Record<string, JSON> | undefined, Id extends FeatureId = FeatureId> {
31
31
  constructor(config?: GeoJSONStoreConfig<Id>);
32
32
  idStrategy: IdStrategy<Id>;
33
33
  private tracked;
@@ -37,25 +37,25 @@ export declare class GeoJSONStore<Id extends FeatureId = FeatureId> {
37
37
  private clone;
38
38
  getId(): FeatureId;
39
39
  has(id: FeatureId): boolean;
40
- load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => StoreValidation, afterFeatureAdded?: (feature: GeoJSONStoreFeatures) => void): StoreValidation[];
40
+ load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => StoreValidation, afterFeatureAdded?: (feature: GeoJSONStoreFeatures) => void, context?: OnChangeContext): StoreValidation[];
41
41
  search(bbox: BBoxPolygon, filter?: (feature: GeoJSONStoreFeatures) => boolean): GeoJSONStoreFeatures[];
42
- registerOnChange(onChange: StoreChangeHandler): void;
42
+ registerOnChange(onChange: StoreChangeHandler<OnChangeContext | undefined>): void;
43
43
  getGeometryCopy<T extends GeoJSONStoreGeometries>(id: FeatureId): T;
44
44
  getPropertiesCopy(id: FeatureId): DefinedProperties;
45
45
  updateProperty(propertiesToUpdate: {
46
46
  id: FeatureId;
47
47
  property: string;
48
48
  value: JSON;
49
- }[]): void;
49
+ }[], context?: OnChangeContext): void;
50
50
  updateGeometry(geometriesToUpdate: {
51
51
  id: FeatureId;
52
52
  geometry: GeoJSONStoreGeometries;
53
- }[]): void;
53
+ }[], context?: OnChangeContext): void;
54
54
  create<Id extends FeatureId>(features: {
55
55
  geometry: GeoJSONStoreGeometries;
56
56
  properties?: JSONObject;
57
- }[]): Id[];
58
- delete(ids: FeatureId[]): void;
57
+ }[], context?: OnChangeContext): Id[];
58
+ delete(ids: FeatureId[], context?: OnChangeContext): void;
59
59
  copy(id: FeatureId): GeoJSONStoreFeatures;
60
60
  copyAll(): GeoJSONStoreFeatures[];
61
61
  copyAllWhere(equals: (properties: JSONObject) => boolean): GeoJSONStoreFeatures[];