terra-draw 1.0.0-beta.1 → 1.0.0-beta.11
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/README.md +9 -2
- package/dist/adapters/common/adapter-listener.d.ts +22 -0
- package/dist/adapters/common/base.adapter.d.ts +59 -0
- package/dist/adapters/mapbox-gl.adapter.d.ts +0 -1
- package/dist/adapters/openlayers.adapter.d.ts +14 -13
- package/dist/common.d.ts +11 -9
- package/dist/extend.d.ts +4 -0
- package/dist/geometry/calculate-relative-angle.d.ts +2 -10
- package/dist/geometry/clockwise.d.ts +2 -0
- package/dist/geometry/determine-halfplane.d.ts +2 -10
- package/dist/geometry/measure/bearing.d.ts +3 -7
- package/dist/geometry/measure/destination.d.ts +2 -7
- package/dist/geometry/measure/pixel-distance-to-line.d.ts +2 -10
- package/dist/geometry/measure/pixel-distance.d.ts +2 -7
- package/dist/geometry/point-on-line.d.ts +5 -0
- package/dist/geometry/project/web-mercator.d.ts +2 -4
- package/dist/geometry/web-mercator-centroid.d.ts +2 -4
- package/dist/geometry/web-mercator-point-on-line.d.ts +11 -0
- package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +2 -7
- package/dist/modes/base.mode.d.ts +3 -1
- package/dist/modes/circle/circle.mode.d.ts +3 -2
- package/dist/modes/coordinate-snapping.behavior.d.ts +16 -0
- package/dist/modes/freehand/freehand.mode.d.ts +8 -2
- package/dist/modes/{snapping.behavior.d.ts → line-snapping.behavior.d.ts} +1 -1
- package/dist/modes/linestring/linestring.mode.d.ts +16 -5
- package/dist/modes/point/point.mode.d.ts +2 -2
- package/dist/modes/polygon/polygon.mode.d.ts +17 -4
- package/dist/modes/rectangle/rectangle.mode.d.ts +2 -2
- package/dist/modes/render/render.mode.d.ts +2 -1
- package/dist/modes/sector/sector.mode.d.ts +60 -0
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +2 -2
- package/dist/modes/sensor/sensor.mode.d.ts +69 -0
- package/dist/store/store-feature-validation.d.ts +8 -2
- package/dist/store/store.d.ts +7 -3
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +12 -13
- 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/validation-reasons.d.ts +13 -0
- package/dist/validations/common-validations.d.ts +2 -0
- package/dist/validations/linestring.validation.d.ts +4 -1
- package/dist/validations/max-size.validation.d.ts +3 -1
- package/dist/validations/min-size.validation.d.ts +3 -1
- package/dist/validations/not-self-intersecting.validation.d.ts +4 -1
- package/dist/validations/point.validation.d.ts +4 -1
- package/dist/validations/polygon.validation.d.ts +8 -2
- package/e2e/package-lock.json +5 -4
- package/e2e/package.json +1 -1
- package/e2e/public/index.html +2 -0
- package/e2e/tests/leaflet.spec.ts +414 -18
- package/e2e/tests/setup.ts +16 -5
- package/eslint.config.js +32 -0
- package/package.json +29 -28
- package/tsconfig.json +2 -1
- package/readme.gif +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
<
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="./assets/logo-dark-mode.png">
|
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="./assets/logo.png">
|
|
4
|
+
<img alt="Terra Draw logo" src="./assets/logo.png" width="400px">
|
|
5
|
+
</picture>
|
|
6
|
+
|
|
7
|
+
<p></p>
|
|
2
8
|
|
|
3
9
|

