terra-draw 0.0.1-alpha.9 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/Dockerfile +8 -0
- package/.devcontainer/devcontainer.json +27 -0
- package/.devcontainer/post-create.sh +16 -0
- package/README.md +23 -13
- package/dist/adapters/arcgis-maps-sdk.adapter.d.ts +106 -0
- package/dist/adapters/google-maps.adapter.d.ts +90 -39
- package/dist/adapters/leaflet.adapter.d.ts +99 -33
- package/dist/adapters/mapbox-gl.adapter.d.ts +91 -37
- package/dist/adapters/maplibre-gl.adapter.d.ts +72 -0
- package/dist/adapters/openlayers.adapter.d.ts +120 -0
- package/dist/common.d.ts +118 -98
- package/dist/geometry/boolean/is-valid-coordinate.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 +14 -7
- package/dist/geometry/helpers.d.ts +4 -4
- package/dist/geometry/limit-decimal-precision.d.ts +1 -1
- package/dist/geometry/measure/area.d.ts +2 -0
- package/dist/geometry/measure/bearing.d.ts +9 -0
- package/dist/geometry/measure/destination.d.ts +2 -0
- 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/measure/slice-along.d.ts +2 -0
- package/dist/geometry/midpoint-coordinate.d.ts +4 -2
- package/dist/geometry/project/web-mercator.d.ts +20 -0
- package/dist/geometry/shape/create-bbox.d.ts +10 -0
- package/dist/geometry/shape/create-circle.d.ts +13 -7
- package/dist/geometry/shape/great-circle-coordinates.d.ts +2 -0
- package/dist/geometry/shape/web-mercator-distortion.d.ts +2 -0
- package/dist/geometry/transform/rotate.d.ts +9 -2
- package/dist/geometry/transform/scale.d.ts +9 -2
- package/dist/geometry/web-mercator-centroid.d.ts +11 -0
- package/dist/modes/base.behavior.d.ts +21 -19
- package/dist/modes/base.mode.d.ts +66 -33
- package/dist/modes/circle/circle.mode.d.ts +66 -37
- package/dist/modes/click-bounding-box.behavior.d.ts +6 -7
- package/dist/modes/freehand/freehand.mode.d.ts +63 -43
- package/dist/modes/insert-coordinates.behavior.d.ts +9 -0
- package/dist/modes/linestring/linestring.mode.d.ts +78 -47
- package/dist/modes/pixel-distance.behavior.d.ts +7 -7
- package/dist/modes/point/point.mode.d.ts +44 -26
- package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -19
- package/dist/modes/polygon/polygon.mode.d.ts +69 -51
- package/dist/modes/rectangle/rectangle.mode.d.ts +55 -0
- package/dist/modes/render/render.mode.d.ts +52 -23
- package/dist/modes/select/behaviors/drag-coordinate-resize.behavior.d.ts +62 -0
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +20 -13
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +20 -17
- package/dist/modes/select/behaviors/{features-at-mouse-event.behavior.d.ts → feature-at-pointer-event.behavior.d.ts} +15 -15
- package/dist/modes/select/behaviors/midpoint.behavior.d.ts +19 -18
- package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +14 -13
- package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +14 -13
- package/dist/modes/select/behaviors/selection-point.behavior.d.ts +19 -18
- package/dist/modes/select/select.mode.d.ts +119 -78
- package/dist/modes/snapping.behavior.d.ts +16 -13
- package/dist/modes/static/static.mode.d.ts +32 -30
- 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-feature-validation.d.ts +16 -0
- package/dist/store/store.d.ts +59 -48
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +222 -48
- 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/dist/validations/linestring.validation.d.ts +2 -0
- package/dist/validations/max-size.validation.d.ts +2 -0
- package/dist/validations/min-size.validation.d.ts +2 -0
- package/dist/validations/not-self-intersecting.validation.d.ts +2 -0
- package/dist/validations/point.validation.d.ts +2 -0
- package/dist/validations/polygon.validation.d.ts +3 -0
- package/e2e/README.md +29 -0
- package/e2e/package-lock.json +4274 -0
- package/e2e/package.json +26 -0
- package/e2e/playwright.config.ts +77 -0
- package/e2e/public/favicon.ico +0 -0
- package/e2e/public/index.html +52 -0
- package/e2e/tests/leaflet.spec.ts +657 -0
- package/e2e/tests/setup.ts +181 -0
- package/e2e/webpack.config.js +36 -0
- package/jest.nocheck.config.ts +17 -0
- package/package.json +159 -87
- package/readme.gif +0 -0
- package/tsconfig.json +25 -12
- package/CODE_OF_CONDUCT.md +0 -36
- package/CONTRIBUTING.md +0 -17
- package/DEVELOPMENT.md +0 -77
- package/dist/bundle.js +0 -6
- package/dist/bundle.js.LICENSE.txt +0 -4
- package/dist/geometry/create-circle.d.ts +0 -6
- package/dist/geometry/get-pixel-distance-to-line.d.ts +0 -10
- package/dist/geometry/get-pixel-distance.d.ts +0 -7
- package/dist/geometry/haversine-distance.d.ts +0 -1
- package/dist/geometry/point-in-polygon.d.ts +0 -1
- package/dist/geometry/self-intersects.d.ts +0 -2
- package/dist/modes/circle.mode.d.ts +0 -18
- package/dist/modes/freehand.mode.d.ts +0 -20
- package/dist/modes/line-string.mode.d.ts +0 -21
- package/dist/modes/point.mode.d.ts +0 -14
- package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +0 -11
- package/dist/modes/polygon.mode.d.ts +0 -21
- package/dist/modes/select.mode.d.ts +0 -21
- package/dist/modes/static.mode.d.ts +0 -10
- package/jest.config.ts +0 -27
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "terra-draw",
|
|
3
|
+
"dockerFile": "Dockerfile",
|
|
4
|
+
"build": {
|
|
5
|
+
"args": {
|
|
6
|
+
"NODE_MAJOR_VERSION": "20"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"postCreateCommand": [".devcontainer/post-create.sh"],
|
|
10
|
+
"portsAttributes": {
|
|
11
|
+
"3000": {
|
|
12
|
+
"label": "Docs"
|
|
13
|
+
},
|
|
14
|
+
"9000": {
|
|
15
|
+
"label": "Development"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"customizations": {
|
|
19
|
+
"vscode": {
|
|
20
|
+
"extensions": [
|
|
21
|
+
"dbaeumer.vscode-eslint",
|
|
22
|
+
"esbenp.prettier-vscode",
|
|
23
|
+
"mikestead.dotenv"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -eo pipefail
|
|
4
|
+
|
|
5
|
+
# when in a VS Code or GitHub Codespaces devcontainer
|
|
6
|
+
if [ -n "${REMOTE_CONTAINERS}" ] || [ -n "${CODESPACES}" ]; then
|
|
7
|
+
this_dir=$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)
|
|
8
|
+
workspace_root=$(realpath ${this_dir}/..)
|
|
9
|
+
|
|
10
|
+
# perform additional one-time setup just after
|
|
11
|
+
# the devcontainer is created
|
|
12
|
+
npm ci --prefix "${workspace_root}" # install lib node dependencies
|
|
13
|
+
npm ci --prefix "${workspace_root}/development" # install dev node dependencies
|
|
14
|
+
touch "${workspace_root}/development/.env" # ensure dev .env file exists
|
|
15
|
+
|
|
16
|
+
fi
|
package/README.md
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
<img src="
|
|
1
|
+
<img src="./logo.png" alt="Terra Draw Logo" width="400"/>
|
|
2
2
|
|
|
3
3
|

|
|
4
|
+
[](https://badge.fury.io/js/terra-draw)
|
|
4
5
|
|
|
5
6
|
Frictionless map drawing across mapping libraries.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Terra Draw centralizes map drawing logic and provides a host of out-of-the-box drawing modes that work across different JavaScript mapping libraries. It also allows you to bring your own modes!
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+

|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
### Library Support
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
npm install terra-draw
|
|
15
|
-
```
|
|
14
|
+
Terra Draw uses the concept of 'adapters' to allow it to work with a host of different mapping libraries. Currently supported are:
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
- [Leaflet](https://leafletjs.com/) v1
|
|
17
|
+
- [OpenLayers](https://openlayers.org/) v7
|
|
18
|
+
- [Mapbox GL JS](https://www.mapbox.com/mapbox-gljs) v2
|
|
19
|
+
- [MapLibre](https://maplibre.org/maplibre-gl-js/docs/) v2/v3
|
|
20
|
+
- [Google Maps JS API](https://developers.google.com/maps/documentation/javascript/overview) v3
|
|
21
|
+
- [ArcGIS JavaScript SDK](https://developers.arcgis.com/javascript/latest/) v4 (MapView)
|
|
18
22
|
|
|
19
|
-
###
|
|
23
|
+
### Getting Started
|
|
20
24
|
|
|
21
|
-
Please see the [the
|
|
25
|
+
Please see the [the getting started guide](./guides/1.GETTING_STARTED.md) - this provides a host of information on how to get up and running with Terra Draw.
|
|
22
26
|
|
|
23
|
-
### Contributing
|
|
27
|
+
### Development & Contributing
|
|
28
|
+
|
|
29
|
+
* For development, please see the [the development documentation](./guides/7.DEVELOPMENT.md)
|
|
30
|
+
* For guidance on contributing, please see the [the contributing documentation](./guides/7.DEVELOPMENT.md#contributing)
|
|
24
31
|
|
|
25
|
-
Please see the [the contributing documentation](./CONTRIBUTING.md)
|
|
26
32
|
|
|
27
33
|
### Project Website
|
|
28
34
|
|
|
29
|
-
You can
|
|
35
|
+
You can check out the official Terra Draw website at [terradraw.io](https://www.terradraw.io). If you are interested in contributing to the website please see [this repository](https://www.github.com/JamesLMilner/terra-draw-website).
|
|
36
|
+
|
|
37
|
+
### Contact
|
|
38
|
+
|
|
39
|
+
Email: [contact@terradraw.io](mailto:contact@terradraw.io)
|
|
30
40
|
|
|
31
41
|
### License
|
|
32
42
|
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { SetCursor, TerraDrawCallbacks, TerraDrawChanges, TerraDrawStylingFunction } from "../common";
|
|
2
|
+
import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
3
|
+
import MapView from "@arcgis/core/views/MapView";
|
|
4
|
+
import Point from "@arcgis/core/geometry/Point";
|
|
5
|
+
import Polyline from "@arcgis/core/geometry/Polyline";
|
|
6
|
+
import Polygon from "@arcgis/core/geometry/Polygon";
|
|
7
|
+
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
|
|
8
|
+
import Graphic from "@arcgis/core/Graphic";
|
|
9
|
+
import SimpleMarkerSymbol from "@arcgis/core/symbols/SimpleMarkerSymbol";
|
|
10
|
+
import SimpleLineSymbol from "@arcgis/core/symbols/SimpleLineSymbol";
|
|
11
|
+
import SimpleFillSymbol from "@arcgis/core/symbols/SimpleFillSymbol";
|
|
12
|
+
import Color from "@arcgis/core/Color";
|
|
13
|
+
type InjectableArcGISMapsSDK = {
|
|
14
|
+
GraphicsLayer: typeof GraphicsLayer;
|
|
15
|
+
Point: typeof Point;
|
|
16
|
+
Polyline: typeof Polyline;
|
|
17
|
+
Polygon: typeof Polygon;
|
|
18
|
+
SimpleLineSymbol: typeof SimpleLineSymbol;
|
|
19
|
+
SimpleMarkerSymbol: typeof SimpleMarkerSymbol;
|
|
20
|
+
SimpleFillSymbol: typeof SimpleFillSymbol;
|
|
21
|
+
Graphic: typeof Graphic;
|
|
22
|
+
Color: typeof Color;
|
|
23
|
+
};
|
|
24
|
+
export declare class TerraDrawArcGISMapsSDKAdapter extends TerraDrawBaseAdapter {
|
|
25
|
+
private readonly _lib;
|
|
26
|
+
private readonly _mapView;
|
|
27
|
+
private readonly _container;
|
|
28
|
+
private readonly _featureIdAttributeName;
|
|
29
|
+
private readonly _featureLayerName;
|
|
30
|
+
private readonly _featureLayer;
|
|
31
|
+
private _dragEnabled;
|
|
32
|
+
private _zoomEnabled;
|
|
33
|
+
private _dragHandler;
|
|
34
|
+
private _doubleClickHandler;
|
|
35
|
+
constructor(config: {
|
|
36
|
+
map: MapView;
|
|
37
|
+
lib: InjectableArcGISMapsSDK;
|
|
38
|
+
} & BaseAdapterConfig);
|
|
39
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
40
|
+
unregister(): void;
|
|
41
|
+
getCoordinatePrecision(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
44
|
+
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
45
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
|
|
46
|
+
*/
|
|
47
|
+
getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
48
|
+
lng: number;
|
|
49
|
+
lat: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the HTML element of the ArcGIS element that handles interaction events
|
|
53
|
+
* @returns The HTMLElement representing the map container.
|
|
54
|
+
*/
|
|
55
|
+
getMapEventElement(): HTMLElement;
|
|
56
|
+
/**
|
|
57
|
+
* Enables or disables the draggable functionality of the map.
|
|
58
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
59
|
+
*/
|
|
60
|
+
setDraggability(enabled: boolean): void;
|
|
61
|
+
/**
|
|
62
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
63
|
+
* @param lng The longitude coordinate to project.
|
|
64
|
+
* @param lat The latitude coordinate to project.
|
|
65
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
66
|
+
*/
|
|
67
|
+
project(lng: number, lat: number): {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
73
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
74
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
75
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
76
|
+
*/
|
|
77
|
+
unproject(x: number, y: number): {
|
|
78
|
+
lng: number;
|
|
79
|
+
lat: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Sets the cursor style for the map container.
|
|
83
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
84
|
+
*/
|
|
85
|
+
setCursor(cursor: Parameters<SetCursor>[0]): void;
|
|
86
|
+
/**
|
|
87
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
88
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
89
|
+
*/
|
|
90
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
91
|
+
/**
|
|
92
|
+
* Renders GeoJSON features on the map using the provided styling configuration.
|
|
93
|
+
* @param changes An object containing arrays of created, updated, and unchanged features to render.
|
|
94
|
+
* @param styling An object mapping draw modes to feature styling functions
|
|
95
|
+
*/
|
|
96
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
97
|
+
/**
|
|
98
|
+
* Clears the map and store of all rendered data layers
|
|
99
|
+
* @returns void
|
|
100
|
+
* */
|
|
101
|
+
clear(): void;
|
|
102
|
+
private removeFeatureById;
|
|
103
|
+
private addFeature;
|
|
104
|
+
private getColorFromHex;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
@@ -1,39 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
|
|
2
|
+
import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
3
|
+
export declare class TerraDrawGoogleMapsAdapter extends TerraDrawBaseAdapter {
|
|
4
|
+
constructor(config: {
|
|
5
|
+
lib: typeof google.maps;
|
|
6
|
+
map: google.maps.Map;
|
|
7
|
+
} & BaseAdapterConfig);
|
|
8
|
+
private _cursor;
|
|
9
|
+
private _cursorStyleSheet;
|
|
10
|
+
private _lib;
|
|
11
|
+
private _map;
|
|
12
|
+
private _overlay;
|
|
13
|
+
private _clickEventListener;
|
|
14
|
+
private _mouseMoveEventListener;
|
|
15
|
+
private get _layers();
|
|
16
|
+
/**
|
|
17
|
+
* Generates an SVG path string for a circle with the given center coordinates and radius.
|
|
18
|
+
* Based off this StackOverflow answer: https://stackoverflow.com/a/27905268/1363484
|
|
19
|
+
* @param cx The x-coordinate of the circle's center.
|
|
20
|
+
* @param cy The y-coordinate of the circle's center.
|
|
21
|
+
* @param r The radius of the circle.
|
|
22
|
+
* @returns The SVG path string representing the circle.
|
|
23
|
+
*/
|
|
24
|
+
private circlePath;
|
|
25
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
26
|
+
unregister(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
29
|
+
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
30
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
|
|
31
|
+
*/
|
|
32
|
+
getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
33
|
+
lng: number;
|
|
34
|
+
lat: number;
|
|
35
|
+
} | null;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the HTML element of the Google Map element that handles interaction events
|
|
38
|
+
* @returns The HTMLElement representing the map container.
|
|
39
|
+
*/
|
|
40
|
+
getMapEventElement(): HTMLDivElement;
|
|
41
|
+
/**
|
|
42
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
43
|
+
* @param lng The longitude coordinate to project.
|
|
44
|
+
* @param lat The latitude coordinate to project.
|
|
45
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
46
|
+
*/
|
|
47
|
+
project(lng: number, lat: number): {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
53
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
54
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
55
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
56
|
+
*/
|
|
57
|
+
unproject(x: number, y: number): {
|
|
58
|
+
lng: number;
|
|
59
|
+
lat: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Sets the cursor style for the map container.
|
|
63
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
64
|
+
*/
|
|
65
|
+
setCursor(cursor: Parameters<SetCursor>[0]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
68
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
69
|
+
*/
|
|
70
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* Enables or disables the draggable functionality of the map.
|
|
73
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
74
|
+
*/
|
|
75
|
+
setDraggability(enabled: boolean): void;
|
|
76
|
+
private renderedFeatureIds;
|
|
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
|
+
private clearLayers;
|
|
84
|
+
/**
|
|
85
|
+
* Clears the map and store of all rendered data layers
|
|
86
|
+
* @returns void
|
|
87
|
+
* */
|
|
88
|
+
clear(): void;
|
|
89
|
+
getCoordinatePrecision(): number;
|
|
90
|
+
}
|
|
@@ -1,33 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import L from "leaflet";
|
|
3
|
-
import {
|
|
4
|
-
export declare class TerraDrawLeafletAdapter
|
|
5
|
-
constructor(config: {
|
|
6
|
-
lib: typeof L;
|
|
7
|
-
map: L.Map;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
|
|
2
|
+
import L from "leaflet";
|
|
3
|
+
import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
4
|
+
export declare class TerraDrawLeafletAdapter extends TerraDrawBaseAdapter {
|
|
5
|
+
constructor(config: {
|
|
6
|
+
lib: typeof L;
|
|
7
|
+
map: L.Map;
|
|
8
|
+
} & BaseAdapterConfig);
|
|
9
|
+
private _lib;
|
|
10
|
+
private _map;
|
|
11
|
+
private _panes;
|
|
12
|
+
private _container;
|
|
13
|
+
private _layers;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a pane and its associated style sheet
|
|
16
|
+
* @param pane - The pane name
|
|
17
|
+
* @param zIndex - The zIndex value for the pane
|
|
18
|
+
* @returns The created style element
|
|
19
|
+
*/
|
|
20
|
+
private createPaneStyleSheet;
|
|
21
|
+
/**
|
|
22
|
+
* Clears the panes created by the adapter
|
|
23
|
+
* @returns void
|
|
24
|
+
* */
|
|
25
|
+
private clearPanes;
|
|
26
|
+
/**
|
|
27
|
+
* Clears the leaflet layers created by the adapter
|
|
28
|
+
* @returns void
|
|
29
|
+
* */
|
|
30
|
+
private clearLayers;
|
|
31
|
+
/**
|
|
32
|
+
* Styles a GeoJSON layer based on the styling function
|
|
33
|
+
* @param styling - The styling function
|
|
34
|
+
* */
|
|
35
|
+
private styleGeoJSONLayer;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
38
|
+
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
39
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
|
|
40
|
+
*/
|
|
41
|
+
getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
42
|
+
lng: number;
|
|
43
|
+
lat: number;
|
|
44
|
+
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves the HTML element of the Leaflet element that handles interaction events
|
|
47
|
+
* @returns The HTMLElement representing the map container.
|
|
48
|
+
*/
|
|
49
|
+
getMapEventElement(): HTMLElement;
|
|
50
|
+
/**
|
|
51
|
+
* Enables or disables the draggable functionality of the map.
|
|
52
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
53
|
+
*/
|
|
54
|
+
setDraggability(enabled: boolean): void;
|
|
55
|
+
/**
|
|
56
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
57
|
+
* @param lng The longitude coordinate to project.
|
|
58
|
+
* @param lat The latitude coordinate to project.
|
|
59
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
60
|
+
*/
|
|
61
|
+
project(lng: number, lat: number): {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
67
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
68
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
69
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
70
|
+
*/
|
|
71
|
+
unproject(x: number, y: number): {
|
|
72
|
+
lng: number;
|
|
73
|
+
lat: number;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Sets the cursor style for the map container.
|
|
77
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
78
|
+
*/
|
|
79
|
+
setCursor(cursor: Parameters<SetCursor>[0]): void;
|
|
80
|
+
/**
|
|
81
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
82
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
83
|
+
*/
|
|
84
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
85
|
+
/**
|
|
86
|
+
* Renders GeoJSON features on the map using the provided styling configuration.
|
|
87
|
+
* @param changes An object containing arrays of created, updated, and unchanged features to render.
|
|
88
|
+
* @param styling An object mapping draw modes to feature styling functions
|
|
89
|
+
*/
|
|
90
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
91
|
+
/**
|
|
92
|
+
* Clears the map and store of all rendered data layers
|
|
93
|
+
* @returns void
|
|
94
|
+
* */
|
|
95
|
+
clear(): void;
|
|
96
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
97
|
+
getCoordinatePrecision(): number;
|
|
98
|
+
unregister(): void;
|
|
99
|
+
}
|
|
@@ -1,37 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import mapboxgl from "mapbox-gl";
|
|
3
|
-
import {
|
|
4
|
-
export declare class TerraDrawMapboxGLAdapter
|
|
5
|
-
constructor(config: {
|
|
6
|
-
map: mapboxgl.Map;
|
|
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
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
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
|
+
getCoordinatePrecision(): number;
|
|
89
|
+
unregister(): void;
|
|
90
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
91
|
+
}
|