terra-draw 1.0.0-beta.8 → 1.0.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 (153) hide show
  1. package/.versionrc.cjs +9 -0
  2. package/README.md +4 -47
  3. package/dist/common/adapter-listener.spec.d.ts +1 -0
  4. package/dist/{adapters/common → common}/base.adapter.d.ts +1 -1
  5. package/dist/common.d.ts +11 -6
  6. package/dist/extend.d.ts +4 -3
  7. package/dist/geometry/boolean/is-valid-coordinate.spec.d.ts +1 -0
  8. package/dist/geometry/boolean/point-in-polygon.spec.d.ts +1 -0
  9. package/dist/geometry/boolean/self-intersects.spec.d.ts +1 -0
  10. package/dist/geometry/calculate-relative-angle.d.ts +2 -10
  11. package/dist/geometry/calculate-relative-angle.spec.d.ts +1 -0
  12. package/dist/geometry/centroid.spec.d.ts +1 -0
  13. package/dist/geometry/clockwise.d.ts +2 -10
  14. package/dist/geometry/clockwise.spec.d.ts +1 -0
  15. package/dist/geometry/coordinates-identical.spec.d.ts +1 -0
  16. package/dist/geometry/determine-halfplane.d.ts +2 -10
  17. package/dist/geometry/determine-halfplane.spec.d.ts +1 -0
  18. package/dist/geometry/get-coordinates-as-points.spec.d.ts +1 -0
  19. package/dist/geometry/get-midpoint.spec.d.ts +1 -0
  20. package/dist/geometry/limit-decimal-precision.spec.d.ts +1 -0
  21. package/dist/geometry/measure/bearing.d.ts +2 -7
  22. package/dist/geometry/measure/bearing.spec.d.ts +1 -0
  23. package/dist/geometry/measure/desination.spec.d.ts +1 -0
  24. package/dist/geometry/measure/destination.d.ts +2 -7
  25. package/dist/geometry/measure/haversine-distance.spec.d.ts +1 -0
  26. package/dist/geometry/measure/pixel-distance-to-line.d.ts +2 -10
  27. package/dist/geometry/measure/pixel-distance-to-line.spec.d.ts +1 -0
  28. package/dist/geometry/measure/pixel-distance.d.ts +2 -7
  29. package/dist/geometry/measure/pixel-distance.spec.d.ts +1 -0
  30. package/dist/geometry/measure/rhumb-bearing.spec.d.ts +1 -0
  31. package/dist/geometry/measure/rhumb-destination.spec.d.ts +1 -0
  32. package/dist/geometry/measure/rhumb-distance.spec.d.ts +1 -0
  33. package/dist/geometry/point-on-line.d.ts +5 -0
  34. package/dist/geometry/point-on-line.spec.d.ts +1 -0
  35. package/dist/geometry/project/web-mercator.d.ts +2 -4
  36. package/dist/geometry/project/web-mercator.spec.d.ts +1 -0
  37. package/dist/geometry/shape/create-bbox.spec.d.ts +1 -0
  38. package/dist/geometry/shape/create-circle.spec.d.ts +1 -0
  39. package/dist/geometry/shape/great-circle-coordinates.spec.d.ts +1 -0
  40. package/dist/geometry/shape/web-mercator-distortion.spec.d.ts +1 -0
  41. package/dist/geometry/transform/rotate.spec.d.ts +1 -0
  42. package/dist/geometry/transform/scale.spec.d.ts +1 -0
  43. package/dist/geometry/web-mercator-centroid.d.ts +2 -4
  44. package/dist/geometry/web-mercator-centroid.spec.d.ts +1 -0
  45. package/dist/geometry/web-mercator-point-on-line.d.ts +11 -0
  46. package/dist/geometry/web-mercator-point-on-line.spec.d.ts +1 -0
  47. package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +2 -3
  48. package/dist/modes/angled-rectangle/angled-rectangle.mode.spec.d.ts +1 -0
  49. package/dist/modes/base.mode.d.ts +3 -1
  50. package/dist/modes/circle/circle.mode.d.ts +3 -2
  51. package/dist/modes/circle/circle.mode.spec.d.ts +1 -0
  52. package/dist/modes/click-bounding-box.behavior.spec.d.ts +1 -0
  53. package/dist/modes/coordinate-snapping.behavior.d.ts +16 -0
  54. package/dist/modes/coordinate-snapping.behavior.spec.d.ts +1 -0
  55. package/dist/modes/freehand/freehand.mode.d.ts +8 -2
  56. package/dist/modes/freehand/freehand.mode.spec.d.ts +1 -0
  57. package/dist/modes/insert-coordinates.behavior.spec.d.ts +1 -0
  58. package/dist/modes/{snapping.behavior.d.ts → line-snapping.behavior.d.ts} +1 -1
  59. package/dist/modes/line-snapping.behavior.spec.d.ts +1 -0
  60. package/dist/modes/linestring/linestring.mode.d.ts +16 -5
  61. package/dist/modes/linestring/linestring.mode.spec.d.ts +1 -0
  62. package/dist/modes/pixel-distance.behavior.spec.d.ts +1 -0
  63. package/dist/modes/point/point.mode.d.ts +2 -2
  64. package/dist/modes/point/point.mode.spec.d.ts +1 -0
  65. package/dist/modes/polygon/behaviors/closing-points.behavior.spec.d.ts +1 -0
  66. package/dist/modes/polygon/polygon.mode.d.ts +17 -4
  67. package/dist/modes/polygon/polygon.mode.spec.d.ts +1 -0
  68. package/dist/modes/rectangle/rectangle.mode.d.ts +2 -2
  69. package/dist/modes/rectangle/rectangle.mode.spec.d.ts +1 -0
  70. package/dist/modes/render/render.mode.d.ts +2 -1
  71. package/dist/modes/render/render.mode.spec.d.ts +1 -0
  72. package/dist/modes/sector/sector.mode.d.ts +2 -2
  73. package/dist/modes/sector/sector.mode.spec.d.ts +1 -0
  74. package/dist/modes/select/behaviors/drag-coordinate-resize.behavior.spec.d.ts +1 -0
  75. package/dist/modes/select/behaviors/drag-coordinate.behavior.spec.d.ts +1 -0
  76. package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +2 -2
  77. package/dist/modes/select/behaviors/drag-feature.behavior.spec.d.ts +1 -0
  78. package/dist/modes/select/behaviors/feature-at-pointer-event.behavior.spec.d.ts +1 -0
  79. package/dist/modes/select/behaviors/midpoint.behavior.spec.d.ts +1 -0
  80. package/dist/modes/select/behaviors/rotate-feature.behavior.spec.d.ts +1 -0
  81. package/dist/modes/select/behaviors/scale-feature.behavior.spec.d.ts +1 -0
  82. package/dist/modes/select/behaviors/selection-point.behavior.spec.d.ts +1 -0
  83. package/dist/modes/select/select.mode.spec.d.ts +1 -0
  84. package/dist/modes/sensor/sensor.mode.d.ts +2 -2
  85. package/dist/modes/sensor/sensor.mode.spec.d.ts +1 -0
  86. package/dist/modes/static/static.mode.spec.d.ts +1 -0
  87. package/dist/store/spatial-index/quickselect.spec.d.ts +1 -0
  88. package/dist/store/spatial-index/rbush.spec.d.ts +1 -0
  89. package/dist/store/spatial-index/spatial-index.spec.d.ts +1 -0
  90. package/dist/store/store-feature-validation.d.ts +8 -2
  91. package/dist/store/store-validation.spec.d.ts +1 -0
  92. package/dist/store/store.d.ts +5 -1
  93. package/dist/store/store.spec.d.ts +1 -0
  94. package/dist/terra-draw.cjs +1 -1
  95. package/dist/terra-draw.cjs.map +1 -1
  96. package/dist/terra-draw.d.ts +13 -14
  97. package/dist/terra-draw.extensions.spec.d.ts +28 -0
  98. package/dist/terra-draw.modern.js +1 -1
  99. package/dist/terra-draw.modern.js.map +1 -1
  100. package/dist/terra-draw.module.js +1 -1
  101. package/dist/terra-draw.module.js.map +1 -1
  102. package/dist/terra-draw.spec.d.ts +1 -0
  103. package/dist/terra-draw.umd.js +1 -1
  104. package/dist/terra-draw.umd.js.map +1 -1
  105. package/dist/test/create-store-features.d.ts +6 -0
  106. package/dist/test/jest.matchers.d.ts +1 -0
  107. package/dist/test/mock-behavior-config.d.ts +2 -0
  108. package/dist/test/mock-callbacks.d.ts +2 -0
  109. package/dist/test/mock-cursor-event.d.ts +6 -0
  110. package/dist/test/mock-features.d.ts +4 -0
  111. package/dist/test/mock-keyboard-event.d.ts +5 -0
  112. package/dist/test/mock-mode-config.d.ts +21 -0
  113. package/dist/test/mock-pointer-event.d.ts +1 -0
  114. package/dist/util/geom.spec.d.ts +1 -0
  115. package/dist/util/id.spec.d.ts +1 -0
  116. package/dist/util/styling.spec.d.ts +1 -0
  117. package/dist/validation-reasons.d.ts +13 -0
  118. package/dist/validations/common-validations.d.ts +2 -0
  119. package/dist/validations/linestring.validation.d.ts +4 -1
  120. package/dist/validations/linestring.validation.spec.d.ts +1 -0
  121. package/dist/validations/max-size.validation.d.ts +3 -1
  122. package/dist/validations/max-size.validation.spec.d.ts +1 -0
  123. package/dist/validations/min-size.validation.d.ts +3 -1
  124. package/dist/validations/min-size.validation.spec.d.ts +1 -0
  125. package/dist/validations/not-self-intersecting.validation.d.ts +4 -1
  126. package/dist/validations/not-self-intersecting.validation.spec.d.ts +1 -0
  127. package/dist/validations/point.validation.d.ts +4 -1
  128. package/dist/validations/point.validation.spec.d.ts +1 -0
  129. package/dist/validations/polygon.validation.d.ts +8 -2
  130. package/dist/validations/polygon.validation.spec.d.ts +1 -0
  131. package/jest.nocheck.config.ts +5 -14
  132. package/package.json +12 -137
  133. package/tsconfig.json +6 -25
  134. package/.devcontainer/Dockerfile +0 -8
  135. package/.devcontainer/devcontainer.json +0 -27
  136. package/.devcontainer/post-create.sh +0 -16
  137. package/LICENSE +0 -8
  138. package/dist/adapters/arcgis-maps-sdk.adapter.d.ts +0 -106
  139. package/dist/adapters/google-maps.adapter.d.ts +0 -90
  140. package/dist/adapters/leaflet.adapter.d.ts +0 -99
  141. package/dist/adapters/mapbox-gl.adapter.d.ts +0 -90
  142. package/dist/adapters/maplibre-gl.adapter.d.ts +0 -72
  143. package/dist/adapters/openlayers.adapter.d.ts +0 -121
  144. package/e2e/README.md +0 -29
  145. package/e2e/package-lock.json +0 -4274
  146. package/e2e/package.json +0 -26
  147. package/e2e/playwright.config.ts +0 -77
  148. package/e2e/public/favicon.ico +0 -0
  149. package/e2e/public/index.html +0 -55
  150. package/e2e/tests/leaflet.spec.ts +0 -1040
  151. package/e2e/tests/setup.ts +0 -208
  152. package/e2e/webpack.config.js +0 -36
  153. /package/dist/{adapters/common → common}/adapter-listener.d.ts +0 -0