|
|
4
10
|
[](https://badge.fury.io/js/terra-draw)
|
|
@@ -7,7 +13,8 @@ Frictionless map drawing across mapping libraries.
|
|
|
7
13
|
|
|
8
14
|
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
15
|
|
|
10
|
-

|
|
16
|
+

|
|
17
|
+
|
|
11
18
|
|
|
12
19
|
### Library Support
|
|
13
20
|
|
|
@@ -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, TerraDrawAdapter } 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 implements TerraDrawAdapter {
|
|
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
|
+
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. The coordinate precision is the number of decimal places in geometry
|
|
39
|
+
* coordinates stored in the store.
|
|
40
|
+
* @returns {number} The coordinate precision.
|
|
41
|
+
*/
|
|
42
|
+
getCoordinatePrecision(): number;
|
|
43
|
+
protected getAdapterListeners(): AdapterListener<BasePointerListener>[];
|
|
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,30 +1,31 @@
|
|
|
1
1
|
import { TerraDrawChanges, SetCursor, TerraDrawStylingFunction, TerraDrawCallbacks } from "../common";
|
|
2
|
-
import CircleGeom from "ol/geom/Circle";
|
|
3
2
|
import Feature from "ol/Feature";
|
|
4
3
|
import GeoJSON from "ol/format/GeoJSON";
|
|
5
4
|
import Map from "ol/Map";
|
|
6
5
|
import Circle from "ol/style/Circle";
|
|
6
|
+
import Fill from "ol/style/Fill";
|
|
7
7
|
import Stroke from "ol/style/Stroke";
|
|
8
8
|
import Style from "ol/style/Style";
|
|
9
9
|
import VectorSource from "ol/source/Vector";
|
|
10
10
|
import VectorLayer from "ol/layer/Vector";
|
|
11
|
-
import {
|
|
11
|
+
import { getUserProjection } from "ol/proj";
|
|
12
12
|
import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
|
|
13
|
-
type InjectableOL = {
|
|
14
|
-
|
|
13
|
+
export type InjectableOL = {
|
|
14
|
+
Fill: typeof Fill;
|
|
15
15
|
Feature: typeof Feature;
|
|
16
16
|
GeoJSON: typeof GeoJSON;
|
|
17
17
|
Style: typeof Style;
|
|
18
|
-
|
|
18
|
+
Circle: typeof Circle;
|
|
19
19
|
VectorLayer: typeof VectorLayer;
|
|
20
20
|
VectorSource: typeof VectorSource;
|
|
21
21
|
Stroke: typeof Stroke;
|
|
22
|
-
|
|
22
|
+
getUserProjection: typeof getUserProjection;
|
|
23
23
|
};
|
|
24
24
|
export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
|
|
25
25
|
constructor(config: {
|
|
26
26
|
map: Map;
|
|
27
27
|
lib: InjectableOL;
|
|
28
|
+
zIndex?: number;
|
|
28
29
|
} & BaseAdapterConfig);
|
|
29
30
|
private stylingFunction;
|
|
30
31
|
private _lib;
|
|
@@ -39,12 +40,6 @@ export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
|
|
|
39
40
|
* @returns an object to red green and blue (RGB) color
|
|
40
41
|
*/
|
|
41
42
|
private hexToRGB;
|
|
42
|
-
/**
|
|
43
|
-
* Converts a hexideciaml color to RGB
|
|
44
|
-
* @param feature
|
|
45
|
-
* @param styling
|
|
46
|
-
* @returns an object to red green and blue (RGB) color
|
|
47
|
-
*/
|
|
48
43
|
private getStyles;
|
|
49
44
|
/**
|
|
50
45
|
* Clears the layers created by the adapter
|
|
@@ -53,6 +48,12 @@ export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
|
|
|
53
48
|
private clearLayers;
|
|
54
49
|
private addFeature;
|
|
55
50
|
private removeFeature;
|
|
51
|
+
/**
|
|
52
|
+
* Sorts an array of DOM elements based on their order in the document, from earliest to latest.
|
|
53
|
+
* @param elements - An array of `HTMLElement` objects to be sorted.
|
|
54
|
+
* @returns A new array of `HTMLElement` objects sorted by their document order.
|
|
55
|
+
*/
|
|
56
|
+
private sortElementsByDOMOrder;
|
|
56
57
|
/**
|
|
57
58
|
* Returns the longitude and latitude coordinates from a given PointerEvent on the map.
|
|
58
59
|
* @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.
|
|
@@ -113,8 +114,8 @@ export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
|
|
|
113
114
|
* @returns void
|
|
114
115
|
* */
|
|
115
116
|
clear(): void;
|
|
117
|
+
private registeredLayerHandlers;
|
|
116
118
|
register(callbacks: TerraDrawCallbacks): void;
|
|
117
119
|
getCoordinatePrecision(): number;
|
|
118
120
|
unregister(): void;
|
|
119
121
|
}
|
|
120
|
-
export {};
|
package/dist/common.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface TerraDrawAdapterStyling {
|
|
|
15
15
|
lineStringColor: HexColor;
|
|
16
16
|
zIndex: number;
|
|
17
17
|
}
|
|
18
|
+
export type CartesianPoint = {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
};
|
|
18
22
|
export interface TerraDrawMouseEvent {
|
|
19
23
|
lng: number;
|
|
20
24
|
lat: number;
|
|
@@ -28,15 +32,9 @@ export interface TerraDrawKeyboardEvent {
|
|
|
28
32
|
heldKeys: string[];
|
|
29
33
|
preventDefault: () => void;
|
|
30
34
|
}
|
|
31
|
-
export type Required<T> = {
|
|
32
|
-
[P in keyof T]-?: T[P];
|
|
33
|
-
};
|
|
34
35
|
export type Cursor = Parameters<SetCursor>[0];
|
|
35
36
|
export type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer" | "wait" | "move") => void;
|
|
36
|
-
export type Project = (lng: number, lat: number) =>
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
|
-
};
|
|
37
|
+
export type Project = (lng: number, lat: number) => CartesianPoint;
|
|
40
38
|
export type Unproject = (x: number, y: number) => {
|
|
41
39
|
lat: number;
|
|
42
40
|
lng: number;
|
|
@@ -71,7 +69,10 @@ export declare enum UpdateTypes {
|
|
|
71
69
|
type ValidationContext = Pick<TerraDrawModeRegisterConfig, "project" | "unproject" | "coordinatePrecision"> & {
|
|
72
70
|
updateType: UpdateTypes;
|
|
73
71
|
};
|
|
74
|
-
export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) =>
|
|
72
|
+
export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) => {
|
|
73
|
+
valid: boolean;
|
|
74
|
+
reason?: string;
|
|
75
|
+
};
|
|
75
76
|
export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped";
|
|
76
77
|
export interface TerraDrawCallbacks {
|
|
77
78
|
getState: () => TerraDrawModeState;
|
|
@@ -112,7 +113,8 @@ export declare const SELECT_PROPERTIES: {
|
|
|
112
113
|
readonly MID_POINT: "midPoint";
|
|
113
114
|
readonly SELECTION_POINT: "selectionPoint";
|
|
114
115
|
};
|
|
115
|
-
export declare const
|
|
116
|
+
export declare const COMMON_PROPERTIES: {
|
|
116
117
|
CLOSING_POINT: string;
|
|
118
|
+
SNAPPING_POINT: string;
|
|
117
119
|
};
|
|
118
120
|
export {};
|
package/dist/extend.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TerraDrawBaseAdapter, BaseAdapterConfig } from "./adapters/common/base.adapter";
|
|
2
|
+
import { HexColorStyling, NumericStyling, TerraDrawCallbacks } from "./common";
|
|
3
|
+
import { BaseModeOptions, TerraDrawBaseDrawMode } from "./modes/base.mode";
|
|
4
|
+
export { TerraDrawBaseDrawMode, TerraDrawBaseAdapter, BaseAdapterConfig, NumericStyling, HexColorStyling, BaseModeOptions, TerraDrawCallbacks, };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CartesianPoint } from "../common";
|
|
1
2
|
/**
|
|
2
3
|
* Calculate the relative angle between two lines
|
|
3
4
|
* @param A The first point of the first line
|
|
@@ -5,13 +6,4 @@
|
|
|
5
6
|
* @param C The second point of the second line
|
|
6
7
|
* @returns The relative angle between the two lines
|
|
7
8
|
*/
|
|
8
|
-
export declare function calculateRelativeAngle(A:
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}, B: {
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
14
|
-
}, C: {
|
|
15
|
-
x: number;
|
|
16
|
-
y: number;
|
|
17
|
-
}): number;
|
|
9
|
+
export declare function calculateRelativeAngle(A: CartesianPoint, B: CartesianPoint, C: CartesianPoint): number;
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
y: number;
|
|
4
|
-
}, lineStart: {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
}, lineEnd: {
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
}): string;
|
|
1
|
+
import { CartesianPoint } from "../common";
|
|
2
|
+
export declare function determineHalfPlane(point: CartesianPoint, lineStart: CartesianPoint, lineEnd: CartesianPoint): string;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { Position } from "geojson";
|
|
2
|
+
import { CartesianPoint } from "../../common";
|
|
2
3
|
export declare function bearing(start: Position, end: Position): number;
|
|
3
|
-
export declare function webMercatorBearing({ x: x1, y: y1 }: {
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
6
|
-
}, { x: x2, y: y2 }: {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
}): number;
|
|
4
|
+
export declare function webMercatorBearing({ x: x1, y: y1 }: CartesianPoint, { x: x2, y: y2 }: CartesianPoint): number;
|
|
5
|
+
export declare function normalizeBearing(bearing: number): number;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { Position } from "geojson";
|
|
2
|
+
import { CartesianPoint } from "../../common";
|
|
2
3
|
export declare function destination(origin: Position, distance: number, bearing: number): Position;
|
|
3
|
-
export declare function webMercatorDestination({ x, y }:
|
|
4
|
-
x: number;
|
|
5
|
-
y: number;
|
|
6
|
-
}, distance: number, bearing: number): {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
};
|
|
4
|
+
export declare function webMercatorDestination({ x, y }: CartesianPoint, distance: number, bearing: number): CartesianPoint;
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
y: number;
|
|
4
|
-
}, linePointOne: {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
}, linePointTwo: {
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
}) => number;
|
|
1
|
+
import { CartesianPoint } from "../../common";
|
|
2
|
+
export declare const pixelDistanceToLine: (point: CartesianPoint, linePointOne: CartesianPoint, linePointTwo: CartesianPoint) => number;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
y: number;
|
|
4
|
-
}, pointTwo: {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
}) => number;
|
|
1
|
+
import { CartesianPoint } from "../../common";
|
|
2
|
+
export declare const cartesianDistance: (pointOne: CartesianPoint, pointTwo: CartesianPoint) => number;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import { CartesianPoint } from "../../common";
|
|
1
2
|
/**
|
|
2
3
|
* Convert longitude and latitude to web mercator x and y
|
|
3
4
|
* @param lng
|
|
4
5
|
* @param lat
|
|
5
6
|
* @returns - web mercator x and y
|
|
6
7
|
*/
|
|
7
|
-
export declare const lngLatToWebMercatorXY: (lng: number, lat: number) =>
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
};
|
|
8
|
+
export declare const lngLatToWebMercatorXY: (lng: number, lat: number) => CartesianPoint;
|
|
11
9
|
/**
|
|
12
10
|
* Convert web mercator x and y to longitude and latitude
|
|
13
11
|
* @param x - web mercator x
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Feature, LineString, Polygon } from "geojson";
|
|
2
|
+
import { CartesianPoint } from "../common";
|
|
2
3
|
/**
|
|
3
4
|
* Calculates the centroid of a GeoJSON Polygon or LineString in Web Mercator
|
|
4
5
|
|
|
5
6
|
* @param {Feature<Polygon | LineString>} feature - The GeoJSON Feature containing either a Polygon or LineString
|
|
6
7
|
* @returns {{ x: number, y: number }} The centroid of the polygon or line string in Web Mercator coordinates.
|
|
7
8
|
*/
|
|
8
|
-
export declare function webMercatorCentroid(feature: Feature<Polygon | LineString>):
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
};
|
|
9
|
+
export declare function webMercatorCentroid(feature: Feature<Polygon | LineString>): CartesianPoint;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Position } from "geojson";
|
|
2
|
+
/**
|
|
3
|
+
* Takes two points and finds the closest point on the line between them to a third point.
|
|
4
|
+
* @param lines
|
|
5
|
+
* @param inputCoordinate
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function webMercatorNearestPointOnLine(inputCoordinate: Position, lines: [Position, Position][]): {
|
|
9
|
+
coordinate: Position;
|
|
10
|
+
distance: number;
|
|
11
|
+
} | undefined;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
|
|
2
2
|
import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling } from "../base.mode";
|
|
3
|
-
import {
|
|
4
|
-
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
3
|
+
import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
|
|
5
4
|
type TerraDrawPolygonModeKeyEvents = {
|
|
6
5
|
cancel?: KeyboardEvent["key"] | null;
|
|
7
6
|
finish?: KeyboardEvent["key"] | null;
|
|
@@ -17,7 +16,6 @@ interface Cursors {
|
|
|
17
16
|
close?: Cursor;
|
|
18
17
|
}
|
|
19
18
|
interface TerraDrawPolygonModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
|
|
20
|
-
snapping?: boolean;
|
|
21
19
|
pointerDistance?: number;
|
|
22
20
|
keyEvents?: TerraDrawPolygonModeKeyEvents | null;
|
|
23
21
|
cursors?: Cursors;
|
|
@@ -27,14 +25,11 @@ export declare class TerraDrawAngledRectangleMode extends TerraDrawBaseDrawMode<
|
|
|
27
25
|
private currentCoordinate;
|
|
28
26
|
private currentId;
|
|
29
27
|
private keyEvents;
|
|
30
|
-
private pixelDistance;
|
|
31
28
|
private cursors;
|
|
32
29
|
private mouseMove;
|
|
33
30
|
constructor(options?: TerraDrawPolygonModeOptions<PolygonStyling>);
|
|
34
31
|
private close;
|
|
35
32
|
/** @internal */
|
|
36
|
-
registerBehaviors(config: BehaviorConfig): void;
|
|
37
|
-
/** @internal */
|
|
38
33
|
start(): void;
|
|
39
34
|
/** @internal */
|
|
40
35
|
stop(): void;
|
|
@@ -57,6 +52,6 @@ export declare class TerraDrawAngledRectangleMode extends TerraDrawBaseDrawMode<
|
|
|
57
52
|
cleanUp(): void;
|
|
58
53
|
/** @internal */
|
|
59
54
|
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
60
|
-
validateFeature(feature: unknown):
|
|
55
|
+
validateFeature(feature: unknown): StoreValidation;
|
|
61
56
|
}
|
|
62
57
|
export {};
|
|
@@ -40,7 +40,9 @@ export declare abstract class TerraDrawBaseDrawMode<T extends CustomStyling> {
|
|
|
40
40
|
protected setStarted(): void;
|
|
41
41
|
protected setStopped(): void;
|
|
42
42
|
register(config: TerraDrawModeRegisterConfig): void;
|
|
43
|
-
validateFeature(feature: unknown):
|
|
43
|
+
validateFeature(feature: unknown): ReturnType<Validation>;
|
|
44
|
+
private performFeatureValidation;
|
|
45
|
+
protected validateModeFeature(feature: unknown, modeValidationFn: (feature: GeoJSONStoreFeatures) => ReturnType<Validation>): ReturnType<Validation>;
|
|
44
46
|
abstract start(): void;
|
|
45
47
|
abstract stop(): void;
|
|
46
48
|
abstract cleanUp(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor, Projection } from "../../common";
|
|
2
|
-
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
2
|
+
import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
|
|
3
3
|
import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
|
|
4
4
|
type TerraDrawCircleModeKeyEvents = {
|
|
5
5
|
cancel: KeyboardEvent["key"] | null;
|
|
@@ -28,6 +28,7 @@ export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePol
|
|
|
28
28
|
private keyEvents;
|
|
29
29
|
private cursors;
|
|
30
30
|
private startingRadiusKilometers;
|
|
31
|
+
private cursorMovedAfterInitialCursorDown;
|
|
31
32
|
/**
|
|
32
33
|
* Create a new circle mode instance
|
|
33
34
|
* @param options - Options to customize the behavior of the circle mode
|
|
@@ -60,7 +61,7 @@ export declare class TerraDrawCircleMode extends TerraDrawBaseDrawMode<CirclePol
|
|
|
60
61
|
cleanUp(): void;
|
|
61
62
|
/** @internal */
|
|
62
63
|
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
63
|
-
validateFeature(feature: unknown):
|
|
64
|
+
validateFeature(feature: unknown): StoreValidation;
|
|
64
65
|
private updateCircle;
|
|
65
66
|
}
|
|
66
67
|
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "./base.behavior";
|
|
2
|
+
import { TerraDrawMouseEvent } from "../common";
|
|
3
|
+
import { Position } from "geojson";
|
|
4
|
+
import { ClickBoundingBoxBehavior } from "./click-bounding-box.behavior";
|
|
5
|
+
import { FeatureId } from "../store/store";
|
|
6
|
+
import { PixelDistanceBehavior } from "./pixel-distance.behavior";
|
|
7
|
+
export declare class CoordinateSnappingBehavior extends TerraDrawModeBehavior {
|
|
8
|
+
readonly config: BehaviorConfig;
|
|
9
|
+
private readonly pixelDistance;
|
|
10
|
+
private readonly clickBoundingBox;
|
|
11
|
+
constructor(config: BehaviorConfig, pixelDistance: PixelDistanceBehavior, clickBoundingBox: ClickBoundingBoxBehavior);
|
|
12
|
+
/** Returns the nearest snappable coordinate - on first click there is no currentId so no need to provide */
|
|
13
|
+
getSnappableCoordinateFirstClick: (event: TerraDrawMouseEvent) => Position | undefined;
|
|
14
|
+
getSnappableCoordinate: (event: TerraDrawMouseEvent, currentFeatureId: FeatureId) => Position | undefined;
|
|
15
|
+
private getSnappable;
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
|
|
2
2
|
import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
|
|
3
|
-
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
3
|
+
import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
|
|
4
4
|
type TerraDrawFreehandModeKeyEvents = {
|
|
5
5
|
cancel: KeyboardEvent["key"] | null;
|
|
6
6
|
finish: KeyboardEvent["key"] | null;
|
|
@@ -22,6 +22,8 @@ interface Cursors {
|
|
|
22
22
|
interface TerraDrawFreehandModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
|
|
23
23
|
minDistance?: number;
|
|
24
24
|
preventPointsNearClose?: boolean;
|
|
25
|
+
autoClose?: boolean;
|
|
26
|
+
autoCloseTimeout?: number;
|
|
25
27
|
keyEvents?: TerraDrawFreehandModeKeyEvents | null;
|
|
26
28
|
cursors?: Cursors;
|
|
27
29
|
}
|
|
@@ -34,6 +36,10 @@ export declare class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<Freehan
|
|
|
34
36
|
private keyEvents;
|
|
35
37
|
private cursors;
|
|
36
38
|
private preventPointsNearClose;
|
|
39
|
+
private autoClose;
|
|
40
|
+
private autoCloseTimeout;
|
|
41
|
+
private hasLeftStartingPoint;
|
|
42
|
+
private preventNewFeature;
|
|
37
43
|
constructor(options?: TerraDrawFreehandModeOptions<FreehandPolygonStyling>);
|
|
38
44
|
private close;
|
|
39
45
|
/** @internal */
|
|
@@ -58,6 +64,6 @@ export declare class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<Freehan
|
|
|
58
64
|
cleanUp(): void;
|
|
59
65
|
/** @internal */
|
|
60
66
|
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
61
|
-
validateFeature(feature: unknown):
|
|
67
|
+
validateFeature(feature: unknown): StoreValidation;
|
|
62
68
|
}
|
|
63
69
|
export {};
|
|
@@ -4,7 +4,7 @@ import { Position } from "geojson";
|
|
|
4
4
|
import { ClickBoundingBoxBehavior } from "./click-bounding-box.behavior";
|
|
5
5
|
import { FeatureId } from "../store/store";
|
|
6
6
|
import { PixelDistanceBehavior } from "./pixel-distance.behavior";
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class LineSnappingBehavior extends TerraDrawModeBehavior {
|
|
8
8
|
readonly config: BehaviorConfig;
|
|
9
9
|
private readonly pixelDistance;
|
|
10
10
|
private readonly clickBoundingBox;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
|
|
2
|
+
import { Position } from "geojson";
|
|
2
3
|
import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
|
|
3
4
|
import { BehaviorConfig } from "../base.behavior";
|
|
4
|
-
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
5
|
+
import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
|
|
5
6
|
type TerraDrawLineStringModeKeyEvents = {
|
|
6
7
|
cancel: KeyboardEvent["key"] | null;
|
|
7
8
|
finish: KeyboardEvent["key"] | null;
|
|
@@ -13,6 +14,10 @@ type LineStringStyling = {
|
|
|
13
14
|
closingPointWidth: NumericStyling;
|
|
14
15
|
closingPointOutlineColor: HexColorStyling;
|
|
15
16
|
closingPointOutlineWidth: NumericStyling;
|
|
17
|
+
snappingPointColor: HexColorStyling;
|
|
18
|
+
snappingPointWidth: NumericStyling;
|
|
19
|
+
snappingPointOutlineColor: HexColorStyling;
|
|
20
|
+
snappingPointOutlineWidth: NumericStyling;
|
|
16
21
|
};
|
|
17
22
|
interface Cursors {
|
|
18
23
|
start?: Cursor;
|
|
@@ -22,8 +27,12 @@ interface InertCoordinates {
|
|
|
22
27
|
strategy: "amount";
|
|
23
28
|
value: number;
|
|
24
29
|
}
|
|
30
|
+
interface Snapping {
|
|
31
|
+
toCoordinate?: boolean;
|
|
32
|
+
toCustom?: (event: TerraDrawMouseEvent) => Position | undefined;
|
|
33
|
+
}
|
|
25
34
|
interface TerraDrawLineStringModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
|
|
26
|
-
snapping?:
|
|
35
|
+
snapping?: Snapping;
|
|
27
36
|
pointerDistance?: number;
|
|
28
37
|
keyEvents?: TerraDrawLineStringModeKeyEvents | null;
|
|
29
38
|
cursors?: Cursors;
|
|
@@ -35,12 +44,13 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
|
|
|
35
44
|
private currentId;
|
|
36
45
|
private closingPointId;
|
|
37
46
|
private keyEvents;
|
|
38
|
-
private
|
|
47
|
+
private snapping;
|
|
39
48
|
private cursors;
|
|
40
49
|
private mouseMove;
|
|
41
50
|
private insertCoordinates;
|
|
42
51
|
private lastCommitedCoordinates;
|
|
43
|
-
private
|
|
52
|
+
private snappedPointId;
|
|
53
|
+
private coordinateSnapping;
|
|
44
54
|
private insertPoint;
|
|
45
55
|
constructor(options?: TerraDrawLineStringModeOptions<LineStringStyling>);
|
|
46
56
|
private close;
|
|
@@ -73,6 +83,7 @@ export declare class TerraDrawLineStringMode extends TerraDrawBaseDrawMode<LineS
|
|
|
73
83
|
cleanUp(): void;
|
|
74
84
|
/** @internal */
|
|
75
85
|
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
76
|
-
validateFeature(feature: unknown):
|
|
86
|
+
validateFeature(feature: unknown): StoreValidation;
|
|
87
|
+
private snapCoordinate;
|
|
77
88
|
}
|
|
78
89
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, NumericStyling, HexColorStyling, Cursor } from "../../common";
|
|
2
|
-
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
2
|
+
import { GeoJSONStoreFeatures, StoreValidation } from "../../store/store";
|
|
3
3
|
import { BaseModeOptions, CustomStyling, TerraDrawBaseDrawMode } from "../base.mode";
|
|
4
4
|
type PointModeStyling = {
|
|
5
5
|
pointWidth: NumericStyling;
|
|
@@ -39,6 +39,6 @@ export declare class TerraDrawPointMode extends TerraDrawBaseDrawMode<PointModeS
|
|
|
39
39
|
onDragEnd(): void;
|
|
40
40
|
/** @internal */
|
|
41
41
|
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
42
|
-
validateFeature(feature: unknown):
|
|
42
|
+
validateFeature(feature: unknown): StoreValidation;
|
|
43
43
|
}
|
|
44
44
|
export {};
|