terra-draw 1.0.0 → 1.2.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.
Files changed (37) hide show
  1. package/README.md +33 -4
  2. package/dist/common.d.ts +1 -0
  3. package/dist/geometry/boolean/right-hand-rule.d.ts +7 -0
  4. package/dist/geometry/boolean/right-hand-rule.spec.d.ts +1 -0
  5. package/dist/geometry/ensure-right-hand-rule.d.ts +2 -0
  6. package/dist/geometry/ensure-right-hand-rule.spec.d.ts +1 -0
  7. package/dist/geometry/point-on-line.d.ts +1 -0
  8. package/dist/geometry/web-mercator-point-on-line.d.ts +1 -0
  9. package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +2 -1
  10. package/dist/modes/base.mode.d.ts +10 -9
  11. package/dist/modes/circle/circle.mode.d.ts +2 -1
  12. package/dist/modes/coordinate-snapping.behavior.d.ts +7 -2
  13. package/dist/modes/freehand/freehand.mode.d.ts +2 -1
  14. package/dist/modes/line-snapping.behavior.d.ts +7 -2
  15. package/dist/modes/linestring/linestring.mode.d.ts +19 -4
  16. package/dist/modes/point/point.mode.d.ts +21 -5
  17. package/dist/modes/polygon/polygon.mode.d.ts +23 -7
  18. package/dist/modes/rectangle/rectangle.mode.d.ts +2 -1
  19. package/dist/modes/render/render.mode.d.ts +2 -1
  20. package/dist/modes/sector/sector.mode.d.ts +2 -1
  21. package/dist/modes/select/select.mode.d.ts +4 -3
  22. package/dist/modes/sensor/sensor.mode.d.ts +2 -1
  23. package/dist/modes/static/static.mode.d.ts +1 -1
  24. package/dist/store/store.d.ts +1 -0
  25. package/dist/terra-draw.cjs +1 -1
  26. package/dist/terra-draw.cjs.map +1 -1
  27. package/dist/terra-draw.d.ts +25 -40
  28. package/dist/terra-draw.modern.js +1 -1
  29. package/dist/terra-draw.modern.js.map +1 -1
  30. package/dist/terra-draw.module.js +1 -1
  31. package/dist/terra-draw.module.js.map +1 -1
  32. package/dist/terra-draw.umd.js +1 -1
  33. package/dist/terra-draw.umd.js.map +1 -1
  34. package/package.json +3 -3
  35. package/dist/test/jest.matchers.d.ts +0 -1
  36. package/dist/test/mock-callbacks.d.ts +0 -2
  37. package/dist/test/mock-pointer-event.d.ts +0 -1
@@ -21,6 +21,7 @@ import { TerraDrawSectorMode } from "./modes/sector/sector.mode";
21
21
  import { TerraDrawSensorMode } from "./modes/sensor/sensor.mode";
22
22
  import * as TerraDrawExtend from "./extend";
23
23
  import { ValidationReasons } from "./validation-reasons";
24
+ type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any[]) => infer R ? R : never;
24
25
  type FinishListener = (id: FeatureId, context: OnFinishContext) => void;
25
26
  type ChangeListener = (ids: FeatureId[], type: string) => void;
26
27
  type SelectListener = (id: FeatureId) => void;
