terra-draw 0.0.1-alpha.6 → 0.0.1-alpha.61

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 (112) hide show
  1. package/.devcontainer/Dockerfile +8 -0
  2. package/.devcontainer/devcontainer.json +21 -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 +105 -0
  6. package/dist/adapters/common/adapter-listener.d.ts +22 -0
  7. package/dist/adapters/common/base.adapter.d.ts +59 -0
  8. package/dist/adapters/google-maps.adapter.d.ts +90 -39
  9. package/dist/adapters/leaflet.adapter.d.ts +97 -33
  10. package/dist/adapters/mapbox-gl.adapter.d.ts +89 -37
  11. package/dist/adapters/maplibre-gl.adapter.d.ts +71 -0
  12. package/dist/adapters/openlayers.adapter.d.ts +118 -0
  13. package/dist/common.d.ts +103 -98
  14. package/dist/geometry/boolean/is-valid-coordinate.d.ts +4 -0
  15. package/dist/geometry/boolean/is-valid-linestring-feature.d.ts +2 -0
  16. package/dist/geometry/boolean/is-valid-point.d.ts +2 -0
  17. package/dist/geometry/boolean/is-valid-polygon-feature.d.ts +3 -0
  18. package/dist/geometry/boolean/point-in-polygon.d.ts +2 -2
  19. package/dist/geometry/boolean/self-intersects.d.ts +2 -2
  20. package/dist/geometry/centroid.d.ts +2 -2
  21. package/dist/geometry/coordinates-identical.d.ts +2 -2
  22. package/dist/geometry/get-coordinates-as-points.d.ts +6 -6
  23. package/dist/geometry/get-midpoints.d.ts +8 -7
  24. package/dist/geometry/helpers.d.ts +4 -4
  25. package/dist/geometry/limit-decimal-precision.d.ts +1 -1
  26. package/dist/geometry/measure/haversine-distance.d.ts +2 -2
  27. package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -10
  28. package/dist/geometry/measure/pixel-distance.d.ts +7 -7
  29. package/dist/geometry/measure/rhumb-bearing.d.ts +2 -2
  30. package/dist/geometry/measure/rhumb-destination.d.ts +2 -2
  31. package/dist/geometry/measure/rhumb-distance.d.ts +2 -2
  32. package/dist/geometry/midpoint-coordinate.d.ts +3 -2
  33. package/dist/geometry/shape/create-bbox.d.ts +10 -0
  34. package/dist/geometry/shape/create-circle.d.ts +7 -7
  35. package/dist/geometry/shape/great-circle-line.d.ts +12 -0
  36. package/dist/geometry/transform/rotate.d.ts +2 -2
  37. package/dist/geometry/transform/scale.d.ts +2 -2
  38. package/dist/modes/base.behavior.d.ts +19 -19
  39. package/dist/modes/base.mode.d.ts +62 -33
  40. package/dist/modes/circle/circle.mode.d.ts +55 -35
  41. package/dist/modes/click-bounding-box.behavior.d.ts +6 -7
  42. package/dist/modes/freehand/freehand.mode.d.ts +63 -37
  43. package/dist/modes/great-circle-snapping.behavior.d.ts +14 -0
  44. package/dist/modes/greatcircle/great-circle.mode.d.ts +64 -0
  45. package/dist/modes/linestring/linestring.mode.d.ts +67 -40
  46. package/dist/modes/pixel-distance.behavior.d.ts +7 -7
  47. package/dist/modes/point/point.mode.d.ts +44 -26
  48. package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -19
  49. package/dist/modes/polygon/polygon.mode.d.ts +70 -49
  50. package/dist/modes/rectangle/rectangle.mode.d.ts +55 -0
  51. package/dist/modes/render/render.mode.d.ts +52 -23
  52. package/dist/modes/select/behaviors/drag-coordinate-resize.behavior.d.ts +28 -0
  53. package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +20 -13
  54. package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +20 -17
  55. package/dist/modes/select/behaviors/{features-at-mouse-event.behavior.d.ts → feature-at-pointer-event.behavior.d.ts} +15 -15
  56. package/dist/modes/select/behaviors/midpoint.behavior.d.ts +19 -18
  57. package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +14 -13
  58. package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +14 -13
  59. package/dist/modes/select/behaviors/selection-point.behavior.d.ts +19 -18
  60. package/dist/modes/select/select.mode.d.ts +117 -78
  61. package/dist/modes/snapping.behavior.d.ts +16 -13
  62. package/dist/modes/static/static.mode.d.ts +32 -30
  63. package/dist/store/spatial-index/quickselect.d.ts +2 -2
  64. package/dist/store/spatial-index/rbush.d.ts +35 -35
  65. package/dist/store/spatial-index/spatial-index.d.ts +18 -18
  66. package/dist/store/store-feature-validation.d.ts +16 -0
  67. package/dist/store/store.d.ts +59 -48
  68. package/dist/terra-draw.cjs +1 -1
  69. package/dist/terra-draw.cjs.map +1 -1
  70. package/dist/terra-draw.d.ts +220 -48
  71. package/dist/terra-draw.modern.js +1 -1
  72. package/dist/terra-draw.modern.js.map +1 -1
  73. package/dist/terra-draw.module.js +1 -1
  74. package/dist/terra-draw.module.js.map +1 -1
  75. package/dist/terra-draw.umd.js +1 -1
  76. package/dist/terra-draw.umd.js.map +1 -1
  77. package/dist/util/geoms.d.ts +3 -3
  78. package/dist/util/id.d.ts +1 -1
  79. package/dist/util/styling.d.ts +2 -2
  80. package/e2e/README.md +29 -0
  81. package/e2e/package-lock.json +4249 -0
  82. package/e2e/package.json +26 -0
  83. package/e2e/playwright.config.ts +77 -0
  84. package/e2e/public/index.html +53 -0
  85. package/e2e/src/index.ts +165 -0
  86. package/e2e/tests/leaflet.spec.ts +413 -0
  87. package/e2e/tests/setup.ts +164 -0
  88. package/e2e/webpack.config.js +36 -0
  89. package/jest.nocheck.config.ts +17 -0
  90. package/package.json +157 -87
  91. package/readme.gif +0 -0
  92. package/tsconfig.json +17 -12
  93. package/CODE_OF_CONDUCT.md +0 -36
  94. package/CONTRIBUTING.md +0 -17
  95. package/DEVELOPMENT.md +0 -77
  96. package/dist/bundle.js +0 -6
  97. package/dist/bundle.js.LICENSE.txt +0 -4
  98. package/dist/geometry/create-circle.d.ts +0 -6
  99. package/dist/geometry/get-pixel-distance-to-line.d.ts +0 -10
  100. package/dist/geometry/get-pixel-distance.d.ts +0 -7
  101. package/dist/geometry/haversine-distance.d.ts +0 -1
  102. package/dist/geometry/point-in-polygon.d.ts +0 -1
  103. package/dist/geometry/self-intersects.d.ts +0 -2
  104. package/dist/modes/circle.mode.d.ts +0 -18
  105. package/dist/modes/freehand.mode.d.ts +0 -20
  106. package/dist/modes/line-string.mode.d.ts +0 -21
  107. package/dist/modes/point.mode.d.ts +0 -14
  108. package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +0 -11
  109. package/dist/modes/polygon.mode.d.ts +0 -21
  110. package/dist/modes/select.mode.d.ts +0 -21
  111. package/dist/modes/static.mode.d.ts +0 -10
  112. package/jest.config.ts +0 -27