package/.versionrc.cjs ADDED
@@ -0,0 +1,9 @@
1
+ const path = require("path");
2
+ const packageJsonPath = path.resolve(__dirname, `package.json`);
3
+ const packageName = require(packageJsonPath).name
4
+ console.log(`✔ Package: ${packageName}`)
5
+
6
+ const changelogPath = path.resolve(__dirname, "/CHANGELOG.md")
7
+ const releaseConfig = require('../../release')
8
+
9
+ module.exports = releaseConfig(packageName, packageJsonPath, changelogPath)
package/README.md CHANGED
@@ -1,50 +1,7 @@
1
- <picture>
2
- <source media="(prefers-color-scheme: dark)" srcset="./assets/logo-dark-mode.png">
3
- <source media="(prefers-color-scheme: light)" srcset="./assets/logo.png">
4
- <img alt="Terra Draw logo" src="./assets/logo.png" width="400px">
5
- </picture>
1
+ # Terra Draw
6
2
 
7
- <p></p>
3
+ This package is the core package for Terra Draw. You can read more context about what Terra Draw is in [the root level README](../../README.md) and more information on how to get started in the [GUIDES section of the Terra Draw monorepo](../../guides/1.GETTING_STARTED.md).
8
4
 
9
- ![Terra Draw CI Badge](https://github.com/JamesLMilner/terra-draw/actions/workflows/ci.yml/badge.svg)
10
- [![npm version](https://badge.fury.io/js/terra-draw.svg)](https://badge.fury.io/js/terra-draw)
5
+ ## License
11
6
 
12
- Frictionless map drawing across mapping libraries.
13
-
14
- Terra Draw centralizes map drawing logic and provides a host of out-of-the-box drawing modes that work across different JavaScript mapping libraries. It also allows you to bring your own modes!
15
-
16
- ![An example of drawing geodesic lines using Terra Draw with Leaflet](./assets/readme.gif)
17
-
18
-
19
- ### Library Support
20
-
21
- Terra Draw uses the concept of 'adapters' to allow it to work with a host of different mapping libraries. Currently supported are:
22
-
23
- - [Leaflet](https://leafletjs.com/) v1
24
- - [OpenLayers](https://openlayers.org/) v10
25
- - [Mapbox GL JS](https://www.mapbox.com/mapbox-gljs) v2
26
- - [MapLibre](https://maplibre.org/maplibre-gl-js/docs/) v2/v3
27
- - [Google Maps JS API](https://developers.google.com/maps/documentation/javascript/overview) v3
28
- - [ArcGIS JavaScript SDK](https://developers.arcgis.com/javascript/latest/) v4 (MapView)
29
-
30
- ### Getting Started
31
-
32
- Please see the [the getting started guide](./guides/1.GETTING_STARTED.md) - this provides a host of information on how to get up and running with Terra Draw.
33
-
34
- ### Development & Contributing
35
-
36
- * For development, please see the [the development documentation](./guides/7.DEVELOPMENT.md)
37
- * For guidance on contributing, please see the [the contributing documentation](./guides/7.DEVELOPMENT.md#contributing)
38
-
39
-
40
- ### Project Website
41
-
42
- You can check out the official Terra Draw website at [terradraw.io](https://www.terradraw.io). If you are interested in contributing to the website please see [this repository](https://www.github.com/JamesLMilner/terra-draw-website).
43
-
44
- ### Contact
45
-
46
- Email: [contact@terradraw.io](mailto:contact@terradraw.io)
47
-
48
- ### License
49
-
50
- MIT
7
+ [MIT](../../LICENSE)
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { Project, Unproject, TerraDrawCallbacks, TerraDrawChanges, TerraDrawMouseEvent, SetCursor, TerraDrawStylingFunction, GetLngLatFromEvent, TerraDrawAdapter } from "../../common";
1
+ import { Project, Unproject, TerraDrawCallbacks, TerraDrawChanges, TerraDrawMouseEvent, SetCursor, TerraDrawStylingFunction, GetLngLatFromEvent, TerraDrawAdapter } from "../common";
2
2
  import { AdapterListener } from "./adapter-listener";
3
3
  type BasePointerListener = (event: PointerEvent) => void;
4
4
  type BaseKeyboardListener = (event: KeyboardEvent) => void;
package/dist/common.d.ts CHANGED
@@ -15,6 +15,10 @@ export interface TerraDrawAdapterStyling {
15
15
  lineStringColor: HexColor;
16
16
  zIndex: number;
17
17
  }
18
+ export type CartesianPoint = {
19
+ x: number;
20
+ y: number;
21
+ };
18
22
  export interface TerraDrawMouseEvent {
19
23
  lng: number;
20
24
  lat: number;
@@ -30,10 +34,7 @@ export interface TerraDrawKeyboardEvent {
30
34
  }
31
35
  export type Cursor = Parameters<SetCursor>[0];
32
36
  export type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer" | "wait" | "move") => void;
33
- export type Project = (lng: number, lat: number) => {
34
- x: number;
35
- y: number;
36
- };
37
+ export type Project = (lng: number, lat: number) => CartesianPoint;
37
38
  export type Unproject = (x: number, y: number) => {
38
39
  lat: number;
39
40
  lng: number;
@@ -68,7 +69,10 @@ export declare enum UpdateTypes {
68
69
  type ValidationContext = Pick<TerraDrawModeRegisterConfig, "project" | "unproject" | "coordinatePrecision"> & {
69
70
  updateType: UpdateTypes;
70
71
  };
71
- export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) => boolean;
72
+ export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) => {
73
+ valid: boolean;
74
+ reason?: string;
75
+ };
72
76
  export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped";
73
77
  export interface TerraDrawCallbacks {
74
78
  getState: () => TerraDrawModeState;
@@ -109,7 +113,8 @@ export declare const SELECT_PROPERTIES: {
109
113
  readonly MID_POINT: "midPoint";
110
114
  readonly SELECTION_POINT: "selectionPoint";
111
115
  };
112
- export declare const POLYGON_PROPERTIES: {
116
+ export declare const COMMON_PROPERTIES: {
113
117
  CLOSING_POINT: string;
118
+ SNAPPING_POINT: string;
114
119
  };
115
120
  export {};
package/dist/extend.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { TerraDrawBaseAdapter, BaseAdapterConfig } from "./adapters/common/base.adapter";
2
- import { HexColorStyling, NumericStyling } from "./common";
1
+ import { TerraDrawBaseAdapter, BaseAdapterConfig } from "./common/base.adapter";
2
+ import { HexColorStyling, NumericStyling, SELECT_PROPERTIES, TerraDrawCallbacks } from "./common";
3
3
  import { BaseModeOptions, TerraDrawBaseDrawMode } from "./modes/base.mode";
4
- export { TerraDrawBaseDrawMode, TerraDrawBaseAdapter, BaseAdapterConfig, NumericStyling, HexColorStyling, BaseModeOptions, };
4
+ import { FeatureId, GeoJSONStore } from "./store/store";
5
+ export { GeoJSONStore, TerraDrawBaseDrawMode, TerraDrawBaseAdapter, BaseAdapterConfig, NumericStyling, HexColorStyling, BaseModeOptions, TerraDrawCallbacks, FeatureId, SELECT_PROPERTIES, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ import { CartesianPoint } from "../common";
1
2
  /**
2
3
  * Calculate the relative angle between two lines
3
4
  * @param A The first point of the first line
@@ -5,13 +6,4 @@
5
6
  * @param C The second point of the second line
6
7
  * @returns The relative angle between the two lines
7
8
  */
8
- export declare function calculateRelativeAngle(A: {
9
- x: number;
10
- y: number;
11
- }, B: {
12
- x: number;
13
- y: number;
14
- }, C: {
15
- x: number;
16
- y: number;
17
- }): number;
9
+ export declare function calculateRelativeAngle(A: CartesianPoint, B: CartesianPoint, C: CartesianPoint): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,2 @@
1
- export declare function isClockwiseWebMercator(center: {
2
- x: number;
3
- y: number;
4
- }, secondCoord: {
5
- x: number;
6
- y: number;
7
- }, thirdCoord: {
8
- x: number;
9
- y: number;
10
- }): boolean;
1
+ import { CartesianPoint } from "../common";
2
+ export declare function isClockwiseWebMercator(center: CartesianPoint, secondCoord: CartesianPoint, thirdCoord: CartesianPoint): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,2 @@
1
- export declare function determineHalfPlane(point: {
2
- x: number;
3
- y: number;
4
- }, lineStart: {
5
- x: number;
6
- y: number;
7
- }, lineEnd: {
8
- x: number;
9
- y: number;
10
- }): string;
1
+ import { CartesianPoint } from "../common";
2
+ export declare function determineHalfPlane(point: CartesianPoint, lineStart: CartesianPoint, lineEnd: CartesianPoint): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,5 @@
1
1
  import { Position } from "geojson";
2
+ import { CartesianPoint } from "../../common";
2
3
  export declare function bearing(start: Position, end: Position): number;
3
- export declare function webMercatorBearing({ x: x1, y: y1 }: {
4
- x: number;
5
- y: number;
6
- }, { x: x2, y: y2 }: {
7
- x: number;
8
- y: number;
9
- }): number;
4
+ export declare function webMercatorBearing({ x: x1, y: y1 }: CartesianPoint, { x: x2, y: y2 }: CartesianPoint): number;
10
5
  export declare function normalizeBearing(bearing: number): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,4 @@
1
1
  import { Position } from "geojson";
2
+ import { CartesianPoint } from "../../common";
2
3
  export declare function destination(origin: Position, distance: number, bearing: number): Position;
3
- export declare function webMercatorDestination({ x, y }: {
4
- x: number;
5
- y: number;
6
- }, distance: number, bearing: number): {
7
- x: number;
8
- y: number;
9
- };
4
+ export declare function webMercatorDestination({ x, y }: CartesianPoint, distance: number, bearing: number): CartesianPoint;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,2 @@
1
- export declare const pixelDistanceToLine: (point: {
2
- x: number;
3
- y: number;
4
- }, linePointOne: {
5
- x: number;
6
- y: number;
7
- }, linePointTwo: {
8
- x: number;
9
- y: number;
10
- }) => number;
1
+ import { CartesianPoint } from "../../common";
2
+ export declare const pixelDistanceToLine: (point: CartesianPoint, linePointOne: CartesianPoint, linePointTwo: CartesianPoint) => number;
@@ -1,7 +1,2 @@
1
- export declare const cartesianDistance: (pointOne: {
2
- x: number;
3
- y: number;
4
- }, pointTwo: {
5
- x: number;
6
- y: number;
7
- }) => number;
1
+ import { CartesianPoint } from "../../common";
2
+ export declare const cartesianDistance: (pointOne: CartesianPoint, pointTwo: CartesianPoint) => number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { Position } from "geojson";
2
+ export declare function nearestPointOnLine(inputCoordinate: Position, lines: [Position, Position][]): {
3
+ coordinate: Position;
4
+ distance: number;
5
+ } | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,11 @@
1
+ import { CartesianPoint } from "../../common";
1
2
  /**
2
3
  * Convert longitude and latitude to web mercator x and y
3
4
  * @param lng
4
5
  * @param lat
5
6
  * @returns - web mercator x and y
6
7
  */
7
- export declare const lngLatToWebMercatorXY: (lng: number, lat: number) => {
8
- x: number;
9
- y: number;
10
- };
8
+ export declare const lngLatToWebMercatorXY: (lng: number, lat: number) => CartesianPoint;
11
9
  /**
12
10
  * Convert web mercator x and y to longitude and latitude
13
11
  * @param x - web mercator x
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,9 @@
1
1
  import { Feature, LineString, Polygon } from "geojson";
2
+ import { CartesianPoint } from "../common";
2
3
  /**
3
4
  * Calculates the centroid of a GeoJSON Polygon or LineString in Web Mercator
4
5
 
5
6
  * @param {Feature<Polygon | LineString>} feature - The GeoJSON Feature containing either a Polygon or LineString
6
7
  * @returns {{ x: number, y: number }} The centroid of the polygon or line string in Web Mercator coordinates.
7
8
  */
8
- export declare function webMercatorCentroid(feature: Feature<Polygon | LineString>): {
9
- x: number;
10
- y: number;
11
- };
9
+ export declare function webMercatorCentroid(feature: Feature<Polygon | LineString>): CartesianPoint;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Position } from "geojson";
2
+ /**
3
+ * Takes two points and finds the closest point on the line between them to a third point.
4
+ * @param lines
5
+ * @param inputCoordinate
6
+ * @returns
7
+ */
8
+ export declare function webMercatorNearestPointOnLine(inputCoordinate: Position, lines: [Position, Position][]): {
9
+ coordinate: Position;
10
+ distance: number;
11
+ } | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
2
2
  import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling } from "../base.mode";
3
- import { GeoJSONStoreFeatures } from "../../store/store";
3
+ import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
4
4
  type TerraDrawPolygonModeKeyEvents = {
5
5
  cancel?: KeyboardEvent["key"] | null;
6
6
  finish?: KeyboardEvent["key"] | null;
@@ -16,7 +16,6 @@ interface Cursors {
16
16
  close?: Cursor;
17
17
  }
18
18
  interface TerraDrawPolygonModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
19
- snapping?: boolean;
20
19
  pointerDistance?: number;
21
20
  keyEvents?: TerraDrawPolygonModeKeyEvents | null;
22
21
  cursors?: Cursors;
@@ -53,6 +52,6 @@ export declare class TerraDrawAngledRectangleMode extends TerraDrawBaseDrawMode<
53
52
  cleanUp(): void;
54
53
  /** @internal */
55
54
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
56
- validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
55
+ validateFeature(feature: unknown): StoreValidation;
57
56
  }
58
57
  export {};
@@ -40,7 +40,9 @@ export declare abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
40
40
  protected setStarted(): void;
41
41
  protected setStopped(): void;
42
42
  register(config: TerraDrawModeRegisterConfig): void;
43
- validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
43
+ validateFeature(feature: unknown): ReturnType<Validation>;
44
+ private performFeatureValidation;
45
+ protected validateModeFeature(feature: unknown, modeValidationFn: (feature: GeoJSONStoreFeatures) => ReturnType<Validation>): ReturnType<Validation>;
44
46
  abstract start(): void;
45
47
  abstract stop(): void;
46
48
  abstract cleanUp(): void;
@@ -1,5 +1,5 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor, Projection } from "../../common";
2
- import { GeoJSONStoreFeatures } from "../../store/store";
2
+ import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
3
3
  import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
4
4
  type TerraDrawCircleModeKeyEvents = {
5
5
  cancel: KeyboardEvent["key"] | null;
@@ -28,6 +28,7 @@ export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePol
28
28
  private keyEvents;
29
29
  private cursors;
30
30
  private startingRadiusKilometers;
31
+ private cursorMovedAfterInitialCursorDown;
31
32
  /**
32
33
  * Create a new circle mode instance
33
34
  * @param options - Options to customize the behavior of the circle mode
@@ -60,7 +61,7 @@ export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePol
60
61
  cleanUp(): void;
61
62
  /** @internal */
62
63
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
63
- validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
64
+ validateFeature(feature: unknown): StoreValidation;
64
65
  private updateCircle;
65
66
  }
66
67
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { BehaviorConfig, TerraDrawModeBehavior } from "./base.behavior";
2
+ import { TerraDrawMouseEvent } from "../common";
3
+ import { Position } from "geojson";
4
+ import { ClickBoundingBoxBehavior } from "./click-bounding-box.behavior";
5
+ import { FeatureId } from "../store/store";
6
+ import { PixelDistanceBehavior } from "./pixel-distance.behavior";
7
+ export declare class CoordinateSnappingBehavior extends TerraDrawModeBehavior {
8
+ readonly config: BehaviorConfig;
9
+ private readonly pixelDistance;
10
+ private readonly clickBoundingBox;
11
+ constructor(config: BehaviorConfig, pixelDistance: PixelDistanceBehavior, clickBoundingBox: ClickBoundingBoxBehavior);
12
+ /** Returns the nearest snappable coordinate - on first click there is no currentId so no need to provide */
13
+ getSnappableCoordinateFirstClick: (event: TerraDrawMouseEvent) => Position | undefined;
14
+ getSnappableCoordinate: (event: TerraDrawMouseEvent, currentFeatureId: FeatureId) => Position | undefined;
15
+ private getSnappable;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
2
2
  import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
3
- import { GeoJSONStoreFeatures } from "../../store/store";
3
+ import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
4
4
  type TerraDrawFreehandModeKeyEvents = {
5
5
  cancel: KeyboardEvent["key"] | null;
6
6
  finish: KeyboardEvent["key"] | null;
@@ -22,6 +22,8 @@ interface Cursors {
22
22
  interface TerraDrawFreehandModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
23
23
  minDistance?: number;
24
24
  preventPointsNearClose?: boolean;
25
+ autoClose?: boolean;
26
+ autoCloseTimeout?: number;
25
27
  keyEvents?: TerraDrawFreehandModeKeyEvents | null;
26
28
  cursors?: Cursors;
27
29
  }
@@ -34,6 +36,10 @@ export declare class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<Freehan
34
36
  private keyEvents;
35
37
  private cursors;
36
38
  private preventPointsNearClose;
39
+ private autoClose;
40
+ private autoCloseTimeout;
41
+ private hasLeftStartingPoint;
42
+ private preventNewFeature;
37
43
  constructor(options?: TerraDrawFreehandModeOptions<FreehandPolygonStyling>);
38
44
  private close;
39
45
  /** @internal */
@@ -58,6 +64,6 @@ export declare class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<Freehan
58
64
  cleanUp(): void;
59
65
  /** @internal */
60
66
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
61
- validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
67
+ validateFeature(feature: unknown): StoreValidation;
62
68
  }
63
69
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,7 @@ import { Position } from "geojson";
4
4
  import { ClickBoundingBoxBehavior } from "./click-bounding-box.behavior";
5
5
  import { FeatureId } from "../store/store";
6
6
  import { PixelDistanceBehavior } from "./pixel-distance.behavior";
7
- export declare class SnappingBehavior extends TerraDrawModeBehavior {
7
+ export declare class LineSnappingBehavior extends TerraDrawModeBehavior {
8
8
  readonly config: BehaviorConfig;
9
9
  private readonly pixelDistance;
10
10
  private readonly clickBoundingBox;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,8 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
2
+ import { Position } from "geojson";
2
3
  import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
3
4
  import { BehaviorConfig } from "../base.behavior";
4
- import { GeoJSONStoreFeatures } from "../../store/store";
5
+ import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
5
6
  type TerraDrawLineStringModeKeyEvents = {
6
7
  cancel: KeyboardEvent["key"] | null;
7
8
  finish: KeyboardEvent["key"] | null;
@@ -13,6 +14,10 @@ type LineStringStyling = {
13
14
  closingPointWidth: NumericStyling;
14
15
  closingPointOutlineColor: HexColorStyling;
15
16
  closingPointOutlineWidth: NumericStyling;
17
+ snappingPointColor: HexColorStyling;
18
+ snappingPointWidth: NumericStyling;
19
+ snappingPointOutlineColor: HexColorStyling;
20
+ snappingPointOutlineWidth: NumericStyling;
16
21
  };
17
22
  interface Cursors {
18
23
  start?: Cursor;
@@ -22,8 +27,12 @@ interface InertCoordinates {
22
27
  strategy: "amount";
23
28
  value: number;
24
29
  }
30
+ interface Snapping {
31
+ toCoordinate?: boolean;
32
+ toCustom?: (event: TerraDrawMouseEvent) => Position | undefined;
33
+ }
25
34
  interface TerraDrawLineStringModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
26
- snapping?: boolean;
35
+ snapping?: Snapping;
27
36
  pointerDistance?: number;
28
37
  keyEvents?: TerraDrawLineStringModeKeyEvents | null;
29
38
  cursors?: Cursors;
@@ -35,12 +44,13 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
35
44
  private currentId;
36
45
  private closingPointId;
37
46
  private keyEvents;
38
- private snappingEnabled;
47
+ private snapping;
39
48
  private cursors;
40
49
  private mouseMove;
41
50
  private insertCoordinates;
42
51
  private lastCommitedCoordinates;
43
- private snapping;
52
+ private snappedPointId;
53
+ private coordinateSnapping;
44
54
  private insertPoint;
45
55
  constructor(options?: TerraDrawLineStringModeOptions<LineStringStyling>);
46
56
  private close;
@@ -73,6 +83,7 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
73
83
  cleanUp(): void;
74
84
  /** @internal */
75
85
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
76
- validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
86
+ validateFeature(feature: unknown): StoreValidation;
87
+ private snapCoordinate;
77
88
  }
78
89
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, NumericStyling, HexColorStyling, Cursor } from "../../common";
2
- import { GeoJSONStoreFeatures } from "../../store/store";
2
+ import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
3
3
  import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
4
4
  type PointModeStyling = {
5
5
  pointWidth: NumericStyling;
@@ -39,6 +39,6 @@ export declare class TerraDrawPointMode extends TerraDrawBaseDrawMode<PointModeS
39
39
  onDragEnd(): void;
40
40
  /** @internal */
41
41
  styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
42
- validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
42
+ validateFeature(feature: unknown): StoreValidation;
43
43
  }
44
44
  export {};
@@ -0,0 +1 @@
1
+ export {};