@@ -52,28 +53,41 @@ declare class TerraDraw {
52
53
  private featuresAtLocation;
53
54
  private getSelectMode;
54
55
  /**
56
+ * @deprecated This method is scheduled for removal in the next major version. Instead use the 'updateModeOptions' method passing the
57
+ * styles property in the options object, and this will dynamically update the styles for the mode.
58
+ *
55
59
  * Allows the setting of a style for a given mode
56
60
  *
57
61
  * @param mode - The mode you wish to set a style for
58
62
  * @param styles - The styles you wish to set for the mode - this is
59
63
  * the same as the initialisation style schema
60
- *
61
- * @beta
62
64
  */
63
65
  setModeStyles<Styling extends Record<string, number | HexColor>>(mode: string, styles: Styling): void;
66
+ /**
67
+ * Allow updating of the current options passed to the mode dynamically
68
+ * after the mode has been started. You can also use this method to update styles
69
+ * as these are passed from the options object.
70
+ * @param mode - the mode name you wish to update (the mode name is the public 'mode' property of the mode class)
71
+ * @param options - the options object - this allows _partial_ updating of the modes options (i.e. you do not need to pass the whole options object)
72
+ */
73
+ updateModeOptions<Mode extends {
74
+ new (...args: any[]): any;
75
+ }>(mode: InstanceType<Mode>["mode"], options: ConstructorParameters<Mode>[0]): void;
64
76
  /**
65
77
  * Allows the user to get a snapshot (copy) of all given features
66
78
  *
67
79
  * @returns An array of all given Feature Geometries in the instances store
68
- *
69
- * @beta
70
80
  */
71
81
  getSnapshot(): GeoJSONStoreFeatures[];
82
+ /**
83
+ * Allows the user to get a snapshot (copy) of a given feature by id
84
+ *
85
+ * @returns A copy of the feature geometry in the instances store
86
+ */
87
+ getSnapshotFeature(id: FeatureId): GeoJSONStoreFeatures | undefined;
72
88
  /**
73
89
  * Removes all data from the current store and removes any rendered layers
74
90
  * via the registering the adapter.
75
- *
76
- * @beta
77
91
  */
78
92
  clear(): void;
79
93
  /**
@@ -83,37 +97,27 @@ declare class TerraDraw {
83
97
  *
84
98
  * @return true or false depending on if the instance is stopped or started
85
99
  * @readonly
86
- * @beta
87
100
  */
88
101
  get enabled(): boolean;
89
102
  /**
90
103
  * enabled is a read only property and will throw and error if you try and set it.
91
- *
92
- * @beta
93
104
  */
94
105
  set enabled(_: boolean);
95
106
  /**
96
107
  * A method for getting the current mode name
97
- *
98
108
  * @return the current mode name
99
- *
100
- * @beta
101
109
  */
102
110
  getMode(): string;
103
111
  /**
104
112
  * A method for setting the current mode by name. Under the hood this will stop
105
113
  * the previous mode and start the new one.
106
114
  * @param mode - The mode name you wish to start
107
- *
108
- * @beta
109
115
  */
110
116
  setMode(mode: string): void;
111
117
  /**
112
118
  * A method for removing features to the store
113
119
  * @param ids
114
120
  * @returns
115
- *
116
- * @beta
117
121
  */
118
122
  removeFeatures(ids: FeatureId[]): void;
119
123
  /**
@@ -121,7 +125,6 @@ declare class TerraDraw {
121
125
  * If not select mode is provided in the instance, an error will be thrown. If the instance is not currently
122
126
  * in the select mode, it will switch to it.
123
127
  * @param id - the id of the feature to select
124
- * @beta
125
128
  */
126
129
  selectFeature(id: FeatureId): void;
127
130
  /**
@@ -129,7 +132,6 @@ declare class TerraDraw {
129
132
  * If not select mode is provided in the instance, an error will be thrown. If the instance is not currently
130
133
  * in the select mode, it will switch to it.
131
134
  * @param id - the id of the feature to deselect
132
- * @beta
133
135
  */
134
136
  deselectFeature(id: FeatureId): void;
135
137
  /**
@@ -138,14 +140,11 @@ declare class TerraDraw {
138
140
  * outside of the Terra Draw instance but want to add them in to the store.
139
141
  * @returns a id, either number of string based on whatever the configured idStrategy is
140
142
  *
141
- * @beta
142
143
  */
143
144
  getFeatureId(): FeatureId;
144
145
  /**
145
146
  * Returns true or false depending on if the Terra Draw instance has a feature with a given id
146
147
  * @returns a boolean determining if the instance has a feature with the given id
147
- *
148
- * @beta
149
148
  */
150
149
  hasFeature(id: FeatureId): boolean;
151
150
  /**
@@ -154,23 +153,17 @@ declare class TerraDraw {
154
153
  * in the instance.
155
154
  * @param features - an array of GeoJSON features
156
155
  * @returns an array of validation results
157
- *
158
- * @beta
159
156
  */
160
157
  addFeatures(features: GeoJSONStoreFeatures[]): StoreValidation[];
161
158
  /**
162
159
  * A method starting Terra Draw. It put the instance into a started state, and
163
160
  * in registers the passed adapter giving it all the callbacks required to operate.
164
- *
165
- * @beta
166
161
  */
167
162
  start(): void;
168
163
  /**
169
164
  * Gets the features at a given longitude and latitude.
170
165
  * Will return point and linestrings that are a given pixel distance
171
166
  * away from the lng/lat and any polygons which contain it.
172
- *
173
- * @beta
174
167
  */
175
168
  getFeaturesAtLngLat(lngLat: {
176
169
  lng: number;
@@ -180,21 +173,16 @@ declare class TerraDraw {
180
173
  ignoreSelectFeatures: boolean;
181
174
  }): GeoJSONStoreFeatures[];
182
175
  /**
183
- * Takes a given pointer event and
184
- * Will return point and linestrings that are a given pixel distance
185
- * away from the lng/lat and any polygons which contain it.
186
- *
187
- * @beta
176
+ * Takes a given pointer event and will return point and linestrings that are
177
+ * a given pixel distance away from the longitude/latitude, and any polygons which contain it.
188
178
  */
189
179
  getFeaturesAtPointerEvent(event: PointerEvent | MouseEvent, options?: {
190
- pointerDistance: number;
191
- ignoreSelectFeatures: boolean;
180
+ pointerDistance?: number;
181
+ ignoreSelectFeatures?: boolean;
192
182
  }): GeoJSONStoreFeatures[];
193
183
  /**
194
184
  * A method for stopping Terra Draw. Will clear the store, deregister the adapter and
195
185
  * remove any rendered layers in the process.
196
- *
197
- * @beta
198
186
  */
199
187
  stop(): void;
200
188
  /**
@@ -203,7 +191,6 @@ declare class TerraDraw {
203
191
  * @param event - The name of the event you wish to listen for
204
192
  * @param callback - The callback with you wish to be called when this event occurs
205
193
  *
206
- * @beta
207
194
  */
208
195
  on<T extends TerraDrawEvents>(event: T, callback: TerraDrawEventListeners[T]): void;
209
196
  /**
@@ -212,9 +199,7 @@ declare class TerraDraw {
212
199
  * @param event - The name of the event you wish to unregister
213
200
  * @param callback - The callback you originally provided to the 'on' method
214
201
  *
215
- * @beta
216
202
  */
217
203
  off<T extends TerraDrawEvents>(event: TerraDrawEvents, callback: TerraDrawEventListeners[T]): void;
218
204
  }
219
- declare const HELLO = "HELLO";
220
- export { TerraDraw, HELLO, TerraDrawSelectMode, TerraDrawPointMode, TerraDrawLineStringMode, TerraDrawPolygonMode, TerraDrawCircleMode, TerraDrawFreehandMode, TerraDrawRenderMode, TerraDrawRectangleMode, TerraDrawAngledRectangleMode, TerraDrawSectorMode, TerraDrawSensorMode, TerraDrawExtend, BehaviorConfig, GeoJSONStoreFeatures, GeoJSONStoreGeometries, HexColor, TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, TerraDrawChanges, TerraDrawStylingFunction, Project, Unproject, SetCursor, GetLngLatFromEvent, ValidateMinAreaSquareMeters, ValidateMaxAreaSquareMeters, ValidateNotSelfIntersecting, ValidationReasons, };
205
+ export { TerraDraw, TerraDrawSelectMode, TerraDrawPointMode, TerraDrawLineStringMode, TerraDrawPolygonMode, TerraDrawCircleMode, TerraDrawFreehandMode, TerraDrawRenderMode, TerraDrawRectangleMode, TerraDrawAngledRectangleMode, TerraDrawSectorMode, TerraDrawSensorMode, TerraDrawExtend, BehaviorConfig, GeoJSONStoreFeatures, GeoJSONStoreGeometries, HexColor, TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, TerraDrawChanges, TerraDrawStylingFunction, Project, Unproject, SetCursor, GetLngLatFromEvent, ValidateMinAreaSquareMeters, ValidateMaxAreaSquareMeters, ValidateNotSelfIntersecting, ValidationReasons, };