terra-draw 0.0.1-alpha.7 → 0.0.1-alpha.70

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 (119) hide show
  1. package/.devcontainer/Dockerfile +8 -0
  2. package/.devcontainer/devcontainer.json +27 -0
  3. package/.devcontainer/post-create.sh +16 -0
  4. package/README.md +30 -6
  5. package/dist/adapters/arcgis-maps-sdk.adapter.d.ts +106 -0
  6. package/dist/adapters/google-maps.adapter.d.ts +90 -39
  7. package/dist/adapters/leaflet.adapter.d.ts +99 -33
  8. package/dist/adapters/mapbox-gl.adapter.d.ts +91 -37
  9. package/dist/adapters/maplibre-gl.adapter.d.ts +72 -0
  10. package/dist/adapters/openlayers.adapter.d.ts +120 -0
  11. package/dist/common.d.ts +118 -98
  12. package/dist/geometry/boolean/is-valid-coordinate.d.ts +4 -0
  13. package/dist/geometry/boolean/point-in-polygon.d.ts +2 -2
  14. package/dist/geometry/boolean/self-intersects.d.ts +2 -2
  15. package/dist/geometry/centroid.d.ts +2 -2
  16. package/dist/geometry/coordinates-identical.d.ts +2 -2
  17. package/dist/geometry/get-coordinates-as-points.d.ts +6 -6
  18. package/dist/geometry/get-midpoints.d.ts +14 -7
  19. package/dist/geometry/helpers.d.ts +4 -4
  20. package/dist/geometry/limit-decimal-precision.d.ts +1 -1
  21. package/dist/geometry/measure/area.d.ts +2 -0
  22. package/dist/geometry/measure/bearing.d.ts +9 -0
  23. package/dist/geometry/measure/destination.d.ts +2 -0
  24. package/dist/geometry/measure/haversine-distance.d.ts +2 -2
  25. package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -10
  26. package/dist/geometry/measure/pixel-distance.d.ts +7 -7
  27. package/dist/geometry/measure/rhumb-bearing.d.ts +2 -2
  28. package/dist/geometry/measure/rhumb-destination.d.ts +2 -2
  29. package/dist/geometry/measure/rhumb-distance.d.ts +2 -2
  30. package/dist/geometry/measure/slice-along.d.ts +2 -0
  31. package/dist/geometry/midpoint-coordinate.d.ts +4 -2
  32. package/dist/geometry/project/web-mercator.d.ts +20 -0
  33. package/dist/geometry/shape/create-bbox.d.ts +10 -0
  34. package/dist/geometry/shape/create-circle.d.ts +13 -7
  35. package/dist/geometry/shape/great-circle-coordinates.d.ts +2 -0
  36. package/dist/geometry/shape/web-mercator-distortion.d.ts +2 -0
  37. package/dist/geometry/transform/rotate.d.ts +9 -2
  38. package/dist/geometry/transform/scale.d.ts +9 -2
  39. package/dist/geometry/web-mercator-centroid.d.ts +11 -0
  40. package/dist/modes/base.behavior.d.ts +21 -19
  41. package/dist/modes/base.mode.d.ts +66 -33
  42. package/dist/modes/circle/circle.mode.d.ts +66 -35
  43. package/dist/modes/click-bounding-box.behavior.d.ts +6 -7
  44. package/dist/modes/freehand/freehand.mode.d.ts +63 -37
  45. package/dist/modes/insert-coordinates.behavior.d.ts +9 -0
  46. package/dist/modes/linestring/linestring.mode.d.ts +78 -40
  47. package/dist/modes/pixel-distance.behavior.d.ts +7 -7
  48. package/dist/modes/point/point.mode.d.ts +44 -26
  49. package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -19
  50. package/dist/modes/polygon/polygon.mode.d.ts +69 -49
  51. package/dist/modes/rectangle/rectangle.mode.d.ts +55 -0
  52. package/dist/modes/render/render.mode.d.ts +52 -23
  53. package/dist/modes/select/behaviors/drag-coordinate-resize.behavior.d.ts +62 -0
  54. package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +20 -13
  55. package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +20 -17
  56. package/dist/modes/select/behaviors/{features-at-mouse-event.behavior.d.ts → feature-at-pointer-event.behavior.d.ts} +15 -15
  57. package/dist/modes/select/behaviors/midpoint.behavior.d.ts +19 -18
  58. package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +14 -13
  59. package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +14 -13
  60. package/dist/modes/select/behaviors/selection-point.behavior.d.ts +19 -18
  61. package/dist/modes/select/select.mode.d.ts +119 -78
  62. package/dist/modes/snapping.behavior.d.ts +16 -13
  63. package/dist/modes/static/static.mode.d.ts +32 -30
  64. package/dist/store/spatial-index/quickselect.d.ts +2 -2
  65. package/dist/store/spatial-index/rbush.d.ts +35 -35
  66. package/dist/store/spatial-index/spatial-index.d.ts +18 -18
  67. package/dist/store/store-feature-validation.d.ts +16 -0
  68. package/dist/store/store.d.ts +59 -48
  69. package/dist/terra-draw.cjs +1 -1
  70. package/dist/terra-draw.cjs.map +1 -1
  71. package/dist/terra-draw.d.ts +222 -48
  72. package/dist/terra-draw.modern.js +1 -1
  73. package/dist/terra-draw.modern.js.map +1 -1
  74. package/dist/terra-draw.module.js +1 -1
  75. package/dist/terra-draw.module.js.map +1 -1
  76. package/dist/terra-draw.umd.js +1 -1
  77. package/dist/terra-draw.umd.js.map +1 -1
  78. package/dist/util/geoms.d.ts +3 -3
  79. package/dist/util/id.d.ts +1 -1
  80. package/dist/util/styling.d.ts +2 -2
  81. package/dist/validations/linestring.validation.d.ts +2 -0
  82. package/dist/validations/max-size.validation.d.ts +2 -0
  83. package/dist/validations/min-size.validation.d.ts +2 -0
  84. package/dist/validations/not-self-intersecting.validation.d.ts +2 -0
  85. package/dist/validations/point.validation.d.ts +2 -0
  86. package/dist/validations/polygon.validation.d.ts +3 -0
  87. package/e2e/README.md +29 -0
  88. package/e2e/package-lock.json +4274 -0
  89. package/e2e/package.json +26 -0
  90. package/e2e/playwright.config.ts +77 -0
  91. package/e2e/public/favicon.ico +0 -0
  92. package/e2e/public/index.html +52 -0
  93. package/e2e/tests/leaflet.spec.ts +657 -0
  94. package/e2e/tests/setup.ts +181 -0
  95. package/e2e/webpack.config.js +36 -0
  96. package/jest.nocheck.config.ts +17 -0
  97. package/package.json +158 -87
  98. package/readme.gif +0 -0
  99. package/tsconfig.json +25 -12
  100. package/CODE_OF_CONDUCT.md +0 -36
  101. package/CONTRIBUTING.md +0 -17
  102. package/DEVELOPMENT.md +0 -77
  103. package/dist/bundle.js +0 -6
  104. package/dist/bundle.js.LICENSE.txt +0 -4
  105. package/dist/geometry/create-circle.d.ts +0 -6
  106. package/dist/geometry/get-pixel-distance-to-line.d.ts +0 -10
  107. package/dist/geometry/get-pixel-distance.d.ts +0 -7
  108. package/dist/geometry/haversine-distance.d.ts +0 -1
  109. package/dist/geometry/point-in-polygon.d.ts +0 -1
  110. package/dist/geometry/self-intersects.d.ts +0 -2
  111. package/dist/modes/circle.mode.d.ts +0 -18
  112. package/dist/modes/freehand.mode.d.ts +0 -20
  113. package/dist/modes/line-string.mode.d.ts +0 -21
  114. package/dist/modes/point.mode.d.ts +0 -14
  115. package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +0 -11
  116. package/dist/modes/polygon.mode.d.ts +0 -21
  117. package/dist/modes/select.mode.d.ts +0 -21
  118. package/dist/modes/static.mode.d.ts +0 -10
  119. package/jest.config.ts +0 -27
