terra-draw 0.0.1-alpha.9 → 1.0.0-beta.1

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 (122) hide show
  1. package/.devcontainer/Dockerfile +8 -0
  2. package/.devcontainer/devcontainer.json +27 -0
  3. package/.devcontainer/post-create.sh +16 -0
  4. package/README.md +23 -13
  5. package/dist/adapters/arcgis-maps-sdk.adapter.d.ts +106 -0
  6. package/dist/adapters/google-maps.adapter.d.ts +90 -39
  7. package/dist/adapters/leaflet.adapter.d.ts +99 -33
  8. package/dist/adapters/mapbox-gl.adapter.d.ts +91 -37
  9. package/dist/adapters/maplibre-gl.adapter.d.ts +72 -0
  10. package/dist/adapters/openlayers.adapter.d.ts +120 -0
  11. package/dist/common.d.ts +118 -98
  12. package/dist/geometry/boolean/is-valid-coordinate.d.ts +4 -0
  13. package/dist/geometry/boolean/point-in-polygon.d.ts +2 -2
  14. package/dist/geometry/boolean/self-intersects.d.ts +2 -2
  15. package/dist/geometry/calculate-relative-angle.d.ts +17 -0
  16. package/dist/geometry/centroid.d.ts +2 -2
  17. package/dist/geometry/coordinates-identical.d.ts +2 -2
  18. package/dist/geometry/determine-halfplane.d.ts +10 -0
  19. package/dist/geometry/get-coordinates-as-points.d.ts +6 -6
  20. package/dist/geometry/get-midpoints.d.ts +14 -7
  21. package/dist/geometry/helpers.d.ts +4 -4
  22. package/dist/geometry/limit-decimal-precision.d.ts +1 -1
  23. package/dist/geometry/measure/area.d.ts +2 -0
  24. package/dist/geometry/measure/bearing.d.ts +9 -0
  25. package/dist/geometry/measure/destination.d.ts +9 -0
  26. package/dist/geometry/measure/haversine-distance.d.ts +2 -2
  27. package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -10
  28. package/dist/geometry/measure/pixel-distance.d.ts +7 -7
  29. package/dist/geometry/measure/rhumb-bearing.d.ts +2 -2
  30. package/dist/geometry/measure/rhumb-destination.d.ts +2 -2
  31. package/dist/geometry/measure/rhumb-distance.d.ts +2 -2
  32. package/dist/geometry/measure/slice-along.d.ts +2 -0
  33. package/dist/geometry/midpoint-coordinate.d.ts +4 -2
  34. package/dist/geometry/project/web-mercator.d.ts +20 -0
  35. package/dist/geometry/shape/create-bbox.d.ts +10 -0
  36. package/dist/geometry/shape/create-circle.d.ts +13 -7
  37. package/dist/geometry/shape/great-circle-coordinates.d.ts +2 -0
  38. package/dist/geometry/shape/web-mercator-distortion.d.ts +2 -0
  39. package/dist/geometry/transform/rotate.d.ts +9 -2
  40. package/dist/geometry/transform/scale.d.ts +9 -2
  41. package/dist/geometry/web-mercator-centroid.d.ts +11 -0
  42. package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +62 -0
  43. package/dist/modes/base.behavior.d.ts +21 -19
  44. package/dist/modes/base.mode.d.ts +66 -33
  45. package/dist/modes/circle/circle.mode.d.ts +66 -37
  46. package/dist/modes/click-bounding-box.behavior.d.ts +6 -7
  47. package/dist/modes/freehand/freehand.mode.d.ts +63 -43
  48. package/dist/modes/insert-coordinates.behavior.d.ts +9 -0
  49. package/dist/modes/linestring/linestring.mode.d.ts +78 -47
  50. package/dist/modes/pixel-distance.behavior.d.ts +7 -7
  51. package/dist/modes/point/point.mode.d.ts +44 -26
  52. package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -19
  53. package/dist/modes/polygon/polygon.mode.d.ts +69 -51
  54. package/dist/modes/rectangle/rectangle.mode.d.ts +55 -0
  55. package/dist/modes/render/render.mode.d.ts +52 -23
  56. package/dist/modes/select/behaviors/drag-coordinate-resize.behavior.d.ts +62 -0
  57. package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +20 -13
  58. package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +20 -17
  59. package/dist/modes/select/behaviors/{features-at-mouse-event.behavior.d.ts → feature-at-pointer-event.behavior.d.ts} +15 -15
  60. package/dist/modes/select/behaviors/midpoint.behavior.d.ts +19 -18
  61. package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +14 -13
  62. package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +14 -13
  63. package/dist/modes/select/behaviors/selection-point.behavior.d.ts +19 -18
  64. package/dist/modes/select/select.mode.d.ts +119 -78
  65. package/dist/modes/snapping.behavior.d.ts +16 -13
  66. package/dist/modes/static/static.mode.d.ts +32 -30
  67. package/dist/store/spatial-index/quickselect.d.ts +2 -2
  68. package/dist/store/spatial-index/rbush.d.ts +35 -35
  69. package/dist/store/spatial-index/spatial-index.d.ts +18 -18
  70. package/dist/store/store-feature-validation.d.ts +16 -0
  71. package/dist/store/store.d.ts +59 -48
  72. package/dist/terra-draw.cjs +1 -1
  73. package/dist/terra-draw.cjs.map +1 -1
  74. package/dist/terra-draw.d.ts +223 -48
  75. package/dist/terra-draw.modern.js +1 -1
  76. package/dist/terra-draw.modern.js.map +1 -1
  77. package/dist/terra-draw.module.js +1 -1
  78. package/dist/terra-draw.module.js.map +1 -1
  79. package/dist/terra-draw.umd.js +1 -1
  80. package/dist/terra-draw.umd.js.map +1 -1
  81. package/dist/util/geoms.d.ts +3 -3
  82. package/dist/util/id.d.ts +1 -1
  83. package/dist/util/styling.d.ts +2 -2
  84. package/dist/validations/linestring.validation.d.ts +2 -0
  85. package/dist/validations/max-size.validation.d.ts +2 -0
  86. package/dist/validations/min-size.validation.d.ts +2 -0
  87. package/dist/validations/not-self-intersecting.validation.d.ts +2 -0
  88. package/dist/validations/point.validation.d.ts +2 -0
  89. package/dist/validations/polygon.validation.d.ts +3 -0
  90. package/e2e/README.md +29 -0
  91. package/e2e/package-lock.json +4274 -0
  92. package/e2e/package.json +26 -0
  93. package/e2e/playwright.config.ts +77 -0
  94. package/e2e/public/favicon.ico +0 -0
  95. package/e2e/public/index.html +53 -0
  96. package/e2e/tests/leaflet.spec.ts +739 -0
  97. package/e2e/tests/setup.ts +198 -0
  98. package/e2e/webpack.config.js +36 -0
  99. package/jest.nocheck.config.ts +17 -0
  100. package/package.json +158 -87
  101. package/readme.gif +0 -0
  102. package/tsconfig.json +25 -12
  103. package/CODE_OF_CONDUCT.md +0 -36
  104. package/CONTRIBUTING.md +0 -17
  105. package/DEVELOPMENT.md +0 -77
  106. package/dist/bundle.js +0 -6
  107. package/dist/bundle.js.LICENSE.txt +0 -4
  108. package/dist/geometry/create-circle.d.ts +0 -6
  109. package/dist/geometry/get-pixel-distance-to-line.d.ts +0 -10
  110. package/dist/geometry/get-pixel-distance.d.ts +0 -7
  111. package/dist/geometry/haversine-distance.d.ts +0 -1
  112. package/dist/geometry/point-in-polygon.d.ts +0 -1
  113. package/dist/geometry/self-intersects.d.ts +0 -2
  114. package/dist/modes/circle.mode.d.ts +0 -18
  115. package/dist/modes/freehand.mode.d.ts +0 -20
  116. package/dist/modes/line-string.mode.d.ts +0 -21
  117. package/dist/modes/point.mode.d.ts +0 -14
  118. package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +0 -11
  119. package/dist/modes/polygon.mode.d.ts +0 -21
  120. package/dist/modes/select.mode.d.ts +0 -21
  121. package/dist/modes/static.mode.d.ts +0 -10
  122. 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,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="https://terradraw.io/imgs/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!
