terra-draw 1.0.0-beta.9 → 1.1.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 (133) hide show
  1. package/.versionrc.cjs +9 -0
  2. package/README.md +12 -26
  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 +8 -5
  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 +6 -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 +12 -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 +0 -1
  48. package/dist/modes/angled-rectangle/angled-rectangle.mode.spec.d.ts +1 -0
  49. package/dist/modes/circle/circle.mode.spec.d.ts +1 -0
  50. package/dist/modes/click-bounding-box.behavior.spec.d.ts +1 -0
  51. package/dist/modes/coordinate-snapping.behavior.d.ts +21 -0
  52. package/dist/modes/coordinate-snapping.behavior.spec.d.ts +1 -0
  53. package/dist/modes/freehand/freehand.mode.spec.d.ts +1 -0
  54. package/dist/modes/insert-coordinates.behavior.spec.d.ts +1 -0
  55. package/dist/modes/{snapping.behavior.d.ts → line-snapping.behavior.d.ts} +8 -3
  56. package/dist/modes/line-snapping.behavior.spec.d.ts +1 -0
  57. package/dist/modes/linestring/linestring.mode.d.ts +14 -3
  58. package/dist/modes/linestring/linestring.mode.spec.d.ts +1 -0
  59. package/dist/modes/pixel-distance.behavior.spec.d.ts +1 -0
  60. package/dist/modes/point/point.mode.d.ts +16 -4
  61. package/dist/modes/point/point.mode.spec.d.ts +1 -0
  62. package/dist/modes/polygon/behaviors/closing-points.behavior.spec.d.ts +1 -0
  63. package/dist/modes/polygon/polygon.mode.d.ts +32 -6
  64. package/dist/modes/polygon/polygon.mode.spec.d.ts +1 -0
  65. package/dist/modes/rectangle/rectangle.mode.spec.d.ts +1 -0
  66. package/dist/modes/render/render.mode.spec.d.ts +1 -0
  67. package/dist/modes/sector/sector.mode.spec.d.ts +1 -0
  68. package/dist/modes/select/behaviors/drag-coordinate-resize.behavior.spec.d.ts +1 -0
  69. package/dist/modes/select/behaviors/drag-coordinate.behavior.spec.d.ts +1 -0
  70. package/dist/modes/select/behaviors/drag-feature.behavior.spec.d.ts +1 -0
  71. package/dist/modes/select/behaviors/feature-at-pointer-event.behavior.spec.d.ts +1 -0
  72. package/dist/modes/select/behaviors/midpoint.behavior.spec.d.ts +1 -0
  73. package/dist/modes/select/behaviors/rotate-feature.behavior.spec.d.ts +1 -0
  74. package/dist/modes/select/behaviors/scale-feature.behavior.spec.d.ts +1 -0
  75. package/dist/modes/select/behaviors/selection-point.behavior.spec.d.ts +1 -0
  76. package/dist/modes/select/select.mode.spec.d.ts +1 -0
  77. package/dist/modes/sensor/sensor.mode.spec.d.ts +1 -0
  78. package/dist/modes/static/static.mode.spec.d.ts +1 -0
  79. package/dist/store/spatial-index/quickselect.spec.d.ts +1 -0
  80. package/dist/store/spatial-index/rbush.spec.d.ts +1 -0
  81. package/dist/store/spatial-index/spatial-index.spec.d.ts +1 -0
  82. package/dist/store/store-validation.spec.d.ts +1 -0
  83. package/dist/store/store.spec.d.ts +1 -0
  84. package/dist/terra-draw.cjs +1 -1
  85. package/dist/terra-draw.cjs.map +1 -1
  86. package/dist/terra-draw.d.ts +9 -46
  87. package/dist/terra-draw.extensions.spec.d.ts +28 -0
  88. package/dist/terra-draw.modern.js +1 -1
  89. package/dist/terra-draw.modern.js.map +1 -1
  90. package/dist/terra-draw.module.js +1 -1
  91. package/dist/terra-draw.module.js.map +1 -1
  92. package/dist/terra-draw.spec.d.ts +1 -0
  93. package/dist/terra-draw.umd.js +1 -1
  94. package/dist/terra-draw.umd.js.map +1 -1
  95. package/dist/test/create-store-features.d.ts +6 -0
  96. package/dist/test/mock-behavior-config.d.ts +2 -0
  97. package/dist/test/mock-cursor-event.d.ts +6 -0
  98. package/dist/test/mock-features.d.ts +4 -0
  99. package/dist/test/mock-keyboard-event.d.ts +5 -0
  100. package/dist/test/mock-mode-config.d.ts +21 -0
  101. package/dist/util/geom.spec.d.ts +1 -0
  102. package/dist/util/id.spec.d.ts +1 -0
  103. package/dist/util/styling.spec.d.ts +1 -0
  104. package/dist/validations/linestring.validation.spec.d.ts +1 -0
  105. package/dist/validations/max-size.validation.spec.d.ts +1 -0
  106. package/dist/validations/min-size.validation.spec.d.ts +1 -0
  107. package/dist/validations/not-self-intersecting.validation.spec.d.ts +1 -0
  108. package/dist/validations/point.validation.spec.d.ts +1 -0
  109. package/dist/validations/polygon.validation.spec.d.ts +1 -0
  110. package/jest.nocheck.config.ts +5 -14
  111. package/package.json +8 -119
  112. package/tsconfig.json +6 -25
  113. package/.devcontainer/Dockerfile +0 -8
  114. package/.devcontainer/devcontainer.json +0 -27
  115. package/.devcontainer/post-create.sh +0 -16
  116. package/LICENSE +0 -8
  117. package/dist/adapters/arcgis-maps-sdk.adapter.d.ts +0 -106
  118. package/dist/adapters/google-maps.adapter.d.ts +0 -90
  119. package/dist/adapters/leaflet.adapter.d.ts +0 -99
  120. package/dist/adapters/mapbox-gl.adapter.d.ts +0 -90
  121. package/dist/adapters/maplibre-gl.adapter.d.ts +0 -72
  122. package/dist/adapters/openlayers.adapter.d.ts +0 -121
  123. package/e2e/README.md +0 -29
  124. package/e2e/package-lock.json +0 -4275
  125. package/e2e/package.json +0 -26
  126. package/e2e/playwright.config.ts +0 -77
  127. package/e2e/public/favicon.ico +0 -0
  128. package/e2e/public/index.html +0 -55
  129. package/e2e/tests/leaflet.spec.ts +0 -1040
  130. package/e2e/tests/setup.ts +0 -208
  131. package/e2e/webpack.config.js +0 -36
  132. package/eslint.config.js +0 -31
  133. /package/dist/{adapters/common → common}/adapter-listener.d.ts +0 -0
