terra-draw 0.0.1-alpha.3 → 0.0.1-alpha.30
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.
- package/CHANGELOG.md +311 -0
- package/README.md +25 -4
- package/dist/adapters/common/adapter-listener.d.ts +22 -0
- package/dist/adapters/common/base-adapter.d.ts +31 -0
- package/dist/adapters/common/base.adapter.d.ts +47 -0
- package/dist/adapters/google-maps.adapter.d.ts +87 -38
- package/dist/adapters/leaflet.adapter.d.ts +98 -35
- package/dist/adapters/mapbox-gl.adapter.d.ts +85 -36
- package/dist/adapters/maplibre-gl.adapter.d.ts +72 -0
- package/dist/adapters/openlayers.adapter.d.ts +117 -0
- package/dist/common.d.ts +90 -99
- package/dist/extend-types.d.ts +4 -0
- package/dist/geometry/boolean/point-in-polygon.d.ts +2 -2
- package/dist/geometry/boolean/self-intersects.d.ts +2 -2
- package/dist/geometry/centroid.d.ts +2 -2
- package/dist/geometry/coordinates-identical.d.ts +2 -2
- package/dist/geometry/get-coordinates-as-points.d.ts +6 -6
- package/dist/geometry/get-midpoints.d.ts +8 -7
- package/dist/geometry/helpers.d.ts +4 -4
- package/dist/geometry/limit-decimal-precision.d.ts +1 -1
- package/dist/geometry/measure/haversine-distance.d.ts +2 -2
- package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -10
- package/dist/geometry/measure/pixel-distance.d.ts +7 -7
- package/dist/geometry/measure/rhumb-bearing.d.ts +2 -2
- package/dist/geometry/measure/rhumb-destination.d.ts +2 -2
- package/dist/geometry/measure/rhumb-distance.d.ts +2 -2
- package/dist/geometry/midpoint-coordinate.d.ts +3 -2
- package/dist/geometry/shape/create-circle.d.ts +8 -7
- package/dist/geometry/shape/great-circle-line.d.ts +12 -0
- package/dist/geometry/transform/rotate.d.ts +2 -2
- package/dist/geometry/transform/scale.d.ts +2 -2
- package/dist/modes/base.behavior.d.ts +19 -19
- package/dist/modes/base.mode.d.ts +46 -30
- package/dist/modes/circle/circle.mode.d.ts +48 -27
- package/dist/modes/click-bounding-box.behavior.d.ts +7 -7
- package/dist/modes/freehand/freehand.mode.d.ts +54 -29
- package/dist/modes/great-circle-snapping.behavior.d.ts +13 -0
- package/dist/modes/greatcircle/great-circle.mode.d.ts +57 -0
- package/dist/modes/linestring/linestring.mode.d.ts +60 -34
- package/dist/modes/pixel-distance.behavior.d.ts +7 -7
- package/dist/modes/point/point.mode.d.ts +38 -18
- package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -0
- package/dist/modes/polygon/polygon.mode.d.ts +63 -37
- package/dist/modes/rectangle/rectangle.mode.d.ts +48 -0
- package/dist/modes/render/render.mode.d.ts +36 -0
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +13 -13
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +17 -17
- package/dist/modes/select/behaviors/features-at-mouse-event.behavior.d.ts +15 -15
- package/dist/modes/select/behaviors/midpoint.behavior.d.ts +18 -18
- package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +13 -13
- package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +13 -13
- package/dist/modes/select/behaviors/selection-point.behavior.d.ts +18 -18
- package/dist/modes/select/select.mode.d.ts +89 -62
- package/dist/modes/snapping.behavior.d.ts +13 -13
- package/dist/modes/static/static.mode.d.ts +31 -13
- package/dist/store/spatial-index/quickselect.d.ts +2 -2
- package/dist/store/spatial-index/rbush.d.ts +35 -35
- package/dist/store/spatial-index/spatial-index.d.ts +18 -18
- package/dist/store/store.d.ts +50 -48
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +139 -47
- package/dist/terra-draw.modern.js +1 -1
- package/dist/terra-draw.modern.js.map +1 -1
- package/dist/terra-draw.module.js +1 -1
- package/dist/terra-draw.module.js.map +1 -1
- package/dist/terra-draw.umd.js +1 -1
- package/dist/terra-draw.umd.js.map +1 -1
- package/dist/util/geoms.d.ts +3 -3
- package/dist/util/id.d.ts +1 -1
- package/dist/util/styling.d.ts +2 -2
- package/{CONTRIBUTING.md → guides/CONTRIBUTING.md} +7 -7
- package/guides/DEVELOPMENT.md +156 -0
- package/guides/GETTING_STARTED.md +211 -0
- package/jest.config.ts +22 -22
- package/logo.png +0 -0
- package/package.json +151 -87
- package/readme.gif +0 -0
- package/scratch/release.sh +6 -0
- package/tsconfig.json +20 -12
- package/DEVELOPMENT.md +0 -77
- /package/{CODE_OF_CONDUCT.md → guides/CODE_OF_CONDUCT.md} +0 -0
|
@@ -1,35 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import L from "leaflet";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
private _map;
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction } from "../common";
|
|
2
|
+
import L from "leaflet";
|
|
3
|
+
import { TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
4
|
+
export declare class TerraDrawLeafletAdapter extends TerraDrawBaseAdapter {
|
|
5
|
+
constructor(config: {
|
|
6
|
+
lib: typeof L;
|
|
7
|
+
map: L.Map;
|
|
8
|
+
coordinatePrecision?: number;
|
|
9
|
+
minPixelDragDistance?: number;
|
|
10
|
+
});
|
|
11
|
+
private _lib;
|
|
12
|
+
private _map;
|
|
13
|
+
private _panes;
|
|
14
|
+
private _container;
|
|
15
|
+
private _layers;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a pane and its associated style sheet
|
|
18
|
+
* @param pane - The pane name
|
|
19
|
+
* @param zIndex - The zIndex value for the pane
|
|
20
|
+
* @returns The created style element
|
|
21
|
+
*/
|
|
22
|
+
private createPaneStyleSheet;
|
|
23
|
+
/**
|
|
24
|
+
* Clears the panes created by the adapter
|
|
25
|
+
* @returns void
|
|
26
|
+
* */
|
|
27
|
+
private clearPanes;
|
|
28
|
+
/**
|
|
29
|
+
* Clears the leaflet layers created by the adapter
|
|
30
|
+
* @returns void
|
|
31
|
+
* */
|
|
32
|
+
private clearLayers;
|
|
33
|
+
/**
|
|
34
|
+
* Styles a GeoJSON layer based on the styling function
|
|
35
|
+
* @param styling - The styling function
|
|
36
|
+
* */
|
|
37
|
+
private styleGeoJSONLayer;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
40
|
+
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
41
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
|
|
42
|
+
*/
|
|
43
|
+
getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
44
|
+
lng: number;
|
|
45
|
+
lat: number;
|
|
46
|
+
} | null;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the HTML container element of the Leaflet map.
|
|
49
|
+
* @returns The HTMLElement representing the map container.
|
|
50
|
+
*/
|
|
51
|
+
getMapContainer(): HTMLElement;
|
|
52
|
+
/**
|
|
53
|
+
* Enables or disables the draggable functionality of the map.
|
|
54
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
55
|
+
*/
|
|
56
|
+
setDraggability(enabled: boolean): void;
|
|
57
|
+
/**
|
|
58
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
59
|
+
* @param lng The longitude coordinate to project.
|
|
60
|
+
* @param lat The latitude coordinate to project.
|
|
61
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
62
|
+
*/
|
|
63
|
+
project(lng: number, lat: number): {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
69
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
70
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
71
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
72
|
+
*/
|
|
73
|
+
unproject(x: number, y: number): {
|
|
74
|
+
lng: number;
|
|
75
|
+
lat: number;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Sets the cursor style for the map container.
|
|
79
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
80
|
+
*/
|
|
81
|
+
setCursor(cursor: Parameters<SetCursor>[0]): void;
|
|
82
|
+
/**
|
|
83
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
84
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
85
|
+
*/
|
|
86
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
87
|
+
/**
|
|
88
|
+
* Renders GeoJSON features on the map using the provided styling configuration.
|
|
89
|
+
* @param changes An object containing arrays of created, updated, and unchanged features to render.
|
|
90
|
+
* @param styling An object mapping draw modes to feature styling functions
|
|
91
|
+
*/
|
|
92
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
93
|
+
/**
|
|
94
|
+
* Clears the map and store of all rendered data layers
|
|
95
|
+
* @returns void
|
|
96
|
+
* */
|
|
97
|
+
clear(): void;
|
|
98
|
+
}
|
|
@@ -1,36 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import mapboxgl from "mapbox-gl";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction } from "../common";
|
|
2
|
+
import mapboxgl from "mapbox-gl";
|
|
3
|
+
import { TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
4
|
+
export declare class TerraDrawMapboxGLAdapter extends TerraDrawBaseAdapter {
|
|
5
|
+
constructor(config: {
|
|
6
|
+
map: mapboxgl.Map;
|
|
7
|
+
coordinatePrecision?: number;
|
|
8
|
+
});
|
|
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
|
+
/**
|
|
26
|
+
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
27
|
+
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
28
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
|
|
29
|
+
*/
|
|
30
|
+
getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
31
|
+
lng: number;
|
|
32
|
+
lat: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the HTML container element of the Leaflet map.
|
|
36
|
+
* @returns The HTMLElement representing the map container.
|
|
37
|
+
*/
|
|
38
|
+
getMapContainer(): HTMLElement;
|
|
39
|
+
/**
|
|
40
|
+
* Enables or disables the draggable functionality of the map.
|
|
41
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
42
|
+
*/
|
|
43
|
+
setDraggability(enabled: boolean): void;
|
|
44
|
+
/**
|
|
45
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
46
|
+
* @param lng The longitude coordinate to project.
|
|
47
|
+
* @param lat The latitude coordinate to project.
|
|
48
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
49
|
+
*/
|
|
50
|
+
project(lng: number, lat: number): {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
56
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
57
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
58
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
59
|
+
*/
|
|
60
|
+
unproject(x: number, y: number): {
|
|
61
|
+
lng: number;
|
|
62
|
+
lat: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Sets the cursor style for the map container.
|
|
66
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
67
|
+
*/
|
|
68
|
+
setCursor(style: Parameters<SetCursor>[0]): void;
|
|
69
|
+
/**
|
|
70
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
71
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
72
|
+
*/
|
|
73
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
74
|
+
/**
|
|
75
|
+
* Renders GeoJSON features on the map using the provided styling configuration.
|
|
76
|
+
* @param changes An object containing arrays of created, updated, and unchanged features to render.
|
|
77
|
+
* @param styling An object mapping draw modes to feature styling functions
|
|
78
|
+
*/
|
|
79
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
80
|
+
/**
|
|
81
|
+
* Clears the map and store of all rendered data layers
|
|
82
|
+
* @returns void
|
|
83
|
+
* */
|
|
84
|
+
clear(): void;
|
|
85
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
|
|
2
|
+
import { Map } from "maplibre-gl";
|
|
3
|
+
import { TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
4
|
+
export declare class TerraDrawMapLibreGLAdapter extends TerraDrawBaseAdapter {
|
|
5
|
+
private mapboxglAdapter;
|
|
6
|
+
constructor(config: {
|
|
7
|
+
map: Map;
|
|
8
|
+
coordinatePrecision?: number;
|
|
9
|
+
});
|
|
10
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
11
|
+
unregister(): void;
|
|
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 container element of the Leaflet map.
|
|
23
|
+
* @returns The HTMLElement representing the map container.
|
|
24
|
+
*/
|
|
25
|
+
getMapContainer(): HTMLElement;
|
|
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,117 @@
|
|
|
1
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction } 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 { 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
|
+
coordinatePrecision?: number;
|
|
29
|
+
});
|
|
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
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves the HTML container element of the Leaflet map.
|
|
67
|
+
* @returns The HTMLElement representing the map container.
|
|
68
|
+
*/
|
|
69
|
+
getMapContainer(): HTMLElement;
|
|
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
|
+
}
|
|
117
|
+
export {};
|
package/dist/common.d.ts
CHANGED
|
@@ -1,99 +1,90 @@
|
|
|
1
|
-
import { StoreChangeHandler, GeoJSONStore, GeoJSONStoreFeatures } from "./store/store";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
export
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
[mode: string]: TerraDrawAdapterStyling;
|
|
92
|
-
}): void;
|
|
93
|
-
}
|
|
94
|
-
export declare const SELECT_PROPERTIES: {
|
|
95
|
-
readonly SELECTED: "selected";
|
|
96
|
-
readonly MID_POINT: "midPoint";
|
|
97
|
-
readonly SELECTION_POINT: "selectionPoint";
|
|
98
|
-
};
|
|
99
|
-
export {};
|
|
1
|
+
import { StoreChangeHandler, GeoJSONStore, GeoJSONStoreFeatures } from "./store/store";
|
|
2
|
+
export 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: "neither" | "left" | "middle" | "right";
|
|
22
|
+
heldKeys: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface TerraDrawKeyboardEvent {
|
|
25
|
+
key: string;
|
|
26
|
+
}
|
|
27
|
+
export type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer" | "wait") => void;
|
|
28
|
+
export type Project = (lng: number, lat: number) => {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
export type Unproject = (x: number, y: number) => {
|
|
33
|
+
lat: number;
|
|
34
|
+
lng: number;
|
|
35
|
+
};
|
|
36
|
+
export type GetLngLatFromEvent = (event: PointerEvent | MouseEvent) => {
|
|
37
|
+
lng: number;
|
|
38
|
+
lat: number;
|
|
39
|
+
} | null;
|
|
40
|
+
export interface TerraDrawModeRegisterConfig {
|
|
41
|
+
mode: string;
|
|
42
|
+
store: GeoJSONStore;
|
|
43
|
+
setDoubleClickToZoom: (enabled: boolean) => void;
|
|
44
|
+
setCursor: SetCursor;
|
|
45
|
+
onChange: StoreChangeHandler;
|
|
46
|
+
onSelect: (selectedId: string) => void;
|
|
47
|
+
onDeselect: (deselectedId: string) => void;
|
|
48
|
+
project: Project;
|
|
49
|
+
unproject: Unproject;
|
|
50
|
+
}
|
|
51
|
+
export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selected" | "stopped";
|
|
52
|
+
export interface TerraDrawCallbacks {
|
|
53
|
+
getState: () => TerraDrawModeState;
|
|
54
|
+
onKeyUp: (event: TerraDrawKeyboardEvent) => void;
|
|
55
|
+
onKeyDown: (event: TerraDrawKeyboardEvent) => void;
|
|
56
|
+
onClick: (event: TerraDrawMouseEvent) => void;
|
|
57
|
+
onMouseMove: (event: TerraDrawMouseEvent) => void;
|
|
58
|
+
onDragStart: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
|
|
59
|
+
onDrag: (event: TerraDrawMouseEvent) => void;
|
|
60
|
+
onDragEnd: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void;
|
|
61
|
+
onClear: () => void;
|
|
62
|
+
}
|
|
63
|
+
export interface TerraDrawChanges {
|
|
64
|
+
created: GeoJSONStoreFeatures[];
|
|
65
|
+
updated: GeoJSONStoreFeatures[];
|
|
66
|
+
unchanged: GeoJSONStoreFeatures[];
|
|
67
|
+
deletedIds: string[];
|
|
68
|
+
}
|
|
69
|
+
export type TerraDrawStylingFunction = {
|
|
70
|
+
[mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
|
|
71
|
+
};
|
|
72
|
+
export interface TerraDrawAdapter {
|
|
73
|
+
project: Project;
|
|
74
|
+
unproject: Unproject;
|
|
75
|
+
setCursor: SetCursor;
|
|
76
|
+
setDoubleClickToZoom: (enabled: boolean) => void;
|
|
77
|
+
getMapContainer: () => HTMLElement;
|
|
78
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
79
|
+
unregister(): void;
|
|
80
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
81
|
+
clear(): void;
|
|
82
|
+
}
|
|
83
|
+
export declare const SELECT_PROPERTIES: {
|
|
84
|
+
readonly SELECTED: "selected";
|
|
85
|
+
readonly MID_POINT: "midPoint";
|
|
86
|
+
readonly SELECTION_POINT: "selectionPoint";
|
|
87
|
+
};
|
|
88
|
+
export declare const POLYGON_PROPERTIES: {
|
|
89
|
+
CLOSING_POINT: string;
|
|
90
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GetLngLatFromEvent, Project, SetCursor, TerraDrawChanges, TerraDrawStylingFunction, Unproject } from "./common";
|
|
2
|
+
import { BehaviorConfig } from "./modes/base.behavior";
|
|
3
|
+
import { GeoJSONStoreFeatures } from "./store/store";
|
|
4
|
+
export { BehaviorConfig, GeoJSONStoreFeatures, TerraDrawChanges, TerraDrawStylingFunction, Project, Unproject, SetCursor, GetLngLatFromEvent, };
|
|
@@ -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;
|