terra-draw 0.0.1-alpha.6 → 0.0.1-alpha.60
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 +21 -0
- package/.devcontainer/post-create.sh +16 -0
- package/README.md +30 -6
- package/dist/adapters/arcgis-maps-sdk.adapter.d.ts +105 -0
- package/dist/adapters/common/adapter-listener.d.ts +22 -0
- package/dist/adapters/common/base.adapter.d.ts +59 -0
- package/dist/adapters/google-maps.adapter.d.ts +90 -39
- package/dist/adapters/leaflet.adapter.d.ts +97 -33
- package/dist/adapters/mapbox-gl.adapter.d.ts +89 -37
- package/dist/adapters/maplibre-gl.adapter.d.ts +71 -0
- package/dist/adapters/openlayers.adapter.d.ts +118 -0
- package/dist/common.d.ts +103 -98
- package/dist/geometry/boolean/is-valid-coordinate.d.ts +4 -0
- package/dist/geometry/boolean/is-valid-linestring-feature.d.ts +2 -0
- package/dist/geometry/boolean/is-valid-point.d.ts +2 -0
- package/dist/geometry/boolean/is-valid-polygon-feature.d.ts +3 -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-bbox.d.ts +10 -0
- package/dist/geometry/shape/create-circle.d.ts +7 -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 +62 -33
- package/dist/modes/circle/circle.mode.d.ts +55 -35
- package/dist/modes/click-bounding-box.behavior.d.ts +6 -7
- package/dist/modes/freehand/freehand.mode.d.ts +63 -37
- package/dist/modes/great-circle-snapping.behavior.d.ts +14 -0
- package/dist/modes/greatcircle/great-circle.mode.d.ts +64 -0
- package/dist/modes/linestring/linestring.mode.d.ts +67 -40
- 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 +70 -49
- 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 +31 -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 +117 -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 +220 -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/e2e/README.md +29 -0
- package/e2e/package-lock.json +4249 -0
- package/e2e/package.json +26 -0
- package/e2e/playwright.config.ts +77 -0
- package/e2e/public/index.html +53 -0
- package/e2e/src/index.ts +165 -0
- package/e2e/tests/leaflet.spec.ts +413 -0
- package/e2e/tests/setup.ts +164 -0
- package/e2e/webpack.config.js +36 -0
- package/jest.nocheck.config.ts +17 -0
- package/package.json +157 -87
- package/readme.gif +0 -0
- package/tsconfig.json +17 -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,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "terra-draw",
|
|
3
|
+
"dockerFile": "Dockerfile",
|
|
4
|
+
"build": {
|
|
5
|
+
"args": { "NODE_MAJOR_VERSION": "18" }
|
|
6
|
+
},
|
|
7
|
+
"postCreateCommand": [".devcontainer/post-create.sh"],
|
|
8
|
+
"portsAttributes": {
|
|
9
|
+
"3000": { "label": "Docs" },
|
|
10
|
+
"9000": { "label": "Development" }
|
|
11
|
+
},
|
|
12
|
+
"customizations": {
|
|
13
|
+
"vscode": {
|
|
14
|
+
"extensions": [
|
|
15
|
+
"dbaeumer.vscode-eslint",
|
|
16
|
+
"esbenp.prettier-vscode",
|
|
17
|
+
"mikestead.dotenv"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -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,18 +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
|
+
Terra Draw uses the concept of 'adapters' to allow it to work with a host of different mapping libraries. Currently supported are:
|
|
14
15
|
|
|
15
|
-
|
|
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/projects/maplibre-gl-js/) 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)
|
|
22
|
+
|
|
23
|
+
### Getting Started
|
|
24
|
+
|
|
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.
|
|
26
|
+
|
|
27
|
+
### Development & Contributing
|
|
28
|
+
|
|
29
|
+
* For development, please see the [the development documentation](./guides/6.DEVELOPMENT.md)
|
|
30
|
+
* For guidance on contributing, please see the [the contributing documentation](./guides/CONTRIBUTING.md)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Project Website
|
|
34
|
+
|
|
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)
|
|
16
40
|
|
|
17
41
|
### License
|
|
18
42
|
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
/**
|
|
42
|
+
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
43
|
+
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
44
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
|
|
45
|
+
*/
|
|
46
|
+
getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
47
|
+
lng: number;
|
|
48
|
+
lat: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the HTML element of the ArcGIS element that handles interaction events
|
|
52
|
+
* @returns The HTMLElement representing the map container.
|
|
53
|
+
*/
|
|
54
|
+
getMapEventElement(): HTMLElement;
|
|
55
|
+
/**
|
|
56
|
+
* Enables or disables the draggable functionality of the map.
|
|
57
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
58
|
+
*/
|
|
59
|
+
setDraggability(enabled: boolean): void;
|
|
60
|
+
/**
|
|
61
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
62
|
+
* @param lng The longitude coordinate to project.
|
|
63
|
+
* @param lat The latitude coordinate to project.
|
|
64
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
65
|
+
*/
|
|
66
|
+
project(lng: number, lat: number): {
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
72
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
73
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
74
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
75
|
+
*/
|
|
76
|
+
unproject(x: number, y: number): {
|
|
77
|
+
lng: number;
|
|
78
|
+
lat: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Sets the cursor style for the map container.
|
|
82
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
83
|
+
*/
|
|
84
|
+
setCursor(cursor: Parameters<SetCursor>[0]): void;
|
|
85
|
+
/**
|
|
86
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
87
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
88
|
+
*/
|
|
89
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
90
|
+
/**
|
|
91
|
+
* Renders GeoJSON features on the map using the provided styling configuration.
|
|
92
|
+
* @param changes An object containing arrays of created, updated, and unchanged features to render.
|
|
93
|
+
* @param styling An object mapping draw modes to feature styling functions
|
|
94
|
+
*/
|
|
95
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
96
|
+
/**
|
|
97
|
+
* Clears the map and store of all rendered data layers
|
|
98
|
+
* @returns void
|
|
99
|
+
* */
|
|
100
|
+
clear(): void;
|
|
101
|
+
private removeFeatureById;
|
|
102
|
+
private addFeature;
|
|
103
|
+
private getColorFromHex;
|
|
104
|
+
}
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class AdapterListener<Callback extends (...args: any[]) => any> {
|
|
2
|
+
name: string;
|
|
3
|
+
callback: (...args: any[]) => any;
|
|
4
|
+
registered: boolean;
|
|
5
|
+
register: any;
|
|
6
|
+
unregister: any;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new AdapterListener instance with the provided configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} config - The configuration object for the listener.
|
|
11
|
+
* @param {string} config.name - The name of the event listener.
|
|
12
|
+
* @param {Function} config.callback - The callback function to be called when the event is triggered.
|
|
13
|
+
* @param {Function} config.unregister - The function to unregister the event listeners.
|
|
14
|
+
* @param {Function} config.register - The function to register the event listeners.
|
|
15
|
+
*/
|
|
16
|
+
constructor({ name, callback, unregister, register, }: {
|
|
17
|
+
name: string;
|
|
18
|
+
callback: Callback;
|
|
19
|
+
unregister: (callbacks: Callback) => void;
|
|
20
|
+
register: (callback: Callback) => void;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Project, Unproject, TerraDrawCallbacks, TerraDrawChanges, TerraDrawMouseEvent, SetCursor, TerraDrawStylingFunction, GetLngLatFromEvent } from "../../common";
|
|
2
|
+
import { AdapterListener } from "./adapter-listener";
|
|
3
|
+
type BasePointerListener = (event: PointerEvent) => void;
|
|
4
|
+
type BaseKeyboardListener = (event: KeyboardEvent) => void;
|
|
5
|
+
type BaseMouseListener = (event: MouseEvent) => void;
|
|
6
|
+
export type BaseAdapterConfig = {
|
|
7
|
+
coordinatePrecision?: number;
|
|
8
|
+
minPixelDragDistanceDrawing?: number;
|
|
9
|
+
minPixelDragDistance?: number;
|
|
10
|
+
minPixelDragDistanceSelecting?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare abstract class TerraDrawBaseAdapter {
|
|
13
|
+
constructor(config: BaseAdapterConfig);
|
|
14
|
+
protected _minPixelDragDistance: number;
|
|
15
|
+
protected _minPixelDragDistanceDrawing: number;
|
|
16
|
+
protected _minPixelDragDistanceSelecting: number;
|
|
17
|
+
protected _lastDrawEvent: TerraDrawMouseEvent | undefined;
|
|
18
|
+
protected _coordinatePrecision: number;
|
|
19
|
+
protected _heldKeys: Set<string>;
|
|
20
|
+
protected _listeners: AdapterListener<BasePointerListener | BaseKeyboardListener | BaseMouseListener>[];
|
|
21
|
+
protected _dragState: "not-dragging" | "pre-dragging" | "dragging";
|
|
22
|
+
protected _currentModeCallbacks: TerraDrawCallbacks | undefined;
|
|
23
|
+
protected abstract getMapEventElement(): HTMLElement;
|
|
24
|
+
protected getButton(event: PointerEvent | MouseEvent): "neither" | "left" | "middle" | "right";
|
|
25
|
+
protected getMapElementXYPosition(event: PointerEvent | MouseEvent): {
|
|
26
|
+
containerX: number;
|
|
27
|
+
containerY: number;
|
|
28
|
+
};
|
|
29
|
+
protected getDrawEventFromEvent(event: PointerEvent | MouseEvent): TerraDrawMouseEvent | null;
|
|
30
|
+
/**
|
|
31
|
+
* Registers the provided callbacks for the current drawing mode and attaches
|
|
32
|
+
* the necessary event listeners.
|
|
33
|
+
* @param {TerraDrawCallbacks} callbacks - An object containing callback functions
|
|
34
|
+
* for handling various drawing events in the current mode.
|
|
35
|
+
*/
|
|
36
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the coordinate precision.
|
|
39
|
+
* @returns {number} The coordinate precision.
|
|
40
|
+
* @description The coordinate precision is the number of decimal places. Note that the precision will be overriden by the precision of the TerraDraw Adapter.
|
|
41
|
+
*/
|
|
42
|
+
getCoordinatePrecision(): number;
|
|
43
|
+
private getAdapterListeners;
|
|
44
|
+
/**
|
|
45
|
+
* Unregisters the event listeners for the current drawing mode.
|
|
46
|
+
* This is typically called when switching between drawing modes or
|
|
47
|
+
* stopping the drawing process.
|
|
48
|
+
*/
|
|
49
|
+
unregister(): void;
|
|
50
|
+
abstract clear(): void;
|
|
51
|
+
abstract project(...args: Parameters<Project>): ReturnType<Project>;
|
|
52
|
+
abstract unproject(...args: Parameters<Unproject>): ReturnType<Unproject>;
|
|
53
|
+
abstract setCursor(...args: Parameters<SetCursor>): ReturnType<SetCursor>;
|
|
54
|
+
abstract getLngLatFromEvent(...event: Parameters<GetLngLatFromEvent>): ReturnType<GetLngLatFromEvent>;
|
|
55
|
+
abstract setDraggability(enabled: boolean): void;
|
|
56
|
+
abstract setDoubleClickToZoom(enabled: boolean): void;
|
|
57
|
+
abstract render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -1,39 +1,90 @@
|
|
|
1
|
-
/// <reference types="google.maps" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare class TerraDrawGoogleMapsAdapter
|
|
5
|
-
constructor(config: {
|
|
6
|
-
lib: typeof google.maps;
|
|
7
|
-
map: google.maps.Map;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
/// <reference types="google.maps" />
|
|
2
|
+
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
|
|
3
|
+
import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
4
|
+
export declare class TerraDrawGoogleMapsAdapter extends TerraDrawBaseAdapter {
|
|
5
|
+
constructor(config: {
|
|
6
|
+
lib: typeof google.maps;
|
|
7
|
+
map: google.maps.Map;
|
|
8
|
+
} & BaseAdapterConfig);
|
|
9
|
+
private _cursor;
|
|
10
|
+
private _cursorStyleSheet;
|
|
11
|
+
private _lib;
|
|
12
|
+
private _map;
|
|
13
|
+
private _overlay;
|
|
14
|
+
private _clickEventListener;
|
|
15
|
+
private _mouseMoveEventListener;
|
|
16
|
+
private get _layers();
|
|
17
|
+
/**
|
|
18
|
+
* Generates an SVG path string for a circle with the given center coordinates and radius.
|
|
19
|
+
* Based off this StackOverflow answer: https://stackoverflow.com/a/27905268/1363484
|
|
20
|
+
* @param cx The x-coordinate of the circle's center.
|
|
21
|
+
* @param cy The y-coordinate of the circle's center.
|
|
22
|
+
* @param r The radius of the circle.
|
|
23
|
+
* @returns The SVG path string representing the circle.
|
|
24
|
+
*/
|
|
25
|
+
private circlePath;
|
|
26
|
+
register(callbacks: TerraDrawCallbacks): void;
|
|
27
|
+
unregister(): void;
|
|
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
|
+
} | null;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the HTML element of the Google Map element that handles interaction events
|
|
39
|
+
* @returns The HTMLElement representing the map container.
|
|
40
|
+
*/
|
|
41
|
+
getMapEventElement(): HTMLDivElement;
|
|
42
|
+
/**
|
|
43
|
+
* Converts longitude and latitude coordinates to pixel coordinates in the map container.
|
|
44
|
+
* @param lng The longitude coordinate to project.
|
|
45
|
+
* @param lat The latitude coordinate to project.
|
|
46
|
+
* @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
|
|
47
|
+
*/
|
|
48
|
+
project(lng: number, lat: number): {
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Converts pixel coordinates in the map container to longitude and latitude coordinates.
|
|
54
|
+
* @param x The x-coordinate in the map container to unproject.
|
|
55
|
+
* @param y The y-coordinate in the map container to unproject.
|
|
56
|
+
* @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
|
|
57
|
+
*/
|
|
58
|
+
unproject(x: number, y: number): {
|
|
59
|
+
lng: number;
|
|
60
|
+
lat: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Sets the cursor style for the map container.
|
|
64
|
+
* @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
|
|
65
|
+
*/
|
|
66
|
+
setCursor(cursor: Parameters<SetCursor>[0]): void;
|
|
67
|
+
/**
|
|
68
|
+
* Enables or disables the double-click to zoom functionality on the map.
|
|
69
|
+
* @param enabled Set to true to enable double-click to zoom, or false to disable it.
|
|
70
|
+
*/
|
|
71
|
+
setDoubleClickToZoom(enabled: boolean): void;
|
|
72
|
+
/**
|
|
73
|
+
* Enables or disables the draggable functionality of the map.
|
|
74
|
+
* @param enabled Set to true to enable map dragging, or false to disable it.
|
|
75
|
+
*/
|
|
76
|
+
setDraggability(enabled: boolean): void;
|
|
77
|
+
private renderedFeatureIds;
|
|
78
|
+
/**
|
|
79
|
+
* Renders GeoJSON features on the map using the provided styling configuration.
|
|
80
|
+
* @param changes An object containing arrays of created, updated, and unchanged features to render.
|
|
81
|
+
* @param styling An object mapping draw modes to feature styling functions
|
|
82
|
+
*/
|
|
83
|
+
render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
|
|
84
|
+
private clearLayers;
|
|
85
|
+
/**
|
|
86
|
+
* Clears the map and store of all rendered data layers
|
|
87
|
+
* @returns void
|
|
88
|
+
* */
|
|
89
|
+
clear(): void;
|
|
90
|
+
}
|
|
@@ -1,33 +1,97 @@
|
|
|
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
|
+
}
|