@@ -1,90 +0,0 @@
1
- import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
2
- import mapboxgl from "mapbox-gl";
3
- import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
4
- export declare class TerraDrawMapboxGLAdapter extends TerraDrawBaseAdapter {
5
- constructor(config: {
6
- map: mapboxgl.Map;
7
- } & BaseAdapterConfig);
8
- private _nextRender;
9
- private _map;
10
- private _container;
11
- private _rendered;
12
- /**
13
- * Clears the map of rendered layers and sources
14
- * @returns void
15
- * */
16
- private clearLayers;
17
- private _addGeoJSONSource;
18
- private _addFillLayer;
19
- private _addFillOutlineLayer;
20
- private _addLineLayer;
21
- private _addPointLayer;
22
- private _addLayer;
23
- private _addGeoJSONLayer;
24
- private _setGeoJSONLayerData;
25
- private changedIds;
26
- private updateChangedIds;
27
- /**
28
- * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
29
- * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
30
- * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
31
- */
32
- getLngLatFromEvent(event: PointerEvent | MouseEvent): {
33
- lng: number;
34
- lat: number;
35
- };
36
- /**
37
- *Retrieves the HTML element of the Mapbox element that handles interaction events
38
- * @returns The HTMLElement representing the map container.
39
- */
40
- getMapEventElement(): HTMLCanvasElement;
41
- /**
42
- * Enables or disables the draggable functionality of the map.
43
- * @param enabled Set to true to enable map dragging, or false to disable it.
44
- */
45
- setDraggability(enabled: boolean): void;
46
- /**
47
- * Converts longitude and latitude coordinates to pixel coordinates in the map container.
48
- * @param lng The longitude coordinate to project.
49
- * @param lat The latitude coordinate to project.
50
- * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
51
- */
52
- project(lng: number, lat: number): {
53
- x: number;
54
- y: number;
55
- };
56
- /**
57
- * Converts pixel coordinates in the map container to longitude and latitude coordinates.
58
- * @param x The x-coordinate in the map container to unproject.
59
- * @param y The y-coordinate in the map container to unproject.
60
- * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
61
- */
62
- unproject(x: number, y: number): {
63
- lng: number;
64
- lat: number;
65
- };
66
- /**
67
- * Sets the cursor style for the map container.
68
- * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
69
- */
70
- setCursor(cursor: Parameters<SetCursor>[0]): void;
71
- /**
72
- * Enables or disables the double-click to zoom functionality on the map.
73
- * @param enabled Set to true to enable double-click to zoom, or false to disable it.
74
- */
75
- setDoubleClickToZoom(enabled: boolean): void;
76
- /**
77
- * Renders GeoJSON features on the map using the provided styling configuration.
78
- * @param changes An object containing arrays of created, updated, and unchanged features to render.
79
- * @param styling An object mapping draw modes to feature styling functions
80
- */
81
- render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
82
- /**
83
- * Clears the map and store of all rendered data layers
84
- * @returns void
85
- * */
86
- clear(): void;
87
- getCoordinatePrecision(): number;
88
- unregister(): void;
89
- register(callbacks: TerraDrawCallbacks): void;
90
- }
@@ -1,72 +0,0 @@
1
- import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
2
- import { Map } from "maplibre-gl";
3
- import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
4
- export declare class TerraDrawMapLibreGLAdapter extends TerraDrawBaseAdapter {
5
- private mapboxglAdapter;
6
- constructor(config: {
7
- map: Map;
8
- } & BaseAdapterConfig);
9
- register(callbacks: TerraDrawCallbacks): void;
10
- unregister(): void;
11
- getCoordinatePrecision(): number;
12
- /**
13
- * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
14
- * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
15
- * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
16
- */
17
- getLngLatFromEvent(event: PointerEvent | MouseEvent): {
18
- lng: number;
19
- lat: number;
20
- };
21
- /**
22
- * Retrieves the HTML element of the MapLibre element that handles interaction events
23
- * @returns The HTMLElement representing the map container.
24
- */
25
- getMapEventElement(): HTMLCanvasElement;
26
- /**
27
- * Enables or disables the draggable functionality of the map.
28
- * @param enabled Set to true to enable map dragging, or false to disable it.
29
- */
30
- setDraggability(enabled: boolean): void;
31
- /**
32
- * Converts longitude and latitude coordinates to pixel coordinates in the map container.
33
- * @param lng The longitude coordinate to project.
34
- * @param lat The latitude coordinate to project.
35
- * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
36
- */
37
- project(lng: number, lat: number): {
38
- x: number;
39
- y: number;
40
- };
41
- /**
42
- * Converts pixel coordinates in the map container to longitude and latitude coordinates.
43
- * @param x The x-coordinate in the map container to unproject.
44
- * @param y The y-coordinate in the map container to unproject.
45
- * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
46
- */
47
- unproject(x: number, y: number): {
48
- lng: number;
49
- lat: number;
50
- };
51
- /**
52
- * Sets the cursor style for the map container.
53
- * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
54
- */
55
- setCursor(style: Parameters<SetCursor>[0]): void;
56
- /**
57
- * Enables or disables the double-click to zoom functionality on the map.
58
- * @param enabled Set to true to enable double-click to zoom, or false to disable it.
59
- */
60
- setDoubleClickToZoom(enabled: boolean): void;
61
- /**
62
- * Renders GeoJSON features on the map using the provided styling configuration.
63
- * @param changes An object containing arrays of created, updated, and unchanged features to render.
64
- * @param styling An object mapping draw modes to feature styling functions
65
- */
66
- render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
67
- /**
68
- * Clears the map and store of all rendered data layers
69
- * @returns void
70
- * */
71
- clear(): void;
72
- }
@@ -1,121 +0,0 @@
1
- import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
2
- import Feature from "ol/Feature";
3
- import GeoJSON from "ol/format/GeoJSON";
4
- import Map from "ol/Map";
5
- import Circle from "ol/style/Circle";
6
- import Fill from "ol/style/Fill";
7
- import Stroke from "ol/style/Stroke";
8
- import Style from "ol/style/Style";
9
- import VectorSource from "ol/source/Vector";
10
- import VectorLayer from "ol/layer/Vector";
11
- import { getUserProjection } from "ol/proj";
12
- import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
13
- export type InjectableOL = {
14
- Fill: typeof Fill;
15
- Feature: typeof Feature;
16
- GeoJSON: typeof GeoJSON;
17
- Style: typeof Style;
18
- Circle: typeof Circle;
19
- VectorLayer: typeof VectorLayer;
20
- VectorSource: typeof VectorSource;
21
- Stroke: typeof Stroke;
22
- getUserProjection: typeof getUserProjection;
23
- };
24
- export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
25
- constructor(config: {
26
- map: Map;
27
- lib: InjectableOL;
28
- zIndex?: number;
29
- } & BaseAdapterConfig);
30
- private stylingFunction;
31
- private _lib;
32
- private _map;
33
- private _container;
34
- private _projection;
35
- private _vectorSource;
36
- private _geoJSONReader;
37
- /**
38
- * Converts a hexideciaml color to RGB
39
- * @param hex a string of the hexidecimal string
40
- * @returns an object to red green and blue (RGB) color
41
- */
42
- private hexToRGB;
43
- private getStyles;
44
- /**
45
- * Clears the layers created by the adapter
46
- * @returns void
47
- * */
48
- private clearLayers;
49
- private addFeature;
50
- private removeFeature;
51
- /**
52
- * Sorts an array of DOM elements based on their order in the document, from earliest to latest.
53
- * @param elements - An array of `HTMLElement` objects to be sorted.
54
- * @returns A new array of `HTMLElement` objects sorted by their document order.
55
- */
56
- private sortElementsByDOMOrder;
57
- /**
58
- * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
59
- * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
60
- * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
61
- */
62
- getLngLatFromEvent(event: PointerEvent | MouseEvent): {
63
- lng: number;
64
- lat: number;
65
- } | null;
66
- /**
67
- * Retrieves the HTML element of the OpenLayers element that handles interaction events
68
- * @returns The HTMLElement representing the map container.
69
- */
70
- getMapEventElement(): HTMLCanvasElement;
71
- /**
72
- * Enables or disables the draggable functionality of the map.
73
- * @param enabled Set to true to enable map dragging, or false to disable it.
74
- */
75
- setDraggability(enabled: boolean): void;
76
- /**
77
- * Converts longitude and latitude coordinates to pixel coordinates in the map container.
78
- * @param lng The longitude coordinate to project.
79
- * @param lat The latitude coordinate to project.
80
- * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
81
- */
82
- project(lng: number, lat: number): {
83
- x: number;
84
- y: number;
85
- };
86
- /**
87
- * Converts pixel coordinates in the map container to longitude and latitude coordinates.
88
- * @param x The x-coordinate in the map container to unproject.
89
- * @param y The y-coordinate in the map container to unproject.
90
- * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
91
- */
92
- unproject(x: number, y: number): {
93
- lng: number;
94
- lat: number;
95
- };
96
- /**
97
- * Sets the cursor style for the map container.
98
- * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
99
- */
100
- setCursor(cursor: Parameters<SetCursor>[0]): void;
101
- /**
102
- * Enables or disables the double-click to zoom functionality on the map.
103
- * @param enabled Set to true to enable double-click to zoom, or false to disable it.
104
- */
105
- setDoubleClickToZoom(enabled: boolean): void;
106
- /**
107
- * Renders GeoJSON features on the map using the provided styling configuration.
108
- * @param changes An object containing arrays of created, updated, and unchanged features to render.
109
- * @param styling An object mapping draw modes to feature styling functions
110
- */
111
- render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
112
- /**
113
- * Clears the map and store of all rendered data layers
114
- * @returns void
115
- * */
116
- clear(): void;
117
- private registeredLayerHandlers;
118
- register(callbacks: TerraDrawCallbacks): void;
119
- getCoordinatePrecision(): number;
120
- unregister(): void;
121
- }
package/e2e/README.md DELETED
@@ -1,29 +0,0 @@
1
- # E2E Testing with Playwright
2
-
3
- We provide a basic end-to-end (E2E) test suite via Playwright, testing against the Leaflet Adapter. The test suite aims to emulate how an end user would interact with and use Terra Draw. Here we can attempt to catch bugs earlier in the pipeline and ensure that new behaviours in the future adhere to a given specification.
4
-
5
- ## Installation
6
-
7
- Installation can be down via npm like so:
8
-
9
- ```shell
10
- npm install
11
- ```
12
-
13
- ## Running
14
-
15
- You can run the tests headless (i.e. no opening of Chromimum) like so:
16
-
17
- ```shell
18
- npm run test
19
- ```
20
-
21
- Or you can run them headed (i.e. Chromimum will open and you will see the tests run) like so:
22
-
23
- ```shell
24
- npm run test:headed
25
- ```
26
-
27
- ## Tests
28
-
29
- Tests are located in the `tests` folder. You will see the `leaflet.spec.ts` file, this is where the tests are kept for the E2E tests written for the Leaflet Adapter. There are also some convienence methods written in the `setup.ts` file which can be leveraged to write tests more easily.