terra-draw 0.0.1-alpha.5 → 0.0.1-alpha.51

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 (102) 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 +26 -4
  5. package/dist/adapters/common/adapter-listener.d.ts +22 -0
  6. package/dist/adapters/common/base.adapter.d.ts +52 -0
  7. package/dist/adapters/google-maps.adapter.d.ts +91 -38
  8. package/dist/adapters/leaflet.adapter.d.ts +98 -35
  9. package/dist/adapters/mapbox-gl.adapter.d.ts +89 -36
  10. package/dist/adapters/maplibre-gl.adapter.d.ts +72 -0
  11. package/dist/adapters/openlayers.adapter.d.ts +118 -0
  12. package/dist/common.d.ts +100 -99
  13. package/dist/geometry/boolean/is-valid-coordinate.d.ts +4 -0
  14. package/dist/geometry/boolean/is-valid-linestring-feature.d.ts +2 -0
  15. package/dist/geometry/boolean/is-valid-point.d.ts +2 -0
  16. package/dist/geometry/boolean/is-valid-polygon-feature.d.ts +3 -0
  17. package/dist/geometry/boolean/point-in-polygon.d.ts +2 -2
  18. package/dist/geometry/boolean/self-intersects.d.ts +2 -2
  19. package/dist/geometry/centroid.d.ts +2 -2
  20. package/dist/geometry/coordinates-identical.d.ts +2 -2
  21. package/dist/geometry/get-coordinates-as-points.d.ts +6 -6
  22. package/dist/geometry/get-midpoints.d.ts +8 -7
  23. package/dist/geometry/helpers.d.ts +4 -4
  24. package/dist/geometry/limit-decimal-precision.d.ts +1 -1
  25. package/dist/geometry/measure/haversine-distance.d.ts +2 -2
  26. package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -10
  27. package/dist/geometry/measure/pixel-distance.d.ts +7 -7
  28. package/dist/geometry/measure/rhumb-bearing.d.ts +2 -2
  29. package/dist/geometry/measure/rhumb-destination.d.ts +2 -2
  30. package/dist/geometry/measure/rhumb-distance.d.ts +2 -2
  31. package/dist/geometry/midpoint-coordinate.d.ts +3 -2
  32. package/dist/geometry/shape/create-bbox.d.ts +10 -0
  33. package/dist/geometry/shape/create-circle.d.ts +7 -7
  34. package/dist/geometry/shape/great-circle-line.d.ts +12 -0
  35. package/dist/geometry/transform/rotate.d.ts +2 -2
  36. package/dist/geometry/transform/scale.d.ts +2 -2
  37. package/dist/modes/base.behavior.d.ts +19 -19
  38. package/dist/modes/base.mode.d.ts +58 -30
  39. package/dist/modes/circle/circle.mode.d.ts +54 -27
  40. package/dist/modes/click-bounding-box.behavior.d.ts +6 -7
  41. package/dist/modes/freehand/freehand.mode.d.ts +63 -29
  42. package/dist/modes/great-circle-snapping.behavior.d.ts +13 -0
  43. package/dist/modes/greatcircle/great-circle.mode.d.ts +64 -0
  44. package/dist/modes/linestring/linestring.mode.d.ts +67 -34
  45. package/dist/modes/pixel-distance.behavior.d.ts +7 -7
  46. package/dist/modes/point/point.mode.d.ts +44 -18
  47. package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -0
  48. package/dist/modes/polygon/polygon.mode.d.ts +70 -37
  49. package/dist/modes/rectangle/rectangle.mode.d.ts +55 -0
  50. package/dist/modes/render/render.mode.d.ts +51 -0
  51. package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +19 -13
  52. package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +19 -17
  53. package/dist/modes/select/behaviors/feature-at-pointer-event.behavior.d.ts +15 -0
  54. package/dist/modes/select/behaviors/features-at-mouse-event.behavior.d.ts +15 -15
  55. package/dist/modes/select/behaviors/midpoint.behavior.d.ts +18 -18
  56. package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +13 -13
  57. package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +13 -13
  58. package/dist/modes/select/behaviors/selection-point.behavior.d.ts +18 -18
  59. package/dist/modes/select/select.mode.d.ts +110 -62
  60. package/dist/modes/snapping.behavior.d.ts +15 -13
  61. package/dist/modes/static/static.mode.d.ts +32 -13
  62. package/dist/store/spatial-index/quickselect.d.ts +2 -2
  63. package/dist/store/spatial-index/rbush.d.ts +35 -35
  64. package/dist/store/spatial-index/spatial-index.d.ts +18 -18
  65. package/dist/store/store-feature-validation.d.ts +15 -0
  66. package/dist/store/store.d.ts +48 -48
  67. package/dist/terra-draw.cjs +1 -1
  68. package/dist/terra-draw.cjs.map +1 -1
  69. package/dist/terra-draw.d.ts +183 -47
  70. package/dist/terra-draw.modern.js +1 -1
  71. package/dist/terra-draw.modern.js.map +1 -1
  72. package/dist/terra-draw.module.js +1 -1
  73. package/dist/terra-draw.module.js.map +1 -1
  74. package/dist/terra-draw.umd.js +1 -1
  75. package/dist/terra-draw.umd.js.map +1 -1
  76. package/dist/util/geoms.d.ts +3 -3
  77. package/dist/util/id.d.ts +1 -1
  78. package/dist/util/styling.d.ts +2 -2
  79. package/jest.nocheck.config.ts +9 -0
  80. package/package.json +156 -87
  81. package/readme.gif +0 -0
  82. package/tsconfig.json +20 -12
  83. package/CODE_OF_CONDUCT.md +0 -36
  84. package/CONTRIBUTING.md +0 -17
  85. package/DEVELOPMENT.md +0 -77
  86. package/dist/bundle.js +0 -6
  87. package/dist/bundle.js.LICENSE.txt +0 -4
  88. package/dist/geometry/create-circle.d.ts +0 -6
  89. package/dist/geometry/get-pixel-distance-to-line.d.ts +0 -10
  90. package/dist/geometry/get-pixel-distance.d.ts +0 -7
  91. package/dist/geometry/haversine-distance.d.ts +0 -1
  92. package/dist/geometry/point-in-polygon.d.ts +0 -1
  93. package/dist/geometry/self-intersects.d.ts +0 -2
  94. package/dist/modes/circle.mode.d.ts +0 -18
  95. package/dist/modes/freehand.mode.d.ts +0 -20
  96. package/dist/modes/line-string.mode.d.ts +0 -21
  97. package/dist/modes/point.mode.d.ts +0 -14
  98. package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +0 -11
  99. package/dist/modes/polygon.mode.d.ts +0 -21
  100. package/dist/modes/select.mode.d.ts +0 -21
  101. package/dist/modes/static.mode.d.ts +0 -10
  102. package/jest.config.ts +0 -27