@@ -1,37 +1,89 @@
1
- import { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
2
- import mapboxgl from "mapbox-gl";
3
- import { GeoJSONStoreFeatures } from "../store/store";
4
- export declare class TerraDrawMapboxGLAdapter implements TerraDrawAdapter {
5
- constructor(config: {
6
- map: mapboxgl.Map;
7
- coordinatePrecision: number;
8
- });
9
- unproject: TerraDrawModeRegisterConfig["unproject"];
10
- project: TerraDrawModeRegisterConfig["project"];
11
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
12
- getMapContainer: () => HTMLElement;
13
- private _heldKeys;
14
- private _coordinatePrecision;
15
- private _map;
16
- private _onMouseMoveListener;
17
- private _onClickListener;
18
- private _onDragStartListener;
19
- private _onDragListener;
20
- private _onDragEndListener;
21
- private _onKeyDownListener;
22
- private _onKeyUpListener;
23
- private _rendered;
24
- private _addGeoJSONSource;
25
- private _addFillLayer;
26
- private _addFillOutlineLayer;
27
- private _addLineLayer;
28
- private _addPointLayer;
29
- private _addLayer;
30
- private _addGeoJSONLayer;
31
- private _setGeoJSONLayerData;
32
- register(callbacks: TerraDrawCallbacks): void;
33
- unregister(): void;
34
- render(changes: TerraDrawChanges, styling: {
35
- [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
36
- }): void;
37
- }
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 getEmptyGeometries;
26
+ private changedIds;
27
+ private updateChangedIds;
28
+ /**
29
+ * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
30
+ * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
31
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
32
+ */
33
+ getLngLatFromEvent(event: PointerEvent | MouseEvent): {
34
+ lng: number;
35
+ lat: number;
36
+ };
37
+ /**
38
+ *Retrieves the HTML element of the Mapbox element that handles interaction events
39
+ * @returns The HTMLElement representing the map container.
40
+ */
41
+ getMapEventElement(): HTMLCanvasElement;
42
+ /**
43
+ * Enables or disables the draggable functionality of the map.
44
+ * @param enabled Set to true to enable map dragging, or false to disable it.
45
+ */
46
+ setDraggability(enabled: boolean): void;
47
+ /**
48
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
49
+ * @param lng The longitude coordinate to project.
50
+ * @param lat The latitude coordinate to project.
51
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
52
+ */
53
+ project(lng: number, lat: number): {
54
+ x: number;
55
+ y: number;
56
+ };
57
+ /**
58
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
59
+ * @param x The x-coordinate in the map container to unproject.
60
+ * @param y The y-coordinate in the map container to unproject.
61
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
62
+ */
63
+ unproject(x: number, y: number): {
64
+ lng: number;
65
+ lat: number;
66
+ };
67
+ /**
68
+ * Sets the cursor style for the map container.
69
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
70
+ */
71
+ setCursor(cursor: Parameters<SetCursor>[0]): void;
72
+ /**
73
+ * Enables or disables the double-click to zoom functionality on the map.
74
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
75
+ */
76
+ setDoubleClickToZoom(enabled: boolean): void;
77
+ /**
78
+ * Renders GeoJSON features on the map using the provided styling configuration.
79
+ * @param changes An object containing arrays of created, updated, and unchanged features to render.
80
+ * @param styling An object mapping draw modes to feature styling functions
81
+ */
82
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
83
+ /**
84
+ * Clears the map and store of all rendered data layers
85
+ * @returns void
86
+ * */
87
+ clear(): void;
88
+ register(callbacks: TerraDrawCallbacks): void;
89
+ }
@@ -0,0 +1,71 @@
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
+ /**
12
+ * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
13
+ * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
14
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
15
+ */
16
+ getLngLatFromEvent(event: PointerEvent | MouseEvent): {
17
+ lng: number;
18
+ lat: number;
19
+ };
20
+ /**
21
+ * Retrieves the HTML element of the MapLibre element that handles interaction events
22
+ * @returns The HTMLElement representing the map container.
23
+ */
24
+ getMapEventElement(): HTMLCanvasElement;
25
+ /**
26
+ * Enables or disables the draggable functionality of the map.
27
+ * @param enabled Set to true to enable map dragging, or false to disable it.
28
+ */
29
+ setDraggability(enabled: boolean): void;
30
+ /**
31
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
32
+ * @param lng The longitude coordinate to project.
33
+ * @param lat The latitude coordinate to project.
34
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
35
+ */
36
+ project(lng: number, lat: number): {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ /**
41
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
42
+ * @param x The x-coordinate in the map container to unproject.
43
+ * @param y The y-coordinate in the map container to unproject.
44
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
45
+ */
46
+ unproject(x: number, y: number): {
47
+ lng: number;
48
+ lat: number;
49
+ };
50
+ /**
51
+ * Sets the cursor style for the map container.
52
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
53
+ */
54
+ setCursor(style: Parameters<SetCursor>[0]): void;
55
+ /**
56
+ * Enables or disables the double-click to zoom functionality on the map.
57
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
58
+ */
59
+ setDoubleClickToZoom(enabled: boolean): void;
60
+ /**
61
+ * Renders GeoJSON features on the map using the provided styling configuration.
62
+ * @param changes An object containing arrays of created, updated, and unchanged features to render.
63
+ * @param styling An object mapping draw modes to feature styling functions
64
+ */
65
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
66
+ /**
67
+ * Clears the map and store of all rendered data layers
68
+ * @returns void
69
+ * */
70
+ clear(): void;
71
+ }
@@ -0,0 +1,118 @@
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
+ }
118
+ export {};
package/dist/common.d.ts CHANGED
@@ -1,98 +1,103 @@
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 interface TerraDrawModeRegisterConfig {
49
+ mode: string;
50
+ store: GeoJSONStore;
51
+ setDoubleClickToZoom: (enabled: boolean) => void;
52
+ setCursor: SetCursor;
53
+ onChange: StoreChangeHandler;
54
+ onSelect: (selectedId: string) => void;
55
+ onDeselect: (deselectedId: string) => void;
56
+ onFinish: (finishedId: string) => void;
57
+ project: Project;
58
+ unproject: Unproject;
59
+ coordinatePrecision: number;
60
+ }
61
+ export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped";
62
+ export interface TerraDrawCallbacks {
63
+ getState: () => TerraDrawModeState;
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, setMapDraggability: (enabled: boolean) => void) => void;
70
+ onDragEnd: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
71
+ onClear: () => void;
72
+ onReady?(): void;
73
+ }
74
+ export interface TerraDrawChanges {
75
+ created: GeoJSONStoreFeatures[];
76
+ updated: GeoJSONStoreFeatures[];
77
+ unchanged: GeoJSONStoreFeatures[];
78
+ deletedIds: FeatureId[];
79
+ }
80
+ export type TerraDrawStylingFunction = {
81
+ [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
82
+ };
83
+ export interface TerraDrawAdapter {
84
+ project: Project;
85
+ unproject: Unproject;
86
+ setCursor: SetCursor;
87
+ getLngLatFromEvent: GetLngLatFromEvent;
88
+ setDoubleClickToZoom: (enabled: boolean) => void;
89
+ getMapEventElement: () => HTMLElement;
90
+ register(callbacks: TerraDrawCallbacks): void;
91
+ unregister(): void;
92
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
93
+ clear(): void;
94
+ getCoordinatePrecision(): number;
95
+ }
96
+ export declare const SELECT_PROPERTIES: {
97
+ readonly SELECTED: "selected";
98
+ readonly MID_POINT: "midPoint";
99
+ readonly SELECTION_POINT: "selectionPoint";
100
+ };
101
+ export declare const POLYGON_PROPERTIES: {
102
+ CLOSING_POINT: string;
103
+ };
@@ -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;
@@ -0,0 +1,2 @@
1
+ import { GeoJSONStoreFeatures } from "../../terra-draw";
2
+ export declare function isValidLineStringFeature(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
@@ -0,0 +1,2 @@
1
+ import { GeoJSONStoreFeatures } from "../../terra-draw";
2
+ export declare function isValidPoint(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
@@ -0,0 +1,3 @@
1
+ import { GeoJSONStoreFeatures } from "../../terra-draw";
2
+ export declare function isValidPolygonFeature(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
3
+ export declare function isValidNonIntersectingPolygonFeature(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
@@ -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,8 @@
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, Unproject } from "../common";
3
+ import { JSONObject } from "../store/store";
4
+ export declare function getMidPointCoordinates(featureCoords: Position[], precision: number, project: Project, unproject: Unproject): Position[];
5
+ export declare function getMidPoints(selectedCoords: Position[], properties: (index: number) => JSONObject, precision: number, project: Project, unproject: Unproject): {
6
+ geometry: Point;
7
+ properties: JSONObject;
8
+ }[];
@@ -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;
@@ -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;