8
9
 
9
- ### Install
10
+ ![An example of drawing geodesic lines using Terra Draw with Leaflet](./readme.gif)
10
11
 
11
- You can install the Terra Draw into your project like so:
12
+ ### Library Support
12
13
 
13
- ```shell
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
- Be aware Terra Draw is currently in alpha, the initial API is still being finalised
16
+ - [Leaflet](https://leafletjs.com/) v1
17
+ - [OpenLayers](https://openlayers.org/) v10
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
- ### Development
23
+ ### Getting Started
20
24
 
21
- Please see the [the development documentation](./DEVELOPMENT.md)
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 checkout the offical 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).
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
- /// <reference types="google.maps" />
2
- import { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
3
- import { GeoJSONStoreFeatures } from "../store/store";
4
- export declare class TerraDrawGoogleMapsAdapter implements TerraDrawAdapter {
5
- constructor(config: {
6
- lib: typeof google.maps;
7
- map: google.maps.Map;
8
- coordinatePrecision?: number;
9
- });
10
- private _heldKeys;
11
- private _cursor;
12
- private _cursorStyleSheet;
13
- private _coordinatePrecision;
14
- private _lib;
15
- private _map;
16
- private _onMouseMoveListener;
17
- private _onMouseMoveCallback;
18
- private _onClickListener;
19
- private _onRightClickListener;
20
- private _onClickCallback;
21
- private _onKeyUpListener;
22
- private _onDragStartListener;
23
- private _onDragListener;
24
- private _onDragEndListener;
25
- private _layers;
26
- getMapContainer: () => HTMLElement;
27
- unproject: (x: number, y: number) => {
28
- lng: number;
29
- lat: number;
30
- };
31
- project: TerraDrawModeRegisterConfig["project"];
32
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
33
- private circlePath;
34
- register(callbacks: TerraDrawCallbacks): void;
35
- unregister(): void;
36
- render(changes: TerraDrawChanges, styling: {
37
- [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
38
- }): void;
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 { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
2
- import L from "leaflet";
3
- import { GeoJSONStoreFeatures } from "../store/store";
4
- export declare class TerraDrawLeafletAdapter implements TerraDrawAdapter {
5
- constructor(config: {
6
- lib: typeof L;
7
- map: L.Map;
8
- coordinatePrecision?: number;
9
- });
10
- private _heldKeys;
11
- private _lib;
12
- private _coordinatePrecision;
13
- private _map;
14
- private _onMouseMoveListener;
15
- private _onClickListener;
16
- private _onKeyUpListener;
17
- private _onKeyDownListener;
18
- private _onDragStartListener;
19
- private _onDragListener;
20
- private _onDragEndListener;
21
- private _layer;
22
- private _panes;
23
- project: TerraDrawModeRegisterConfig["project"];
24
- unproject: TerraDrawModeRegisterConfig["unproject"];
25
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
26
- getMapContainer: () => HTMLElement;
27
- private createPaneStyleSheet;
28
- register(callbacks: TerraDrawCallbacks): void;
29
- unregister(): void;
30
- render(changes: TerraDrawChanges, styling: {
31
- [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
32
- }): void;
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 { TerraDrawCallbacks, TerraDrawAdapter, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawChanges } from "../common";
2
- import mapboxgl from "mapbox-gl";
3
- import { GeoJSONStoreFeatures } from "../store/store";
4
- export declare class TerraDrawMapboxGLAdapter implements TerraDrawAdapter {
5
- constructor(config: {
6
- map: mapboxgl.Map;
7
- coordinatePrecision: number;
8
- });
9
- unproject: TerraDrawModeRegisterConfig["unproject"];
10
- project: TerraDrawModeRegisterConfig["project"];
11
- setCursor: TerraDrawModeRegisterConfig["setCursor"];
12
- getMapContainer: () => HTMLElement;
13
- private _heldKeys;
14
- private _coordinatePrecision;
15
- private _map;
16
- private _onMouseMoveListener;
17
- private _onClickListener;
18
- private _onDragStartListener;
19
- private _onDragListener;
20
- private _onDragEndListener;
21
- private _onKeyDownListener;
22
- private _onKeyUpListener;
23
- private _rendered;
24
- private _addGeoJSONSource;
25
- private _addFillLayer;
26
- private _addFillOutlineLayer;
27
- private _addLineLayer;
28
- private _addPointLayer;
29
- private _addLayer;
30
- private _addGeoJSONLayer;
31
- private _setGeoJSONLayerData;
32
- register(callbacks: TerraDrawCallbacks): void;
33
- unregister(): void;
34
- render(changes: TerraDrawChanges, styling: {
35
- [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling;
36
- }): void;
37
- }
1
+ import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
2
+ import mapboxgl from "mapbox-gl";
3
+ import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
4
+ export declare class TerraDrawMapboxGLAdapter extends TerraDrawBaseAdapter {
5
+ constructor(config: {
6
+ map: mapboxgl.Map;
7
+ } & BaseAdapterConfig);
8
+ private _nextRender;
9
+ private _map;
10
+ private _container;
11
+ private _rendered;
12
+ /**
13
+ * Clears the map of rendered layers and sources
14
+ * @returns void
15
+ * */
16
+ private clearLayers;
17
+ private _addGeoJSONSource;
18
+ private _addFillLayer;
19
+ private _addFillOutlineLayer;
20
+ private _addLineLayer;
21
+ private _addPointLayer;
22
+ private _addLayer;
23
+ private _addGeoJSONLayer;
24
+ private _setGeoJSONLayerData;
25
+ private getEmptyGeometries;
26
+ private changedIds;
27
+ private updateChangedIds;
28
+ /**
29
+ * Returns the longitude and latitude coordinates from a given PointerEvent on the map.
30
+ * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
31
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.
32
+ */
33
+ getLngLatFromEvent(event: PointerEvent | MouseEvent): {
34
+ lng: number;
35
+ lat: number;
36
+ };
37
+ /**
38
+ *Retrieves the HTML element of the Mapbox element that handles interaction events
39
+ * @returns The HTMLElement representing the map container.
40
+ */
41
+ getMapEventElement(): HTMLCanvasElement;
42
+ /**
43
+ * Enables or disables the draggable functionality of the map.
44
+ * @param enabled Set to true to enable map dragging, or false to disable it.
45
+ */
46
+ setDraggability(enabled: boolean): void;
47
+ /**
48
+ * Converts longitude and latitude coordinates to pixel coordinates in the map container.
49
+ * @param lng The longitude coordinate to project.
50
+ * @param lat The latitude coordinate to project.
51
+ * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.
52
+ */
53
+ project(lng: number, lat: number): {
54
+ x: number;
55
+ y: number;
56
+ };
57
+ /**
58
+ * Converts pixel coordinates in the map container to longitude and latitude coordinates.
59
+ * @param x The x-coordinate in the map container to unproject.
60
+ * @param y The y-coordinate in the map container to unproject.
61
+ * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.
62
+ */
63
+ unproject(x: number, y: number): {
64
+ lng: number;
65
+ lat: number;
66
+ };
67
+ /**
68
+ * Sets the cursor style for the map container.
69
+ * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.
70
+ */
71
+ setCursor(cursor: Parameters<SetCursor>[0]): void;
72
+ /**
73
+ * Enables or disables the double-click to zoom functionality on the map.
74
+ * @param enabled Set to true to enable double-click to zoom, or false to disable it.
75
+ */
76
+ setDoubleClickToZoom(enabled: boolean): void;
77
+ /**
78
+ * Renders GeoJSON features on the map using the provided styling configuration.
79
+ * @param changes An object containing arrays of created, updated, and unchanged features to render.
80
+ * @param styling An object mapping draw modes to feature styling functions
81
+ */
82
+ render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void;
83
+ /**
84
+ * Clears the map and store of all rendered data layers
85
+ * @returns void
86
+ * */
87
+ clear(): void;
88
+ getCoordinatePrecision(): number;
89
+ unregister(): void;
90
+ register(callbacks: TerraDrawCallbacks): void;
91
+ }