@@ -0,0 +1,8 @@
1
+ ARG NODE_MAJOR_VERSION
2
+
3
+ FROM mcr.microsoft.com/devcontainers/javascript-node:${NODE_MAJOR_VERSION}
4
+
5
+ ENV EDITOR="code -w" VISUAL="code -w" CHOKIDAR_USEPOLLING="1"
6
+
7
+ # uncomment to install additional npm packages
8
+ # RUN su node -c 'npm i -g cowsay@1.5.0'
@@ -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,40 @@
1
- <img src="docs/logo.png" alt="Terra Draw Logo" width="400"/>
1
+ <img src="./logo.png" alt="Terra Draw Logo" width="400"/>
2
2
 
3
3
  ![Terra Draw CI Badge](https://github.com/JamesLMilner/terra-draw/actions/workflows/ci.yml/badge.svg)
4
+ [![npm version](https://badge.fury.io/js/terra-draw.svg)](https://badge.fury.io/js/terra-draw)
4
5
 
5
6
  Frictionless map drawing across mapping libraries.
6
7
 
7
- TerraDraw centralises map drawing logic and provides a host of out the box drawing modes that work across map providers (currently Leaflet, Mapbox, Google) via adapters.
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!
9
+
10
+ ![An example of drawing geodesic lines using Terra Draw with Leaflet](./readme.gif)
11
+
12
+ ### Library Support
13
+
14
+ Terra Draw uses the concept of 'adapters' to allow it to work with a host of different mapping libraries. Currently supported are:
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/GETTING_STARTED.md) - this provides a host of information on how to get up and running with Terra Draw. You may also find some useful pointers for things you may be finding yourself wanting to do in the [common patterns guide](./guides/COMMON_PATTERNS.md).
8
26
 
9
27
  ### Development
10
28
 
11
- Please see the [the development documentation](./DEVELOPMENT.md)
29
+ Please see the [the development documentation](./guides/DEVELOPMENT.md)
12
30
 
13
31
  ### Contributing
14
32
 
15
- Please see the [the contributing documentation](./CONTRIBUTING.md)
33
+ Please see the [the contributing documentation](./guides/CONTRIBUTING.md)
34
+
35
+ ### Project Website
36
+
37
+ 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).
16
38
 
17
39
  ### License
18
40
 
@@ -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,52 @@
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 declare abstract class TerraDrawBaseAdapter {
7
+ constructor(config: {
8
+ coordinatePrecision?: number;
9
+ minPixelDragDistanceDrawing?: number;
10
+ minPixelDragDistance?: number;
11
+ minPixelDragDistanceSelecting?: number;
12
+ });
13
+ protected _minPixelDragDistance: number;
14
+ protected _minPixelDragDistanceDrawing: number;
15
+ protected _minPixelDragDistanceSelecting: number;
16
+ protected _lastDrawEvent: TerraDrawMouseEvent | undefined;
17
+ protected _coordinatePrecision: number;
18
+ protected _heldKeys: Set<string>;
19
+ protected _listeners: AdapterListener<BasePointerListener | BaseKeyboardListener | BaseMouseListener>[];
20
+ protected _dragState: "not-dragging" | "pre-dragging" | "dragging";
21
+ protected _currentModeCallbacks: TerraDrawCallbacks | undefined;
22
+ protected abstract getMapEventElement(): HTMLElement;
23
+ protected getButton(event: PointerEvent | MouseEvent): "neither" | "left" | "middle" | "right";
24
+ protected getMapElementXYPosition(event: PointerEvent | MouseEvent): {
25
+ containerX: number;
26
+ containerY: number;
27
+ };
28
+ protected getDrawEventFromEvent(event: PointerEvent | MouseEvent): TerraDrawMouseEvent | null;
29
+ /**
30
+ * Registers the provided callbacks for the current drawing mode and attaches
31
+ * the necessary event listeners.
32
+ * @param {TerraDrawCallbacks} callbacks - An object containing callback functions
33
+ * for handling various drawing events in the current mode.
34
+ */
35
+ register(callbacks: TerraDrawCallbacks): void;
36
+ private getAdapterListeners;
37
+ /**
38
+ * Unregisters the event listeners for the current drawing mode.
39
+ * This is typically called when switching between drawing modes or
40
+ * stopping the drawing process.
41
+ */
42
+ unregister(): void;
43
+ abstract clear(): void;
44
+ abstract project(...args: Parameters<Project>): ReturnType<Project>;
45
+ abstract unproject(...args: Parameters<Unproject>): ReturnType<Unproject>;
46
+ abstract setCursor(...args: Parameters<SetCursor>): ReturnType<SetCursor>;
47
+ abstract getLngLatFromEvent(...event: Parameters<GetLngLatFromEvent>): ReturnType<GetLngLatFromEvent>;
48
+ abstract setDraggability(enabled: boolean): void;
49
+ abstract setDoubleClickToZoom(enabled: boolean): void;
50
+ abstract render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
51
+ }
52
+ export {};
@@ -1,38 +1,91 @@
1
- /// <reference types="google.maps" />
2
- import { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
3
- export declare class TerraDrawGoogleMapsAdapter implements TerraDrawAdapter {
4
- constructor(config: {
5
- lib: typeof google.maps;
6
- map: google.maps.Map;
7
- coordinatePrecision?: number;
8
- });
9
- private _heldKeys;
10
- private _cursor;
11
- private _cursorStyleSheet;
12
- private _coordinatePrecision;
13
- private _lib;
14
- private _map;
15
- private _onMouseMoveListener;
16
- private _onMouseMoveCallback;
17
- private _onClickListener;
18
- private _onRightClickListener;
19
- private _onClickCallback;
20
- private _onKeyUpListener;
21
- private _onDragStartListener;
22
- private _onDragListener;
23
- private _onDragEndListener;
24
- private _layers;
25
- getMapContainer: () => HTMLElement;
26
- unproject: (x: number, y: number) => {
27
- lng: number;
28
- lat: number;
29
- };
30
- project: TerraDrawModeRegisterConfig["project"];
31
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
32
- private circlePath;
33
- register(callbacks: TerraDrawCallbacks): void;
34
- unregister(): void;
35
- render(changes: TerraDrawChanges, styling: {
36
- [mode: string]: TerraDrawAdapterStyling;
37
- }): void;
38
- }
1
+ /// <reference types="google.maps" />
2
+ import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
3
+ import { 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
+ coordinatePrecision?: number;
9
+ });
10
+ private _cursor;
11
+ private _cursorStyleSheet;
12
+ private _lib;
13
+ private _map;
14
+ private _overlay;
15
+ private _clickEventListener;
16
+ private _mouseMoveEventListener;
17
+ private get _layers();
18
+ /**
19
+ * Generates an SVG path string for a circle with the given center coordinates and radius.
20
+ * Based off this StackOverflow answer: https://stackoverflow.com/a/27905268/1363484
21
+ * @param cx The x-coordinate of the circle's center.
22
+ * @param cy The y-coordinate of the circle's center.
23
+ * @param r The radius of the circle.
24
+ * @returns The SVG path string representing the circle.
25
+ */
26
+ private circlePath;
27
+ register(callbacks: TerraDrawCallbacks): void;
28
+ unregister(): void;
29
+ /**
30
+ * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
31
+ * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
32
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
33
+ */
34
+ getLngLatFromEvent(event: PointerEvent | MouseEvent): {
35
+ lng: number;
36
+ lat: number;
37
+ } | null;
38
+ /**
39
+ * Retrieves the HTML element of the Google Map element that handles interaction events
40
+ * @returns The HTMLElement representing the map container.
41
+ */
42
+ getMapEventElement(): HTMLDivElement;
43
+ /**
44
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
45
+ * @param lng The longitude coordinate to project.
46
+ * @param lat The latitude coordinate to project.
47
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
48
+ */
49
+ project(lng: number, lat: number): {
50
+ x: number;
51
+ y: number;
52
+ };
53
+ /**
54
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
55
+ * @param x The x-coordinate in the map container to unproject.
56
+ * @param y The y-coordinate in the map container to unproject.
57
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
58
+ */
59
+ unproject(x: number, y: number): {
60
+ lng: number;
61
+ lat: number;
62
+ };
63
+ /**
64
+ * Sets the cursor style for the map container.
65
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
66
+ */
67
+ setCursor(cursor: Parameters<SetCursor>[0]): void;
68
+ /**
69
+ * Enables or disables the double-click to zoom functionality on the map.
70
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
71
+ */
72
+ setDoubleClickToZoom(enabled: boolean): void;
73
+ /**
74
+ * Enables or disables the draggable functionality of the map.
75
+ * @param enabled Set to true to enable map dragging, or false to disable it.
76
+ */
77
+ setDraggability(enabled: boolean): void;
78
+ private renderedFeatureIds;
79
+ /**
80
+ * Renders GeoJSON features on the map using the provided styling configuration.
81
+ * @param changes An object containing arrays of created, updated, and unchanged features to render.
82
+ * @param styling An object mapping draw modes to feature styling functions
83
+ */
84
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
85
+ private clearLayers;
86
+ /**
87
+ * Clears the map and store of all rendered data layers
88
+ * @returns void
89
+ * */
90
+ clear(): void;
91
+ }
@@ -1,35 +1,98 @@
1
- import { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
2
- import L from "leaflet";
3
- export declare class TerraDrawLeafletAdapter implements TerraDrawAdapter {
4
- constructor(config: {
5
- lib: typeof L;
6
- map: L.Map;
7
- coordinatePrecision?: number;
8
- });
9
- private _heldKeys;
10
- private _lib;
11
- private _coordinatePrecision;
12
- private _map;
13
- private _onMouseMoveListener;
14
- private _onClickListener;
15
- private _onKeyUpListener;
16
- private _onKeyDownListener;
17
- private _onDragStartListener;
18
- private _onDragListener;
19
- private _onDragEndListener;
20
- private _layer;
21
- private _midPointPaneZIndexStyleSheet;
22
- private _midPointPane;
23
- private _selectionPaneZIndexStyleSheet;
24
- private _selectedPane;
25
- project: TerraDrawModeRegisterConfig["project"];
26
- unproject: TerraDrawModeRegisterConfig["unproject"];
27
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
28
- getMapContainer: () => HTMLElement;
29
- private createPaneStyleSheet;
30
- register(callbacks: TerraDrawCallbacks): void;
31
- unregister(): void;
32
- render(changes: TerraDrawChanges, styling: {
33
- [mode: string]: TerraDrawAdapterStyling;
34
- }): void;
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 element of the Leaflet element that handles interaction events
49
+ * @returns The HTMLElement representing the map container.
50
+ */
51
+ getMapEventElement(): 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,89 @@
1
- import { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
2
- import mapboxgl from "mapbox-gl";
3
- export declare class TerraDrawMapboxGLAdapter implements TerraDrawAdapter {
4
- constructor(config: {
5
- map: mapboxgl.Map;
6
- coordinatePrecision: number;
7
- });
8
- unproject: TerraDrawModeRegisterConfig["unproject"];
9
- project: TerraDrawModeRegisterConfig["project"];
10
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
11
- getMapContainer: () => HTMLElement;
12
- private _heldKeys;
13
- private _coordinatePrecision;
14
- private _map;
15
- private _onMouseMoveListener;
16
- private _onClickListener;
17
- private _onDragStartListener;
18
- private _onDragListener;
19
- private _onDragEndListener;
20
- private _onKeyDownListener;
21
- private _onKeyUpListener;
22
- private _rendered;
23
- private _addGeoJSONSource;
24
- private _addFillLayer;
25
- private _addFillOutlineLayer;
26
- private _addLineLayer;
27
- private _addPointLayer;
28
- private _addLayer;
29
- private _addGeoJSONLayer;
30
- private _setGeoJSONLayerData;
31
- register(callbacks: TerraDrawCallbacks): void;
32
- unregister(): void;
33
- render(changes: TerraDrawChanges, styling: {
34
- [mode: string]: TerraDrawAdapterStyling;
35
- }): void;
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 _nextRender;
10
+ private _map;
11
+ private _container;
12
+ private _rendered;
13
+ /**
14
+ * Clears the map of rendered layers and sources
15
+ * @returns void
16
+ * */
17
+ private clearLayers;
18
+ private _addGeoJSONSource;
19
+ private _addFillLayer;
20
+ private _addFillOutlineLayer;
21
+ private _addLineLayer;
22
+ private _addPointLayer;
23
+ private _addLayer;
24
+ private _addGeoJSONLayer;
25
+ private _setGeoJSONLayerData;
26
+ private getEmptyGeometries;
27
+ private changedIds;
28
+ private updateChangedIds;
29
+ /**
30
+ * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
31
+ * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
32
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
33
+ */
34
+ getLngLatFromEvent(event: PointerEvent | MouseEvent): {
35
+ lng: number;
36
+ lat: number;
37
+ };
38
+ /**
39
+ *Retrieves the HTML element of the Mapbox element that handles interaction events
40
+ * @returns The HTMLElement representing the map container.
41
+ */
42
+ getMapEventElement(): HTMLCanvasElement;
43
+ /**
44
+ * Enables or disables the draggable functionality of the map.
45
+ * @param enabled Set to true to enable map dragging, or false to disable it.
46
+ */
47
+ setDraggability(enabled: boolean): void;
48
+ /**
49
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
50
+ * @param lng The longitude coordinate to project.
51
+ * @param lat The latitude coordinate to project.
52
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
53
+ */
54
+ project(lng: number, lat: number): {
55
+ x: number;
56
+ y: number;
57
+ };
58
+ /**
59
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
60
+ * @param x The x-coordinate in the map container to unproject.
61
+ * @param y The y-coordinate in the map container to unproject.
62
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
63
+ */
64
+ unproject(x: number, y: number): {
65
+ lng: number;
66
+ lat: number;
67
+ };
68
+ /**
69
+ * Sets the cursor style for the map container.
70
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
71
+ */
72
+ setCursor(cursor: Parameters<SetCursor>[0]): void;
73
+ /**
74
+ * Enables or disables the double-click to zoom functionality on the map.
75
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
76
+ */
77
+ setDoubleClickToZoom(enabled: boolean): void;
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
+ /**
85
+ * Clears the map and store of all rendered data layers
86
+ * @returns void
87
+ * */
88
+ clear(): void;
89
+ }
@@ -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 element of the MapLibre element that handles interaction events
23
+ * @returns The HTMLElement representing the map container.
24
+ */
25
+ getMapEventElement(): HTMLCanvasElement;
26
+ /**
27
+ * Enables or disables the draggable functionality of the map.
28
+ * @param enabled Set to true to enable map dragging, or false to disable it.
29
+ */
30
+ setDraggability(enabled: boolean): void;
31
+ /**
32
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
33
+ * @param lng The longitude coordinate to project.
34
+ * @param lat The latitude coordinate to project.
35
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
36
+ */
37
+ project(lng: number, lat: number): {
38
+ x: number;
39
+ y: number;
40
+ };
41
+ /**
42
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
43
+ * @param x The x-coordinate in the map container to unproject.
44
+ * @param y The y-coordinate in the map container to unproject.
45
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
46
+ */
47
+ unproject(x: number, y: number): {
48
+ lng: number;
49
+ lat: number;
50
+ };
51
+ /**
52
+ * Sets the cursor style for the map container.
53
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
54
+ */
55
+ setCursor(style: Parameters<SetCursor>[0]): void;
56
+ /**
57
+ * Enables or disables the double-click to zoom functionality on the map.
58
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
59
+ */
60
+ setDoubleClickToZoom(enabled: boolean): void;
61
+ /**
62
+ * Renders GeoJSON features on the map using the provided styling configuration.
63
+ * @param changes An object containing arrays of created, updated, and unchanged features to render.
64
+ * @param styling An object mapping draw modes to feature styling functions
65
+ */
66
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
67
+ /**
68
+ * Clears the map and store of all rendered data layers
69
+ * @returns void
70
+ * */
71
+ clear(): void;
72
+ }