@@ -0,0 +1,72 @@
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
+ }
@@ -0,0 +1,120 @@
1
+ import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
2
+ import CircleGeom from "ol/geom/Circle";
3
+ import Feature from "ol/Feature";
4
+ import GeoJSON from "ol/format/GeoJSON";
5
+ import Map from "ol/Map";
6
+ import Circle from "ol/style/Circle";
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 { toLonLat } from "ol/proj";
12
+ import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
13
+ type InjectableOL = {
14
+ Circle: typeof CircleGeom;
15
+ Feature: typeof Feature;
16
+ GeoJSON: typeof GeoJSON;
17
+ Style: typeof Style;
18
+ CircleStyle: typeof Circle;
19
+ VectorLayer: typeof VectorLayer;
20
+ VectorSource: typeof VectorSource;
21
+ Stroke: typeof Stroke;
22
+ toLonLat: typeof toLonLat;
23
+ };
24
+ export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
25
+ constructor(config: {
26
+ map: Map;
27
+ lib: InjectableOL;
28
+ } & BaseAdapterConfig);
29
+ private stylingFunction;
30
+ private _lib;
31
+ private _map;
32
+ private _container;
33
+ private _projection;
34
+ private _vectorSource;
35
+ private _geoJSONReader;
36
+ /**
37
+ * Converts a hexideciaml color to RGB
38
+ * @param hex a string of the hexidecimal string
39
+ * @returns an object to red green and blue (RGB) color
40
+ */
41
+ private hexToRGB;
42
+ /**
43
+ * Converts a hexideciaml color to RGB
44
+ * @param feature
45
+ * @param styling
46
+ * @returns an object to red green and blue (RGB) color
47
+ */
48
+ private getStyles;
49
+ /**
50
+ * Clears the layers created by the adapter
51
+ * @returns void
52
+ * */
53
+ private clearLayers;
54
+ private addFeature;
55
+ private removeFeature;
56
+ /**
57
+ * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
58
+ * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
59
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
60
+ */
61
+ getLngLatFromEvent(event: PointerEvent | MouseEvent): {
62
+ lng: number;
63
+ lat: number;
64
+ } | null;
65
+ /**
66
+ * Retrieves the HTML element of the OpenLayers element that handles interaction events
67
+ * @returns The HTMLElement representing the map container.
68
+ */
69
+ getMapEventElement(): HTMLCanvasElement;
70
+ /**
71
+ * Enables or disables the draggable functionality of the map.
72
+ * @param enabled Set to true to enable map dragging, or false to disable it.
73
+ */
74
+ setDraggability(enabled: boolean): void;
75
+ /**
76
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
77
+ * @param lng The longitude coordinate to project.
78
+ * @param lat The latitude coordinate to project.
79
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
80
+ */
81
+ project(lng: number, lat: number): {
82
+ x: number;
83
+ y: number;
84
+ };
85
+ /**
86
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
87
+ * @param x The x-coordinate in the map container to unproject.
88
+ * @param y The y-coordinate in the map container to unproject.
89
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
90
+ */
91
+ unproject(x: number, y: number): {
92
+ lng: number;
93
+ lat: number;
94
+ };
95
+ /**
96
+ * Sets the cursor style for the map container.
97
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
98
+ */
99
+ setCursor(cursor: Parameters<SetCursor>[0]): void;
100
+ /**
101
+ * Enables or disables the double-click to zoom functionality on the map.
102
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
103
+ */
104
+ setDoubleClickToZoom(enabled: boolean): void;
105
+ /**
106
+ * Renders GeoJSON features on the map using the provided styling configuration.
107
+ * @param changes An object containing arrays of created, updated, and unchanged features to render.
108
+ * @param styling An object mapping draw modes to feature styling functions
109
+ */
110
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
111
+ /**
112
+ * Clears the map and store of all rendered data layers
113
+ * @returns void
114
+ * */
115
+ clear(): void;
116
+ register(callbacks: TerraDrawCallbacks): void;
117
+ getCoordinatePrecision(): number;
118
+ unregister(): void;
119
+ }
120
+ export {};
package/dist/common.d.ts CHANGED
@@ -1,98 +1,118 @@
1
- import { StoreChangeHandler, GeoJSONStore, GeoJSONStoreFeatures } from "./store/store";
2
- export declare type HexColor = `#${string}`;
3
- export interface TerraDrawAdapterStyling {
4
- pointColor: HexColor;
5
- pointWidth: number;
6
- pointOutlineColor: HexColor;
7
- pointOutlineWidth: number;
8
- polygonFillColor: HexColor;
9
- polygonFillOpacity: number;
10
- polygonOutlineColor: HexColor;
11
- polygonOutlineWidth: number;
12
- lineStringWidth: number;
13
- lineStringColor: HexColor;
14
- zIndex: number;
15
- }
16
- export interface TerraDrawMouseEvent {
17
- lng: number;
18
- lat: number;
19
- containerX: number;
20
- containerY: number;
21
- button: "left" | "right" | "pointer";
22
- heldKeys: string[];
23
- }
24
- export interface TerraDrawKeyboardEvent {
25
- key: string;
26
- }
27
- declare type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer") => void;
28
- export declare type Project = (lng: number, lat: number) => {
29
- x: number;
30
- y: number;
31
- };
32
- export declare type Unproject = (x: number, y: number) => {
33
- lat: number;
34
- lng: number;
35
- };
36
- export interface TerraDrawModeRegisterConfig {
37
- mode: string;
38
- store: GeoJSONStore;
39
- setCursor: SetCursor;
40
- onChange: StoreChangeHandler;
41
- onSelect: (selectedId: string) => void;
42
- onDeselect: (deselectedId: string) => void;
43
- project: Project;
44
- unproject: Unproject;
45
- }
46
- export declare type TerraDrawModeState = "unregistered" | "registered" | "started" | "stopped";
47
- export interface TerraDrawMode {
48
- mode: string;
49
- styleFeature: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
50
- styles: any;
51
- state: TerraDrawModeState;
52
- start: () => void;
53
- stop: () => void;
54
- register: (config: TerraDrawModeRegisterConfig) => void;
55
- onKeyDown: (event: TerraDrawKeyboardEvent) => void;
56
- onKeyUp: (event: TerraDrawKeyboardEvent) => void;
57
- onMouseMove: (event: TerraDrawMouseEvent) => void;
58
- onClick: (event: TerraDrawMouseEvent) => void;
59
- onDragStart: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
60
- onDrag: (event: TerraDrawMouseEvent) => void;
61
- onDragEnd: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
62
- }
63
- export interface TerraDrawCallbacks {
64
- onKeyUp: (event: TerraDrawKeyboardEvent) => void;
65
- onKeyDown: (event: TerraDrawKeyboardEvent) => void;
66
- onClick: (event: TerraDrawMouseEvent) => void;
67
- onMouseMove: (event: TerraDrawMouseEvent) => void;
68
- onDragStart: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
69
- onDrag: (event: TerraDrawMouseEvent) => void;
70
- onDragEnd: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
71
- }
72
- export interface TerraDrawChanges {
73
- created: GeoJSONStoreFeatures[];
74
- updated: GeoJSONStoreFeatures[];
75
- unchanged: GeoJSONStoreFeatures[];
76
- deletedIds: string[];
77
- }
78
- declare type TerraDrawStylingFunction = {
79
- [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
80
- };
81
- export interface TerraDrawAdapter {
82
- project: Project;
83
- unproject: Unproject;
84
- setCursor: SetCursor;
85
- getMapContainer: () => HTMLElement;
86
- register(callbacks: TerraDrawCallbacks): void;
87
- unregister(): void;
88
- render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
89
- }
90
- export declare const SELECT_PROPERTIES: {
91
- readonly SELECTED: "selected";
92
- readonly MID_POINT: "midPoint";
93
- readonly SELECTION_POINT: "selectionPoint";
94
- };
95
- export declare const POLYGON_PROPERTIES: {
96
- CLOSING_POINT: string;
97
- };
98
- export {};
1
+ import { StoreChangeHandler, GeoJSONStore, GeoJSONStoreFeatures, FeatureId } from "./store/store";
2
+ export type HexColor = `#${string}`;
3
+ export type HexColorStyling = HexColor | ((feature: GeoJSONStoreFeatures) => HexColor);
4
+ export type NumericStyling = number | ((feature: GeoJSONStoreFeatures) => number);
5
+ export interface TerraDrawAdapterStyling {
6
+ pointColor: HexColor;
7
+ pointWidth: number;
8
+ pointOutlineColor: HexColor;
9
+ pointOutlineWidth: number;
10
+ polygonFillColor: HexColor;
11
+ polygonFillOpacity: number;
12
+ polygonOutlineColor: HexColor;
13
+ polygonOutlineWidth: number;
14
+ lineStringWidth: number;
15
+ lineStringColor: HexColor;
16
+ zIndex: number;
17
+ }
18
+ export interface TerraDrawMouseEvent {
19
+ lng: number;
20
+ lat: number;
21
+ containerX: number;
22
+ containerY: number;
23
+ button: "neither" | "left" | "middle" | "right";
24
+ heldKeys: string[];
25
+ }
26
+ export interface TerraDrawKeyboardEvent {
27
+ key: string;
28
+ heldKeys: string[];
29
+ preventDefault: () => void;
30
+ }
31
+ export type Required<T> = {
32
+ [P in keyof T]-?: T[P];
33
+ };
34
+ export type Cursor = Parameters<SetCursor>[0];
35
+ export type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer" | "wait" | "move") => void;
36
+ export type Project = (lng: number, lat: number) => {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ export type Unproject = (x: number, y: number) => {
41
+ lat: number;
42
+ lng: number;
43
+ };
44
+ export type GetLngLatFromEvent = (event: PointerEvent | MouseEvent) => {
45
+ lng: number;
46
+ lat: number;
47
+ } | null;
48
+ export type Projection = "web-mercator" | "globe";
49
+ export type OnFinishContext = {
50
+ mode: string;
51
+ action: string;
52
+ };
53
+ export interface TerraDrawModeRegisterConfig {
54
+ mode: string;
55
+ store: GeoJSONStore;
56
+ setDoubleClickToZoom: (enabled: boolean) => void;
57
+ setCursor: SetCursor;
58
+ onChange: StoreChangeHandler;
59
+ onSelect: (selectedId: string) => void;
60
+ onDeselect: (deselectedId: string) => void;
61
+ onFinish: (finishedId: string, context: OnFinishContext) => void;
62
+ project: Project;
63
+ unproject: Unproject;
64
+ coordinatePrecision: number;
65
+ }
66
+ export declare enum UpdateTypes {
67
+ Commit = "commit",
68
+ Provisional = "provisional",
69
+ Finish = "finish"
70
+ }
71
+ type ValidationContext = Pick<TerraDrawModeRegisterConfig, "project" | "unproject" | "coordinatePrecision"> & {
72
+ updateType: UpdateTypes;
73
+ };
74
+ export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) => boolean;
75
+ export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped";
76
+ export interface TerraDrawCallbacks {
77
+ getState: () => TerraDrawModeState;
78
+ onKeyUp: (event: TerraDrawKeyboardEvent) => void;
79
+ onKeyDown: (event: TerraDrawKeyboardEvent) => void;
80
+ onClick: (event: TerraDrawMouseEvent) => void;
81
+ onMouseMove: (event: TerraDrawMouseEvent) => void;
82
+ onDragStart: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
83
+ onDrag: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
84
+ onDragEnd: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
85
+ onClear: () => void;
86
+ onReady?(): void;
87
+ }
88
+ export interface TerraDrawChanges {
89
+ created: GeoJSONStoreFeatures[];
90
+ updated: GeoJSONStoreFeatures[];
91
+ unchanged: GeoJSONStoreFeatures[];
92
+ deletedIds: FeatureId[];
93
+ }
94
+ export type TerraDrawStylingFunction = {
95
+ [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
96
+ };
97
+ export interface TerraDrawAdapter {
98
+ project: Project;
99
+ unproject: Unproject;
100
+ setCursor: SetCursor;
101
+ getLngLatFromEvent: GetLngLatFromEvent;
102
+ setDoubleClickToZoom: (enabled: boolean) => void;
103
+ getMapEventElement: () => HTMLElement;
104
+ register(callbacks: TerraDrawCallbacks): void;
105
+ unregister(): void;
106
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
107
+ clear(): void;
108
+ getCoordinatePrecision(): number;
109
+ }
110
+ export declare const SELECT_PROPERTIES: {
111
+ readonly SELECTED: "selected";
112
+ readonly MID_POINT: "midPoint";
113
+ readonly SELECTION_POINT: "selectionPoint";
114
+ };
115
+ export declare const POLYGON_PROPERTIES: {
116
+ CLOSING_POINT: string;
117
+ };
118
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare function validLatitude(lat: number): boolean;
2
+ export declare function validLongitude(lng: number): boolean;
3
+ export declare function coordinateIsValid(coordinate: unknown[], coordinatePrecision: number): boolean;
4
+ export declare function getDecimalPlaces(value: number): number;
@@ -1,2 +1,2 @@
1
- import { Position } from "geojson";
2
- export declare function pointInPolygon(point: Position, rings: Position[][]): boolean;
1
+ import { Position } from "geojson";
2
+ export declare function pointInPolygon(point: Position, rings: Position[][]): boolean;
@@ -1,2 +1,2 @@
1
- import { Feature, LineString, Polygon } from "geojson";
2
- export declare function selfIntersects(feature: Feature<Polygon> | Feature<LineString>): boolean;
1
+ import { Feature, LineString, Polygon } from "geojson";
2
+ export declare function selfIntersects(feature: Feature<Polygon> | Feature<LineString>): boolean;
@@ -1,2 +1,2 @@
1
- import { Feature, LineString, Polygon, Position } from "geojson";
2
- export declare function centroid(geojson: Feature<Polygon | LineString>): Position;
1
+ import { Feature, LineString, Polygon, Position } from "geojson";
2
+ export declare function centroid(geojson: Feature<Polygon | LineString>): Position;
@@ -1,2 +1,2 @@
1
- import { Position } from "geojson";
2
- export declare function coordinatesIdentical(coordinate: Position, coordinateTwo: Position): boolean;
1
+ import { Position } from "geojson";
2
+ export declare function coordinatesIdentical(coordinate: Position, coordinateTwo: Position): boolean;
@@ -1,6 +1,6 @@
1
- import { Point, Position } from "geojson";
2
- import { JSONObject } from "../store/store";
3
- export declare function getCoordinatesAsPoints(selectedCoords: Position[], geometryType: "Polygon" | "LineString", properties: (index: number) => JSONObject): {
4
- geometry: Point;
5
- properties: JSONObject;
6
- }[];
1
+ import { Point, Position } from "geojson";
2
+ import { JSONObject } from "../store/store";
3
+ export declare function getCoordinatesAsPoints(selectedCoords: Position[], geometryType: "Polygon" | "LineString", properties: (index: number) => JSONObject): {
4
+ geometry: Point;
5
+ properties: JSONObject;
6
+ }[];
@@ -1,7 +1,14 @@
1
- import { Point, Position } from "geojson";
2
- import { JSONObject } from "../store/store";
3
- export declare function getMidPointCoordinates(featureCoords: Position[], precision: number): Position[];
4
- export declare function getMidPoints(selectedCoords: Position[], properties: (index: number) => JSONObject, precision: number): {
5
- geometry: Point;
6
- properties: JSONObject;
7
- }[];
1
+ import { Point, Position } from "geojson";
2
+ import { Project, Projection, Unproject } from "../common";
3
+ import { JSONObject } from "../store/store";
4
+ export declare function getMidPointCoordinates({ featureCoords, precision, unproject, project, projection, }: {
5
+ featureCoords: Position[];
6
+ precision: number;
7
+ project: Project;
8
+ unproject: Unproject;
9
+ projection: Projection;
10
+ }): Position[];
11
+ export declare function getMidPoints(selectedCoords: Position[], properties: (index: number) => JSONObject, precision: number, project: Project, unproject: Unproject, projection: Projection): {
12
+ geometry: Point;
13
+ properties: JSONObject;
14
+ }[];
@@ -1,4 +1,4 @@
1
- export declare const earthRadius = 6371008.8;
2
- export declare function degreesToRadians(degrees: number): number;
3
- export declare function lengthToRadians(distance: number): number;
4
- export declare function radiansToDegrees(radians: number): number;
1
+ export declare const earthRadius = 6371008.8;
2
+ export declare function degreesToRadians(degrees: number): number;
3
+ export declare function lengthToRadians(distance: number): number;
4
+ export declare function radiansToDegrees(radians: number): number;
@@ -1 +1 @@
1
- export declare function limitPrecision(num: number, decimalLimit?: number): number;
1
+ export declare function limitPrecision(num: number, decimalLimit?: number): number;
@@ -0,0 +1,2 @@
1
+ import { Polygon } from "geojson";
2
+ export declare function polygonAreaSquareMeters(polygon: Polygon): number;
@@ -0,0 +1,9 @@
1
+ import { Position } from "geojson";
2
+ 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;
@@ -0,0 +1,2 @@
1
+ import { Position } from "geojson";
2
+ export declare function destination(origin: Position, distance: number, bearing: number): Position;
@@ -1,2 +1,2 @@
1
- import { Position } from "geojson";
2
- export declare function haversineDistanceKilometers(pointOne: Position, pointTwo: Position): number;
1
+ import { Position } from "geojson";
2
+ export declare function haversineDistanceKilometers(pointOne: Position, pointTwo: Position): number;
@@ -1,10 +1,10 @@
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
+ 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,7 +1,7 @@
1
- export declare const pixelDistance: (pointOne: {
2
- x: number;
3
- y: number;
4
- }, pointTwo: {
5
- x: number;
6
- y: number;
7
- }) => number;
1
+ export declare const pixelDistance: (pointOne: {
2
+ x: number;
3
+ y: number;
4
+ }, pointTwo: {
5
+ x: number;
6
+ y: number;
7
+ }) => number;
@@ -1,2 +1,2 @@
1
- import { Position } from "geojson";
2
- export declare function rhumbBearing(start: Position, end: Position): number;
1
+ import { Position } from "geojson";
2
+ export declare function rhumbBearing(start: Position, end: Position): number;
@@ -1,2 +1,2 @@
1
- import { Position } from "geojson";
2
- export declare function rhumbDestination(origin: Position, distanceMeters: number, bearing: number): Position;
1
+ import { Position } from "geojson";
2
+ export declare function rhumbDestination(origin: Position, distanceMeters: number, bearing: number): Position;
@@ -1,2 +1,2 @@
1
- import { Position } from "geojson";
2
- export declare function rhumbDistance(destination: Position, origin: Position): number;
1
+ import { Position } from "geojson";
2
+ export declare function rhumbDistance(destination: Position, origin: Position): number;
@@ -0,0 +1,2 @@
1
+ import { LineString, Position } from "geojson";
2
+ export declare function lineSliceAlong(coords: LineString["coordinates"], startDist: number, stopDist: number): Position[];
@@ -1,2 +1,4 @@
1
- import { Position } from "geojson";
2
- export declare function midpointCoordinate(coordinates1: Position, coordinates2: Position, precision: number): number[];
1
+ import { Position } from "geojson";
2
+ import { Project, Unproject } from "../common";
3
+ export declare function midpointCoordinate(coordinates1: Position, coordinates2: Position, precision: number, project: Project, unproject: Unproject): number[];
4
+ export declare function geodesicMidpointCoordinate(coordinates1: Position, coordinates2: Position, precision: number): number[];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Convert longitude and latitude to web mercator x and y
3
+ * @param lng
4
+ * @param lat
5
+ * @returns - web mercator x and y
6
+ */
7
+ export declare const lngLatToWebMercatorXY: (lng: number, lat: number) => {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ /**
12
+ * Convert web mercator x and y to longitude and latitude
13
+ * @param x - web mercator x
14
+ * @param y - web mercator y
15
+ * @returns - longitude and latitude
16
+ */
17
+ export declare const webMercatorXYToLngLat: (x: number, y: number) => {
18
+ lng: number;
19
+ lat: number;
20
+ };
@@ -0,0 +1,10 @@
1
+ import { Feature, Polygon } from "geojson";
2
+ import { Unproject } from "../../common";
3
+ export declare function createBBoxFromPoint({ unproject, point, pointerDistance, }: {
4
+ point: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ unproject: Unproject;
9
+ pointerDistance: number;
10
+ }): Feature<Polygon>;
@@ -1,7 +1,13 @@
1
- import { Feature, Polygon, Position } from "geojson";
2
- export declare function destination(origin: Position, distance: number, bearing: number): Position;
3
- export declare function circle(options: {
4
- center: Position;
5
- radiusKilometers: number;
6
- steps?: number;
7
- }): Feature<Polygon>;
1
+ import { Feature, Polygon, Position } from "geojson";
2
+ export declare function circle(options: {
3
+ center: Position;
4
+ radiusKilometers: number;
5
+ coordinatePrecision: number;
6
+ steps?: number;
7
+ }): Feature<Polygon>;
8
+ export declare function circleWebMercator(options: {
9
+ center: Position;
10
+ radiusKilometers: number;
11
+ coordinatePrecision: number;
12
+ steps?: number;
13
+ }): GeoJSON.Feature<GeoJSON.Polygon>;