terra-draw 1.0.0-beta.0 → 1.0.0-beta.3
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 +10 -3
- package/dist/adapters/mapbox-gl.adapter.d.ts +0 -1
- package/dist/adapters/openlayers.adapter.d.ts +6 -13
- package/dist/common.d.ts +0 -3
- package/dist/geometry/calculate-relative-angle.d.ts +17 -0
- package/dist/geometry/clockwise.d.ts +10 -0
- package/dist/geometry/determine-halfplane.d.ts +10 -0
- package/dist/geometry/measure/bearing.d.ts +1 -0
- package/dist/geometry/measure/destination.d.ts +7 -0
- package/dist/geometry/measure/pixel-distance.d.ts +1 -1
- package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +58 -0
- package/dist/modes/sector/sector.mode.d.ts +60 -0
- package/dist/store/store.d.ts +2 -2
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +3 -1
- 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/e2e/public/index.html +2 -0
- package/e2e/tests/leaflet.spec.ts +216 -14
- package/e2e/tests/setup.ts +24 -3
- package/package.json +19 -5
- 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,14 +13,15 @@ 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
|
|
|
14
21
|
Terra Draw uses the concept of 'adapters' to allow it to work with a host of different mapping libraries. Currently supported are:
|
|
15
22
|
|
|
16
23
|
- [Leaflet](https://leafletjs.com/) v1
|
|
17
|
-
- [OpenLayers](https://openlayers.org/)
|
|
24
|
+
- [OpenLayers](https://openlayers.org/) v10
|
|
18
25
|
- [Mapbox GL JS](https://www.mapbox.com/mapbox-gljs) v2
|
|
19
26
|
- [MapLibre](https://maplibre.org/maplibre-gl-js/docs/) v2/v3
|
|
20
27
|
- [Google Maps JS API](https://developers.google.com/maps/documentation/javascript/overview) v3
|
|
@@ -1,25 +1,25 @@
|
|
|
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: {
|
|
@@ -39,12 +39,6 @@ export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
|
|
|
39
39
|
* @returns an object to red green and blue (RGB) color
|
|
40
40
|
*/
|
|
41
41
|
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
42
|
private getStyles;
|
|
49
43
|
/**
|
|
50
44
|
* Clears the layers created by the adapter
|
|
@@ -117,4 +111,3 @@ export declare class TerraDrawOpenLayersAdapter extends TerraDrawBaseAdapter {
|
|
|
117
111
|
getCoordinatePrecision(): number;
|
|
118
112
|
unregister(): void;
|
|
119
113
|
}
|
|
120
|
-
export {};
|
package/dist/common.d.ts
CHANGED
|
@@ -28,9 +28,6 @@ export interface TerraDrawKeyboardEvent {
|
|
|
28
28
|
heldKeys: string[];
|
|
29
29
|
preventDefault: () => void;
|
|
30
30
|
}
|
|
31
|
-
export type Required<T> = {
|
|
32
|
-
[P in keyof T]-?: T[P];
|
|
33
|
-
};
|
|
34
31
|
export type Cursor = Parameters<SetCursor>[0];
|
|
35
32
|
export type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer" | "wait" | "move") => void;
|
|
36
33
|
export type Project = (lng: number, lat: number) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the relative angle between two lines
|
|
3
|
+
* @param A The first point of the first line
|
|
4
|
+
* @param B The second point of the first line and the first point of the second line
|
|
5
|
+
* @param C The second point of the second line
|
|
6
|
+
* @returns The relative angle between the two lines
|
|
7
|
+
*/
|
|
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;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { Position } from "geojson";
|
|
2
2
|
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
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
|
|
2
|
+
import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling } from "../base.mode";
|
|
3
|
+
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
4
|
+
type TerraDrawPolygonModeKeyEvents = {
|
|
5
|
+
cancel?: KeyboardEvent["key"] | null;
|
|
6
|
+
finish?: KeyboardEvent["key"] | null;
|
|
7
|
+
};
|
|
8
|
+
type PolygonStyling = {
|
|
9
|
+
fillColor: HexColorStyling;
|
|
10
|
+
outlineColor: HexColorStyling;
|
|
11
|
+
outlineWidth: NumericStyling;
|
|
12
|
+
fillOpacity: NumericStyling;
|
|
13
|
+
};
|
|
14
|
+
interface Cursors {
|
|
15
|
+
start?: Cursor;
|
|
16
|
+
close?: Cursor;
|
|
17
|
+
}
|
|
18
|
+
interface TerraDrawPolygonModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
|
|
19
|
+
snapping?: boolean;
|
|
20
|
+
pointerDistance?: number;
|
|
21
|
+
keyEvents?: TerraDrawPolygonModeKeyEvents | null;
|
|
22
|
+
cursors?: Cursors;
|
|
23
|
+
}
|
|
24
|
+
export declare class TerraDrawAngledRectangleMode extends TerraDrawBaseDrawMode<PolygonStyling> {
|
|
25
|
+
mode: string;
|
|
26
|
+
private currentCoordinate;
|
|
27
|
+
private currentId;
|
|
28
|
+
private keyEvents;
|
|
29
|
+
private cursors;
|
|
30
|
+
private mouseMove;
|
|
31
|
+
constructor(options?: TerraDrawPolygonModeOptions<PolygonStyling>);
|
|
32
|
+
private close;
|
|
33
|
+
/** @internal */
|
|
34
|
+
start(): void;
|
|
35
|
+
/** @internal */
|
|
36
|
+
stop(): void;
|
|
37
|
+
/** @internal */
|
|
38
|
+
onMouseMove(event: TerraDrawMouseEvent): void;
|
|
39
|
+
private updatePolygonGeometry;
|
|
40
|
+
/** @internal */
|
|
41
|
+
onClick(event: TerraDrawMouseEvent): void;
|
|
42
|
+
/** @internal */
|
|
43
|
+
onKeyUp(event: TerraDrawKeyboardEvent): void;
|
|
44
|
+
/** @internal */
|
|
45
|
+
onKeyDown(): void;
|
|
46
|
+
/** @internal */
|
|
47
|
+
onDragStart(): void;
|
|
48
|
+
/** @internal */
|
|
49
|
+
onDrag(): void;
|
|
50
|
+
/** @internal */
|
|
51
|
+
onDragEnd(): void;
|
|
52
|
+
/** @internal */
|
|
53
|
+
cleanUp(): void;
|
|
54
|
+
/** @internal */
|
|
55
|
+
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
56
|
+
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
|
|
2
|
+
import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling } from "../base.mode";
|
|
3
|
+
import { GeoJSONStoreFeatures } from "../../store/store";
|
|
4
|
+
type TerraDrawSectorModeKeyEvents = {
|
|
5
|
+
cancel?: KeyboardEvent["key"] | null;
|
|
6
|
+
finish?: KeyboardEvent["key"] | null;
|
|
7
|
+
};
|
|
8
|
+
type SectorPolygonStyling = {
|
|
9
|
+
fillColor: HexColorStyling;
|
|
10
|
+
outlineColor: HexColorStyling;
|
|
11
|
+
outlineWidth: NumericStyling;
|
|
12
|
+
fillOpacity: NumericStyling;
|
|
13
|
+
};
|
|
14
|
+
interface Cursors {
|
|
15
|
+
start?: Cursor;
|
|
16
|
+
close?: Cursor;
|
|
17
|
+
}
|
|
18
|
+
interface TerraDrawSectorModeOptions<T extends CustomStyling> extends BaseModeOptions<T> {
|
|
19
|
+
arcPoints?: number;
|
|
20
|
+
pointerDistance?: number;
|
|
21
|
+
keyEvents?: TerraDrawSectorModeKeyEvents | null;
|
|
22
|
+
cursors?: Cursors;
|
|
23
|
+
}
|
|
24
|
+
export declare class TerraDrawSectorMode extends TerraDrawBaseDrawMode<SectorPolygonStyling> {
|
|
25
|
+
mode: string;
|
|
26
|
+
private currentCoordinate;
|
|
27
|
+
private currentId;
|
|
28
|
+
private keyEvents;
|
|
29
|
+
private direction;
|
|
30
|
+
private arcPoints;
|
|
31
|
+
private cursors;
|
|
32
|
+
private mouseMove;
|
|
33
|
+
constructor(options?: TerraDrawSectorModeOptions<SectorPolygonStyling>);
|
|
34
|
+
private close;
|
|
35
|
+
/** @internal */
|
|
36
|
+
start(): void;
|
|
37
|
+
/** @internal */
|
|
38
|
+
stop(): void;
|
|
39
|
+
/** @internal */
|
|
40
|
+
onMouseMove(event: TerraDrawMouseEvent): void;
|
|
41
|
+
private updatePolygonGeometry;
|
|
42
|
+
/** @internal */
|
|
43
|
+
onClick(event: TerraDrawMouseEvent): void;
|
|
44
|
+
/** @internal */
|
|
45
|
+
onKeyUp(event: TerraDrawKeyboardEvent): void;
|
|
46
|
+
/** @internal */
|
|
47
|
+
onKeyDown(): void;
|
|
48
|
+
/** @internal */
|
|
49
|
+
onDragStart(): void;
|
|
50
|
+
/** @internal */
|
|
51
|
+
onDrag(): void;
|
|
52
|
+
/** @internal */
|
|
53
|
+
onDragEnd(): void;
|
|
54
|
+
/** @internal */
|
|
55
|
+
cleanUp(): void;
|
|
56
|
+
/** @internal */
|
|
57
|
+
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling;
|
|
58
|
+
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
package/dist/store/store.d.ts
CHANGED
|
@@ -8,14 +8,14 @@ type DefinedProperties = Record<string, JSON>;
|
|
|
8
8
|
export type GeoJSONStoreGeometries = Polygon | LineString | Point;
|
|
9
9
|
export type BBoxPolygon = Feature<Polygon, DefinedProperties>;
|
|
10
10
|
export type GeoJSONStoreFeatures = Feature<GeoJSONStoreGeometries, DefinedProperties>;
|
|
11
|
-
|
|
11
|
+
type StoreChangeEvents = "delete" | "create" | "update" | "styling";
|
|
12
12
|
export type StoreChangeHandler = (ids: FeatureId[], change: StoreChangeEvents) => void;
|
|
13
13
|
export type FeatureId = string | number;
|
|
14
14
|
export type IdStrategy<Id extends FeatureId> = {
|
|
15
15
|
isValidId: (id: Id) => boolean;
|
|
16
16
|
getId: () => Id;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type GeoJSONStoreConfig<Id extends FeatureId> = {
|
|
19
19
|
idStrategy?: IdStrategy<Id>;
|
|
20
20
|
tracked?: boolean;
|
|
21
21
|
};
|