terra-draw 0.0.1-alpha.0
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/.github/workflows/ci.yml +27 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +5 -0
- package/CODE_OF_CONDUCT.md +36 -0
- package/CONTRIBUTING.md +17 -0
- package/DEVELOPMENT.md +77 -0
- package/LICENSE +8 -0
- package/README.md +19 -0
- package/ROADMAP.md +63 -0
- package/common/addModeChangeHandler.ts +26 -0
- package/data/sample.ts +10126 -0
- package/dist/adapters/google-maps.adapter.d.ts +38 -0
- package/dist/adapters/leaflet.adapter.d.ts +35 -0
- package/dist/adapters/mapbox-gl.adapter.d.ts +36 -0
- package/dist/bundle.js +6 -0
- package/dist/bundle.js.LICENSE.txt +4 -0
- package/dist/common.d.ts +99 -0
- package/dist/geometry/boolean/point-in-polygon.d.ts +2 -0
- package/dist/geometry/boolean/self-intersects.d.ts +2 -0
- package/dist/geometry/centroid.d.ts +2 -0
- package/dist/geometry/coordinates-identical.d.ts +2 -0
- package/dist/geometry/create-circle.d.ts +6 -0
- package/dist/geometry/get-coordinates-as-points.d.ts +6 -0
- package/dist/geometry/get-midpoints.d.ts +7 -0
- package/dist/geometry/get-pixel-distance-to-line.d.ts +10 -0
- package/dist/geometry/get-pixel-distance.d.ts +7 -0
- package/dist/geometry/haversine-distance.d.ts +1 -0
- package/dist/geometry/helpers.d.ts +4 -0
- package/dist/geometry/limit-decimal-precision.d.ts +1 -0
- package/dist/geometry/measure/haversine-distance.d.ts +2 -0
- package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -0
- package/dist/geometry/measure/pixel-distance.d.ts +7 -0
- package/dist/geometry/measure/rhumb-bearing.d.ts +2 -0
- package/dist/geometry/measure/rhumb-destination.d.ts +2 -0
- package/dist/geometry/measure/rhumb-distance.d.ts +2 -0
- package/dist/geometry/midpoint-coordinate.d.ts +2 -0
- package/dist/geometry/point-in-polygon.d.ts +1 -0
- package/dist/geometry/self-intersects.d.ts +2 -0
- package/dist/geometry/shape/create-circle.d.ts +7 -0
- package/dist/geometry/transform/rotate.d.ts +2 -0
- package/dist/geometry/transform/scale.d.ts +2 -0
- package/dist/modes/base.behavior.d.ts +19 -0
- package/dist/modes/base.mode.d.ts +30 -0
- package/dist/modes/circle/circle.mode.d.ts +27 -0
- package/dist/modes/circle.mode.d.ts +18 -0
- package/dist/modes/click-bounding-box.behavior.d.ts +7 -0
- package/dist/modes/freehand/freehand.mode.d.ts +29 -0
- package/dist/modes/freehand.mode.d.ts +20 -0
- package/dist/modes/line-string.mode.d.ts +21 -0
- package/dist/modes/linestring/linestring.mode.d.ts +34 -0
- package/dist/modes/pixel-distance.behavior.d.ts +7 -0
- package/dist/modes/point/point.mode.d.ts +18 -0
- package/dist/modes/point.mode.d.ts +14 -0
- package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +11 -0
- package/dist/modes/polygon/polygon.mode.d.ts +37 -0
- package/dist/modes/polygon.mode.d.ts +21 -0
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +17 -0
- package/dist/modes/select/behaviors/features-at-mouse-event.behavior.d.ts +15 -0
- package/dist/modes/select/behaviors/midpoint.behavior.d.ts +18 -0
- package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/selection-point.behavior.d.ts +18 -0
- package/dist/modes/select/select.mode.d.ts +62 -0
- package/dist/modes/select.mode.d.ts +21 -0
- package/dist/modes/snapping.behavior.d.ts +13 -0
- package/dist/modes/static/static.mode.d.ts +13 -0
- package/dist/modes/static.mode.d.ts +10 -0
- package/dist/store/spatial-index/quickselect.d.ts +2 -0
- package/dist/store/spatial-index/rbush.d.ts +35 -0
- package/dist/store/spatial-index/spatial-index.d.ts +18 -0
- package/dist/store/store.d.ts +48 -0
- package/dist/terra-draw.cjs +2 -0
- package/dist/terra-draw.cjs.map +1 -0
- package/dist/terra-draw.d.ts +47 -0
- package/dist/terra-draw.modern.js +2 -0
- package/dist/terra-draw.modern.js.map +1 -0
- package/dist/terra-draw.module.js +2 -0
- package/dist/terra-draw.module.js.map +1 -0
- package/dist/terra-draw.umd.js +2 -0
- package/dist/terra-draw.umd.js.map +1 -0
- package/dist/util/geoms.d.ts +3 -0
- package/dist/util/id.d.ts +1 -0
- package/dist/util/styling.d.ts +2 -0
- package/jest.config.ts +27 -0
- package/package.json +86 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent } from "../../common";
|
|
2
|
+
import { TerraDrawBaseDrawMode } from "../base.mode";
|
|
3
|
+
import { BehaviorConfig } from "../base.behavior";
|
|
4
|
+
declare type TerraDrawPolygonModeKeyEvents = {
|
|
5
|
+
cancel: KeyboardEvent["key"];
|
|
6
|
+
};
|
|
7
|
+
export declare class TerraDrawPolygonMode extends TerraDrawBaseDrawMode {
|
|
8
|
+
mode: string;
|
|
9
|
+
private currentCoordinate;
|
|
10
|
+
private currentId;
|
|
11
|
+
private allowSelfIntersections;
|
|
12
|
+
private keyEvents;
|
|
13
|
+
private snappingEnabled;
|
|
14
|
+
private isClosed;
|
|
15
|
+
private snapping;
|
|
16
|
+
private pixelDistance;
|
|
17
|
+
private startEndPoint;
|
|
18
|
+
constructor(options?: {
|
|
19
|
+
allowSelfIntersections?: boolean;
|
|
20
|
+
snapping?: boolean;
|
|
21
|
+
styling?: Partial<TerraDrawAdapterStyling>;
|
|
22
|
+
pointerDistance?: number;
|
|
23
|
+
keyEvents?: TerraDrawPolygonModeKeyEvents;
|
|
24
|
+
});
|
|
25
|
+
registerBehaviors(config: BehaviorConfig): void;
|
|
26
|
+
start(): void;
|
|
27
|
+
stop(): void;
|
|
28
|
+
onMouseMove(event: TerraDrawMouseEvent): void;
|
|
29
|
+
onClick(event: TerraDrawMouseEvent): void;
|
|
30
|
+
onKeyUp(event: TerraDrawKeyboardEvent): void;
|
|
31
|
+
onKeyDown(): void;
|
|
32
|
+
onDragStart(): void;
|
|
33
|
+
onDrag(): void;
|
|
34
|
+
onDragEnd(): void;
|
|
35
|
+
cleanUp(): void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent, TerraDrawMode, TerraDrawModeRegisterConfig, TerraDrawAdapterStyling, TerraDrawKeyboardEvent } from "../common";
|
|
2
|
+
export declare class TerraDrawPolygonMode implements TerraDrawMode {
|
|
3
|
+
mode: string;
|
|
4
|
+
private store;
|
|
5
|
+
private project;
|
|
6
|
+
private currentCoordinate;
|
|
7
|
+
private currentId;
|
|
8
|
+
private allowSelfIntersections;
|
|
9
|
+
private pointerDistance;
|
|
10
|
+
constructor(options?: {
|
|
11
|
+
allowSelfIntersections?: boolean;
|
|
12
|
+
styling?: Partial<TerraDrawAdapterStyling>;
|
|
13
|
+
pointerDistance?: number;
|
|
14
|
+
});
|
|
15
|
+
styling: TerraDrawAdapterStyling;
|
|
16
|
+
register(config: TerraDrawModeRegisterConfig): void;
|
|
17
|
+
onMouseMove(event: TerraDrawMouseEvent): void;
|
|
18
|
+
onClick(event: TerraDrawMouseEvent): void;
|
|
19
|
+
onKeyPress(event: TerraDrawKeyboardEvent): void;
|
|
20
|
+
cleanUp(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent } from "../../../common";
|
|
2
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
3
|
+
import { PixelDistanceBehavior } from "../../pixel-distance.behavior";
|
|
4
|
+
import { MidPointBehavior } from "./midpoint.behavior";
|
|
5
|
+
import { SelectionPointBehavior } from "./selection-point.behavior";
|
|
6
|
+
export declare class DragCoordinateBehavior extends TerraDrawModeBehavior {
|
|
7
|
+
readonly config: BehaviorConfig;
|
|
8
|
+
private readonly pixelDistance;
|
|
9
|
+
private readonly selectionPoints;
|
|
10
|
+
private readonly midPoints;
|
|
11
|
+
constructor(config: BehaviorConfig, pixelDistance: PixelDistanceBehavior, selectionPoints: SelectionPointBehavior, midPoints: MidPointBehavior);
|
|
12
|
+
drag(event: TerraDrawMouseEvent, selectedId: string): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent } from "../../../common";
|
|
2
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
3
|
+
import { FeaturesAtMouseEventBehavior } from "./features-at-mouse-event.behavior";
|
|
4
|
+
import { Position } from "geojson";
|
|
5
|
+
import { SelectionPointBehavior } from "./selection-point.behavior";
|
|
6
|
+
import { MidPointBehavior } from "./midpoint.behavior";
|
|
7
|
+
export declare class DragFeatureBehavior extends TerraDrawModeBehavior {
|
|
8
|
+
readonly config: BehaviorConfig;
|
|
9
|
+
private readonly featuresAtMouseEvent;
|
|
10
|
+
private readonly selectionPoints;
|
|
11
|
+
private readonly midPoints;
|
|
12
|
+
constructor(config: BehaviorConfig, featuresAtMouseEvent: FeaturesAtMouseEventBehavior, selectionPoints: SelectionPointBehavior, midPoints: MidPointBehavior);
|
|
13
|
+
private dragPosition;
|
|
14
|
+
get position(): undefined | Position;
|
|
15
|
+
set position(newPosition: undefined | Position);
|
|
16
|
+
drag(event: TerraDrawMouseEvent, selectedId: string): false | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent } from "../../../common";
|
|
2
|
+
import { GeoJSONStoreFeatures } from "../../../store/store";
|
|
3
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
4
|
+
import { ClickBoundingBoxBehavior } from "../../click-bounding-box.behavior";
|
|
5
|
+
import { PixelDistanceBehavior } from "../../pixel-distance.behavior";
|
|
6
|
+
export declare class FeaturesAtMouseEventBehavior extends TerraDrawModeBehavior {
|
|
7
|
+
readonly config: BehaviorConfig;
|
|
8
|
+
private readonly createClickBoundingBox;
|
|
9
|
+
private readonly pixelDistance;
|
|
10
|
+
constructor(config: BehaviorConfig, createClickBoundingBox: ClickBoundingBoxBehavior, pixelDistance: PixelDistanceBehavior);
|
|
11
|
+
find(event: TerraDrawMouseEvent, hasSelection: boolean): {
|
|
12
|
+
clickedFeature: GeoJSONStoreFeatures | undefined;
|
|
13
|
+
clickedMidPoint: GeoJSONStoreFeatures | undefined;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Point, Position } from "geojson";
|
|
2
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
3
|
+
import { SelectionPointBehavior } from "./selection-point.behavior";
|
|
4
|
+
export declare class MidPointBehavior extends TerraDrawModeBehavior {
|
|
5
|
+
readonly config: BehaviorConfig;
|
|
6
|
+
private readonly selectionPointBehavior;
|
|
7
|
+
constructor(config: BehaviorConfig, selectionPointBehavior: SelectionPointBehavior);
|
|
8
|
+
private _midPoints;
|
|
9
|
+
get ids(): string[];
|
|
10
|
+
set ids(_: string[]);
|
|
11
|
+
insert(midPointId: string, coordinatePrecision: number): void;
|
|
12
|
+
create(selectedCoords: Position[], featureId: string, coordinatePrecision: number): void;
|
|
13
|
+
delete(): void;
|
|
14
|
+
getUpdated(updatedCoordinates: Position[]): {
|
|
15
|
+
id: string;
|
|
16
|
+
geometry: Point;
|
|
17
|
+
}[] | undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent } from "../../../common";
|
|
2
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
3
|
+
import { SelectionPointBehavior } from "./selection-point.behavior";
|
|
4
|
+
import { MidPointBehavior } from "./midpoint.behavior";
|
|
5
|
+
export declare class RotateFeatureBehavior extends TerraDrawModeBehavior {
|
|
6
|
+
readonly config: BehaviorConfig;
|
|
7
|
+
private readonly selectionPoints;
|
|
8
|
+
private readonly midPoints;
|
|
9
|
+
constructor(config: BehaviorConfig, selectionPoints: SelectionPointBehavior, midPoints: MidPointBehavior);
|
|
10
|
+
private lastBearing;
|
|
11
|
+
reset(): void;
|
|
12
|
+
rotate(event: TerraDrawMouseEvent, selectedId: string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent } from "../../../common";
|
|
2
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
3
|
+
import { SelectionPointBehavior } from "./selection-point.behavior";
|
|
4
|
+
import { MidPointBehavior } from "./midpoint.behavior";
|
|
5
|
+
export declare class ScaleFeatureBehavior extends TerraDrawModeBehavior {
|
|
6
|
+
readonly config: BehaviorConfig;
|
|
7
|
+
private readonly selectionPoints;
|
|
8
|
+
private readonly midPoints;
|
|
9
|
+
constructor(config: BehaviorConfig, selectionPoints: SelectionPointBehavior, midPoints: MidPointBehavior);
|
|
10
|
+
private lastDistance;
|
|
11
|
+
reset(): void;
|
|
12
|
+
scale(event: TerraDrawMouseEvent, selectedId: string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LineString, Point, Polygon, Position } from "geojson";
|
|
2
|
+
import { BehaviorConfig, TerraDrawModeBehavior } from "../../base.behavior";
|
|
3
|
+
export declare class SelectionPointBehavior extends TerraDrawModeBehavior {
|
|
4
|
+
constructor(config: BehaviorConfig);
|
|
5
|
+
private _selectionPoints;
|
|
6
|
+
get ids(): string[];
|
|
7
|
+
set ids(_: string[]);
|
|
8
|
+
create(selectedCoords: Position[], type: Polygon["type"] | LineString["type"], featureId: string): void;
|
|
9
|
+
delete(): void;
|
|
10
|
+
getUpdated(updatedCoordinates: Position[]): {
|
|
11
|
+
id: string;
|
|
12
|
+
geometry: Point;
|
|
13
|
+
}[] | undefined;
|
|
14
|
+
getOneUpdated(index: number, updatedCoordinate: Position): {
|
|
15
|
+
id: string;
|
|
16
|
+
geometry: Point;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent, TerraDrawKeyboardEvent } from "../../common";
|
|
2
|
+
import { TerraDrawBaseDrawMode } from "../base.mode";
|
|
3
|
+
import { BehaviorConfig } from "../base.behavior";
|
|
4
|
+
declare type TerraDrawSelectModeKeyEvents = {
|
|
5
|
+
deselect: KeyboardEvent["key"];
|
|
6
|
+
delete: KeyboardEvent["key"];
|
|
7
|
+
rotate: KeyboardEvent["key"];
|
|
8
|
+
scale: KeyboardEvent["key"];
|
|
9
|
+
};
|
|
10
|
+
declare type ModeFlags = {
|
|
11
|
+
feature?: {
|
|
12
|
+
draggable?: boolean;
|
|
13
|
+
rotateable?: boolean;
|
|
14
|
+
scaleable?: boolean;
|
|
15
|
+
coordinates?: {
|
|
16
|
+
midpoints?: boolean;
|
|
17
|
+
draggable?: boolean;
|
|
18
|
+
deletable?: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare class TerraDrawSelectMode extends TerraDrawBaseDrawMode {
|
|
23
|
+
mode: string;
|
|
24
|
+
private dragEventThrottle;
|
|
25
|
+
private dragEventCount;
|
|
26
|
+
private selected;
|
|
27
|
+
private flags;
|
|
28
|
+
private keyEvents;
|
|
29
|
+
private selectionPoints;
|
|
30
|
+
private midPoints;
|
|
31
|
+
private featuresAtMouseEvent;
|
|
32
|
+
private pixelDistance;
|
|
33
|
+
private clickBoundingBox;
|
|
34
|
+
private dragFeature;
|
|
35
|
+
private dragCoordinate;
|
|
36
|
+
private rotateFeature;
|
|
37
|
+
private scaleFeature;
|
|
38
|
+
constructor(options?: {
|
|
39
|
+
pointerDistance?: number;
|
|
40
|
+
flags?: {
|
|
41
|
+
[mode: string]: ModeFlags;
|
|
42
|
+
};
|
|
43
|
+
keyEvents?: TerraDrawSelectModeKeyEvents;
|
|
44
|
+
dragEventThrottle?: number;
|
|
45
|
+
});
|
|
46
|
+
registerBehaviors(config: BehaviorConfig): void;
|
|
47
|
+
private deselect;
|
|
48
|
+
private deleteSelected;
|
|
49
|
+
private onRightClick;
|
|
50
|
+
private onLeftClick;
|
|
51
|
+
start(): void;
|
|
52
|
+
stop(): void;
|
|
53
|
+
onClick(event: TerraDrawMouseEvent): void;
|
|
54
|
+
onKeyDown(): void;
|
|
55
|
+
onKeyUp(event: TerraDrawKeyboardEvent): void;
|
|
56
|
+
cleanUp(): void;
|
|
57
|
+
onDragStart(event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
|
|
58
|
+
onDrag(event: TerraDrawMouseEvent): void;
|
|
59
|
+
onDragEnd(_: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void): void;
|
|
60
|
+
onMouseMove(event: TerraDrawMouseEvent): void;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TerraDrawMouseEvent, TerraDrawMode, TerraDrawModeRegisterConfig, TerraDrawKeyboardEvent, TerraDrawAdapterStyling } from "../common";
|
|
2
|
+
export declare class TerraDrawSelectMode implements TerraDrawMode {
|
|
3
|
+
mode: string;
|
|
4
|
+
private store;
|
|
5
|
+
private project;
|
|
6
|
+
private selected;
|
|
7
|
+
private pointerDistance;
|
|
8
|
+
private selectionPoints;
|
|
9
|
+
constructor(options?: {
|
|
10
|
+
styling?: Partial<TerraDrawAdapterStyling>;
|
|
11
|
+
pointerDistance?: number;
|
|
12
|
+
});
|
|
13
|
+
styling: TerraDrawAdapterStyling;
|
|
14
|
+
onClick(event: TerraDrawMouseEvent): void;
|
|
15
|
+
onKeyPress(event: TerraDrawKeyboardEvent): void;
|
|
16
|
+
cleanUp(): void;
|
|
17
|
+
onMouseMove(): void;
|
|
18
|
+
register(config: TerraDrawModeRegisterConfig): void;
|
|
19
|
+
onDeselect(deselectedId: string): void;
|
|
20
|
+
onSelect(selectedId: string): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { PixelDistanceBehavior } from "./pixel-distance.behavior";
|
|
6
|
+
export declare class SnappingBehavior extends TerraDrawModeBehavior {
|
|
7
|
+
readonly config: BehaviorConfig;
|
|
8
|
+
private readonly pixelDistance;
|
|
9
|
+
private readonly clickBoundingBox;
|
|
10
|
+
constructor(config: BehaviorConfig, pixelDistance: PixelDistanceBehavior, clickBoundingBox: ClickBoundingBoxBehavior);
|
|
11
|
+
getSnappableCoordinate: (event: TerraDrawMouseEvent, currentFeatureId: string) => Position | undefined;
|
|
12
|
+
private getSnappable;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TerraDrawBaseDrawMode } from "../base.mode";
|
|
2
|
+
export declare class TerraDrawStaticMode extends TerraDrawBaseDrawMode {
|
|
3
|
+
mode: string;
|
|
4
|
+
start(): void;
|
|
5
|
+
stop(): void;
|
|
6
|
+
onKeyUp(): void;
|
|
7
|
+
onKeyDown(): void;
|
|
8
|
+
onClick(): void;
|
|
9
|
+
onDragStart(): void;
|
|
10
|
+
onDrag(): void;
|
|
11
|
+
onDragEnd(): void;
|
|
12
|
+
onMouseMove(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TerraDrawAdapterStyling, TerraDrawMode } from "../common";
|
|
2
|
+
export declare class TerraDrawStaticMode implements TerraDrawMode {
|
|
3
|
+
mode: string;
|
|
4
|
+
styling: TerraDrawAdapterStyling;
|
|
5
|
+
register(): void;
|
|
6
|
+
onKeyPress(): void;
|
|
7
|
+
onClick(): void;
|
|
8
|
+
onMouseMove(): void;
|
|
9
|
+
cleanUp(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare type Node = {
|
|
2
|
+
children: Node[];
|
|
3
|
+
height: number;
|
|
4
|
+
leaf: boolean;
|
|
5
|
+
minX: number;
|
|
6
|
+
minY: number;
|
|
7
|
+
maxX: number;
|
|
8
|
+
maxY: number;
|
|
9
|
+
};
|
|
10
|
+
export declare class RBush {
|
|
11
|
+
private _maxEntries;
|
|
12
|
+
private _minEntries;
|
|
13
|
+
private data;
|
|
14
|
+
constructor(maxEntries: number);
|
|
15
|
+
search(bbox: Node): Node[];
|
|
16
|
+
collides(bbox: Node): boolean;
|
|
17
|
+
load(data: Node[]): void;
|
|
18
|
+
insert(item: Node): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
remove(item: Node): void;
|
|
21
|
+
private toBBox;
|
|
22
|
+
private compareMinX;
|
|
23
|
+
private compareMinY;
|
|
24
|
+
private _all;
|
|
25
|
+
private _build;
|
|
26
|
+
private _chooseSubtree;
|
|
27
|
+
private _insert;
|
|
28
|
+
private _split;
|
|
29
|
+
private _splitRoot;
|
|
30
|
+
private _chooseSplitIndex;
|
|
31
|
+
private _chooseSplitAxis;
|
|
32
|
+
private _allDistMargin;
|
|
33
|
+
private _adjustParentBBoxes;
|
|
34
|
+
private _condense;
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GeoJSONStoreFeatures } from "../store";
|
|
2
|
+
export declare class SpatialIndex {
|
|
3
|
+
private tree;
|
|
4
|
+
private idToNode;
|
|
5
|
+
private nodeToId;
|
|
6
|
+
constructor(options?: {
|
|
7
|
+
maxEntries: number;
|
|
8
|
+
});
|
|
9
|
+
private setMaps;
|
|
10
|
+
private toBBox;
|
|
11
|
+
insert(feature: GeoJSONStoreFeatures): void;
|
|
12
|
+
load(features: GeoJSONStoreFeatures[]): void;
|
|
13
|
+
update(feature: GeoJSONStoreFeatures): void;
|
|
14
|
+
remove(featureId: string): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
search(feature: GeoJSONStoreFeatures): string[];
|
|
17
|
+
collides(feature: GeoJSONStoreFeatures): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Feature, Point, Polygon, LineString } from "geojson";
|
|
2
|
+
declare type JSON = string | number | boolean | null | JSONArray | JSONObject;
|
|
3
|
+
export interface JSONObject {
|
|
4
|
+
[member: string]: JSON;
|
|
5
|
+
}
|
|
6
|
+
declare type JSONArray = Array<JSON>;
|
|
7
|
+
declare type DefinedProperties = Record<string, JSON>;
|
|
8
|
+
export declare type GeoJSONStoreGeometries = Polygon | LineString | Point;
|
|
9
|
+
export declare type BBoxPolygon = Feature<Polygon, DefinedProperties>;
|
|
10
|
+
export declare type GeoJSONStoreFeatures = Feature<GeoJSONStoreGeometries, DefinedProperties>;
|
|
11
|
+
export declare type StoreChangeEvents = "delete" | "create" | "update";
|
|
12
|
+
export declare type StoreChangeHandler = (ids: string[], change: StoreChangeEvents) => void;
|
|
13
|
+
export declare type GeoJSONStoreConfig = {
|
|
14
|
+
data?: GeoJSONStoreFeatures[];
|
|
15
|
+
tracked?: boolean;
|
|
16
|
+
validateFeature?: (feature: unknown, tracked?: boolean) => void;
|
|
17
|
+
};
|
|
18
|
+
export declare class GeoJSONStore {
|
|
19
|
+
constructor(config?: GeoJSONStoreConfig);
|
|
20
|
+
private tracked;
|
|
21
|
+
private spatialIndex;
|
|
22
|
+
private store;
|
|
23
|
+
private _onChange;
|
|
24
|
+
private getId;
|
|
25
|
+
private clone;
|
|
26
|
+
has(id: string): boolean;
|
|
27
|
+
load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => void): void;
|
|
28
|
+
search(bbox: BBoxPolygon, filter?: (feature: GeoJSONStoreFeatures) => boolean): GeoJSONStoreFeatures[];
|
|
29
|
+
registerOnChange(onChange: StoreChangeHandler): void;
|
|
30
|
+
getGeometryCopy<T extends GeoJSONStoreGeometries>(id: string): T;
|
|
31
|
+
getPropertiesCopy(id: string): DefinedProperties;
|
|
32
|
+
updateProperty(propertiesToUpdate: {
|
|
33
|
+
id: string;
|
|
34
|
+
property: string;
|
|
35
|
+
value: JSON;
|
|
36
|
+
}[]): void;
|
|
37
|
+
updateGeometry(geometriesToUpdate: {
|
|
38
|
+
id: string;
|
|
39
|
+
geometry: GeoJSONStoreGeometries;
|
|
40
|
+
}[]): void;
|
|
41
|
+
create(features: {
|
|
42
|
+
geometry: GeoJSONStoreGeometries;
|
|
43
|
+
properties?: JSONObject;
|
|
44
|
+
}[]): string[];
|
|
45
|
+
delete(ids: string[]): void;
|
|
46
|
+
copyAll(): GeoJSONStoreFeatures[];
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t},t.apply(this,arguments)}function e(t,e){void 0===e&&(e=9);var o=Math.pow(10,e);return Math.round(t*o)/o}var o=/*#__PURE__*/function(){function t(t){var e=this;this._coordinatePrecision=void 0,this._lib=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onMouseMoveCallback=void 0,this._onClickListener=void 0,this._onClickCallback=void 0,this._onKeyUpListener=void 0,this._layers=void 0,this.project=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.getBounds(),n=new e._lib.LatLng(i.getNorthEast().lat(),i.getSouthWest().lng()),r=e._map.getProjection(),s=r.fromLatLngToPoint(n),l=r.fromLatLngToPoint({lng:t,lat:o}),a=Math.pow(2,e._map.getZoom());return{x:Math.floor((l.x-s.x)*a),y:Math.floor((l.y-s.y)*a)}}}var o=t.prototype;return o.circlePath=function(t,e,o){return"M "+t+" "+e+" m -"+o+", 0 a "+o+","+o+" 0 1,0 "+2*o+",0 a "+o+","+o+" 0 1,0 -"+2*o+",0"},o.register=function(t){var o=this;this._onClickCallback=function(i){t.onClick({lng:e(i.latLng.lng(),o._coordinatePrecision),lat:e(i.latLng.lat(),o._coordinatePrecision),containerX:i.domEvent.clientX-o._map.getDiv().offsetLeft,containerY:i.domEvent.clientY-o._map.getDiv().offsetTop})},this._onClickListener=this._map.addListener("click",this._onClickCallback),this._onMouseMoveCallback=function(i){t.onMouseMove({lng:e(i.latLng.lng(),o._coordinatePrecision),lat:e(i.latLng.lat(),o._coordinatePrecision),containerX:i.domEvent.clientX,containerY:i.domEvent.clientY})},this._onMouseMoveListener=this._map.addListener("mousemove",this._onMouseMoveCallback),this._onKeyUpListener=function(e){t.onKeyPress({key:e.key})},this._map.getDiv().addEventListener("keyup",this._onKeyUpListener)},o.unregister=function(){this._onClickListener&&(this._onClickCallback=void 0,this._onClickListener.remove(),this._onClickListener=void 0),this._onMouseMoveListener&&(this._onMouseMoveCallback=void 0,this._onMouseMoveListener.remove(),this._onMouseMoveListener=void 0),this._onKeyUpListener&&(this._map.getDiv().removeEventListener("keyup",this._onKeyUpListener),this._onKeyUpListener=void 0)},o.render=function(t,e){var o=this;this._layers?this._map.data.forEach(function(t){o._map.data.remove(t)}):(this._map.data.addListener("click",function(t){o._onClickCallback(t)}),this._map.data.addListener("mousemove",function(t){o._onMouseMoveCallback(t)})),console.log(t),this._map.data.addGeoJson({type:"FeatureCollection",features:t}),this._map.data.setStyle(function(t){var i=t.getProperty("mode"),n=t.getGeometry().getType(),r=t.getProperty("selected");switch(n){case"Point":return{icon:{path:o.circlePath(e[i].pointWidth,e[i].pointWidth,e[i].pointWidth),fillColor:r?e[i].selectedColor:e[i].pointColor,fillOpacity:1,strokeWeight:0,rotation:0,scale:1}};case"LineString":return{strokeColor:r?e[i].selectedColor:e[i].lineStringColor,strokeWeight:e[i].lineStringWidth};case"Polygon":return console.log("STYLING",e,i,e[i]),{strokeColor:e[i].polygonOutlineColor,strokeWeight:e[i].polygonOutlineWidth,fillOpacity:e[i].polygonFillOpacity,fillColor:r?e[i].selectedColor:e[i].polygonFillColor}}}),this._layers=!0},t}(),i=/*#__PURE__*/function(){function t(t){var e=this;this._lib=void 0,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyPressListener=void 0,this._layer=void 0,this.project=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.latLngToContainerPoint({lng:t,lat:o});return{x:i.x,y:i.y}}}var o=t.prototype;return o.register=function(t){var o=this;this._onClickListener=function(i){i.originalEvent.preventDefault(),t.onClick({lng:e(i.latlng.lng,o._coordinatePrecision),lat:e(i.latlng.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("click",this._onClickListener),this._onMouseMoveListener=function(i){i.originalEvent.preventDefault(),t.onMouseMove({lng:e(i.latlng.lng,o._coordinatePrecision),lat:e(i.latlng.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("mousemove",this._onMouseMoveListener),this._onKeyPressListener=function(e){e.originalEvent.preventDefault(),t.onKeyPress({key:e.originalEvent.key})},this._map.on("keyup",this._onKeyPressListener)},o.unregister=function(){this._onClickListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0)},o.render=function(t,e){var o=this;this._layer&&this._map.removeLayer(this._layer);var i=this._lib.geoJSON({type:"FeatureCollection",features:t},{pointToLayer:function(t,i){var n=e[t.properties.mode];return o._lib.circleMarker(i,{radius:n.pointWidth,fillColor:t.properties.selected?n.selectedColor:n.pointColor,color:n.pointOutlineColor,weight:1,opacity:1,fillOpacity:.8})},style:function(t){var o=e[t.properties.mode];return"LineString"===t.geometry.type?{color:t.properties.selected?o.selectedColor:o.lineStringColor,weight:o.lineStringWidth}:"Polygon"===t.geometry.type?{fillOpacity:o.polygonFillOpacity,color:t.properties.selected?o.selectedColor:o.polygonFillColor}:void 0}});i.addTo(this._map),this._layer=i},t}(),n=/*#__PURE__*/function(){function t(t){var e=this;this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyPressListener=void 0,this._rendered=!1,this.project=void 0,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.project({lng:t,lat:o});return{x:i.x,y:i.y}}}var o=t.prototype;return o._addGeoJSONSource=function(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e}})},o._addFillLayer=function(t,e,o){return this._map.addLayer({id:t,source:t,type:"fill",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"fill-color":["get","selectedStyle"],"fill-opacity":o.polygonFillOpacity}})},o._addFillOutlineLayer=function(t,e,o){return this._map.addLayer({id:t+"outline",source:t,type:"line",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":o.polygonOutlineWidth,"line-color":["get","selectedStyle"]}})},o._addLineLayer=function(t,e,o){return this._map.addLayer({id:t,source:t,type:"line",filter:["all",["match",["geometry-type"],"LineString",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":o.lineStringWidth,"line-color":["get","selectedStyle"]}})},o._addPointLayer=function(t,e,o){return this._map.addLayer({id:t,source:t,type:"circle",filter:["all",["match",["geometry-type"],"Point",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"circle-radius":o.pointWidth,"circle-color":["get","selectedStyle"]}})},o._addLayer=function(t,e,o,i){"Point"===o&&this._addPointLayer(t,e,i),"LineString"===o&&this._addLineLayer(t,e,i),"Polygon"===o&&(this._addFillLayer(t,e,i),this._addFillOutlineLayer(t,e,i))},o._addGeoJSONLayer=function(t,e,o,i){var n=t+"-"+e.toLowerCase();this._addGeoJSONSource(n,o),this._addLayer(n,t,e,i)},o._setGeoJSONLayerData=function(t,e,o){var i=t+"-"+e.toLowerCase();this._map.getSource(i).setData({type:"FeatureCollection",features:o})},o.register=function(t){var o=this;this._onClickListener=function(i){i.preventDefault(),t.onClick({lng:e(i.lngLat.lng,o._coordinatePrecision),lat:e(i.lngLat.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("click",this._onClickListener),this._onMouseMoveListener=function(i){i.preventDefault(),t.onMouseMove({lng:e(i.lngLat.lng,o._coordinatePrecision),lat:e(i.lngLat.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("mousemove",this._onMouseMoveListener),this._onKeyPressListener=function(e){e.preventDefault(),t.onKeyPress({key:e.key})},this._map.getCanvas().addEventListener("keyup",this._onKeyPressListener)},o.unregister=function(){this._onClickListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("mousemove",this._onMouseMoveListener),this._onMouseMoveListener=void 0),this._onKeyPressListener&&this._map.getCanvas().removeEventListener("keypress",this._onKeyPressListener)},o.render=function(t,e){var o=this,i=function(t,e){return e.filter(function(e){return e.geometry.type===t})},n=function(n){Object.keys(e).forEach(function(r){var s=e[r],l=t.filter(function(t){return t.properties.mode===r}),a=i("Point",l);a.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.pointColor});var c=i("LineString",l);c.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.lineStringColor});var h=i("Polygon",l);h.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.polygonFillColor}),"create"===n?(o._addGeoJSONLayer(r,"Point",a,s),o._addGeoJSONLayer(r,"LineString",c,s),o._addGeoJSONLayer(r,"Polygon",h,s)):"update"===n&&(o._setGeoJSONLayerData(r,"Point",a),o._setGeoJSONLayerData(r,"LineString",c),o._setGeoJSONLayerData(r,"Polygon",h))})};this._rendered?n("update"):(n("create"),this._rendered=!0)},t}();function r(t){return t%360*Math.PI/180}function s(t){return t%(2*Math.PI)*180/Math.PI}function l(t){for(var e,o,i,n,l,a,c,h,d=t.center,p=t.radiusKilometers,u=t.steps?t.steps:64,y=[],g=0;g<u;g++)y.push((o=p,i=-360*g/u,n=r((e=d)[0]),l=r(e[1]),a=r(i),c=function(t){return t/6371.0088}(o),h=Math.asin(Math.sin(l)*Math.cos(c)+Math.cos(l)*Math.sin(c)*Math.cos(a)),[s(n+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(l),Math.cos(c)-Math.sin(l)*Math.sin(h))),s(h)]));return y.push(y[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[y]},properties:{}}}var a=/*#__PURE__*/function(){function e(e){this.mode="circle",this.store=void 0,this.project=void 0,this.center=void 0,this.clickCount=0,this.currentCircleId=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=l({center:this.center,radiusKilometers:1e-5});this.currentCircleId=this.store.create(e.geometry,{mode:this.mode}),this.clickCount++}else this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.onMouseMove=function(t){if(1===this.clickCount){var e=(n=[t.lng,t.lat],s=(r=function(t){return t*Math.PI/180})((i=this.center)[1]),a=r(i[0]),h=(c=r(n[1]))-s,d=r(n[0])-a,p=Math.sin(h/2)*Math.sin(h/2)+Math.cos(s)*Math.cos(c)*Math.sin(d/2)*Math.sin(d/2),2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p))*6371e3/1e3),o=l({center:this.center,radiusKilometers:e});this.store.updateGeometry(this.currentCircleId,o.geometry)}var i,n,r,s,a,c,h,d,p},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentCircleId)}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},e}(),c=/*#__PURE__*/function(){function e(e){this.mode="freehand",this.store=void 0,this.project=void 0,this.startingClick=!1,this.currentId=void 0,this.skip=0,this.everyNthMouseEvent=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.everyNthMouseEvent=e&&e.everyNthMouseEvent||10}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&!1!==this.startingClick){if(this.skip>this.everyNthMouseEvent){this.skip=0;var e=this.store.getGeometryCopy(this.currentId);e.coordinates[0].pop(),this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[].concat(e.coordinates[0],[[t.lng,t.lat],e.coordinates[0][0]])]})}this.skip++}},o.onClick=function(t){if(!1===this.startingClick)return this.currentId=this.store.create({type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},{mode:this.mode}),void(this.startingClick=!0);this.startingClick=!1,this.currentId=void 0},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.startingClick=!1},e}();function h(t){var e;"Polygon"===t.geometry.type?e=t.geometry.coordinates:"LineString"===t.geometry.type&&(e=[t.geometry.coordinates]);for(var o=[],i=0;i<e.length;i++)for(var n=0;n<e[i].length-1;n++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)a(i,n,r,s);return o.length>0;function l(t){return t<0||t>1}function a(t,i,n,r){var s,a=e[t][i],c=e[t][i+1],h=e[n][r],p=e[n][r+1],u=function(t,e,o,i){if(d(t,o)||d(t,i)||d(e,o)||d(i,o))return null;var n=t[0],r=t[1],s=e[0],l=e[1],a=o[0],c=o[1],h=i[0],p=i[1],u=(n-s)*(c-p)-(r-l)*(a-h);return 0===u?null:[((n*l-r*s)*(a-h)-(n-s)*(a*p-c*h))/u,((n*l-r*s)*(c-p)-(r-l)*(a*p-c*h))/u]}(a,c,h,p);null!==u&&(s=p[0]!==h[0]?(u[0]-h[0])/(p[0]-h[0]):(u[1]-h[1])/(p[1]-h[1]),l(c[0]!==a[0]?(u[0]-a[0])/(c[0]-a[0]):(u[1]-a[1])/(c[1]-a[1]))||l(s)||(u.toString(),o.push(u)))}}function d(t,e){return t[0]===e[0]&&t[1]===e[1]}var p=function(t,e){var o=e.x-t.x,i=e.y-t.y;return Math.sqrt(i*i+o*o)},u=/*#__PURE__*/function(){function e(e){this.mode="linestring",this.store=void 0,this.project=void 0,this.pointerDistance=void 0,this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.pointerDistance=e&&e.pointerDistance||40,this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&0!==this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);e.coordinates.pop(),this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[].concat(e.coordinates,[[t.lng,t.lat]])})}},o.onClick=function(t){if(0===this.currentCoordinate)this.currentId=this.store.create({type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},{mode:this.mode}),this.currentCoordinate++;else if(1===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[e.coordinates[0],[t.lng,t.lat],[t.lng,t.lat]]}),this.currentCoordinate++}else{var o=this.store.getGeometryCopy(this.currentId),i=o.coordinates[o.coordinates.length-2],n=this.project(i[0],i[1]);if(p({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance)o.coordinates.pop(),this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[].concat(o.coordinates)}),this.currentCoordinate=0,this.currentId=void 0;else{var r={type:"LineString",coordinates:[].concat(o.coordinates,[[t.lng,t.lat]])};if(!this.allowSelfIntersections&&h({type:"Feature",geometry:r,properties:{}}))return;this.store.updateGeometry(this.currentId,r),this.currentCoordinate++}}},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.currentCoordinate=0},e}(),y=/*#__PURE__*/function(){function e(e){this.mode="point",this.store=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange)},o.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");this.store.create({type:"Point",coordinates:[t.lng,t.lat]},{mode:this.mode})},o.onMouseMove=function(){},o.onKeyPress=function(){},o.cleanUp=function(){},e}(),g=/*#__PURE__*/function(){function e(e){this.mode="polygon",this.store=void 0,this.project=void 0,this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.pointerDistance=void 0,this.styling=void 0,this.pointerDistance=e&&e.pointerDistance||40,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&0!==this.currentCoordinate){var e,o=this.store.getGeometryCopy(this.currentId).coordinates[0];e=1===this.currentCoordinate?[o[0],[t.lng,t.lat],o[0],o[0]]:2===this.currentCoordinate?[o[0],o[1],[t.lng,t.lat],o[0]]:[].concat(o.slice(0,-2),[[t.lng,t.lat],o[0]]),this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[e]})}},o.onClick=function(t){if(0===this.currentCoordinate)this.currentId=this.store.create({type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},{mode:this.mode}),this.currentCoordinate++;else if(1===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[e.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],e.coordinates[0][0]]]}),this.currentCoordinate++}else if(2===this.currentCoordinate){var o=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[o.coordinates[0][0],o.coordinates[0][1],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]]]}),this.currentCoordinate++}else{var i=this.store.getGeometryCopy(this.currentId),n=i.coordinates[0][0],r=this.project(n[0],n[1]),s=p({x:r.x,y:r.y},{x:t.containerX,y:t.containerY});if(console.log(s,this.pointerDistance),s<this.pointerDistance)this.currentCoordinate=0,this.currentId=void 0;else{var l={type:"Polygon",coordinates:[[].concat(i.coordinates[0].slice(0,-1),[[t.lng,t.lat],i.coordinates[0][0]])]};if(this.currentCoordinate>2&&!this.allowSelfIntersections&&h({type:"Feature",geometry:l,properties:{}}))return void this.store.updateGeometry(this.currentId,i);console.log(l),this.store.updateGeometry(this.currentId,l),this.currentCoordinate++}}},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.currentCoordinate=0},e}();function f(t,e){for(var o,i,n,r=!1,s=0,l=e.length;s<l;s++)for(var a=e[s],c=0,h=a.length,d=h-1;c<h;d=c++)(i=a[c])[1]>(o=t)[1]!=(n=a[d])[1]>o[1]&&o[0]<(n[0]-i[0])*(o[1]-i[1])/(n[1]-i[1])+i[0]&&(r=!r);return r}var v=function(t,e,o){var i=function(t){return t*t},n=function(t,e){return i(t.x-e.x)+i(t.y-e.y)};return Math.sqrt(function(t,e,o){var i=n(e,o);if(0===i)return n(t,e);var r=((t.x-e.x)*(o.x-e.x)+(t.y-e.y)*(o.y-e.y))/i;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(o.x-e.x),y:e.y+r*(o.y-e.y)})}(t,e,o))},C=/*#__PURE__*/function(){function e(e){this.mode="select",this.store=void 0,this.project=void 0,this.selected=[],this.pointerDistance=void 0,this.styling=void 0,this.pointerDistance=e&&e.pointerDistance||40,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=e.prototype;return o.onClick=function(t){for(var e,o=this.store.copyAll(),i=Infinity,n=0;n<o.length;n++){var r=o[n],s=r.geometry;if("Point"===s.type){var l=this.project(s.coordinates[0],s.coordinates[1]),a=p({x:l.x,y:l.y},{x:t.containerX,y:t.containerY});a<this.pointerDistance&&a<i&&(i=a,e=r.id)}else if("LineString"===s.type)for(var c=0;c<s.coordinates.length-1;c++){var h=s.coordinates[c],d=s.coordinates[c+1],u=v({x:t.containerX,y:t.containerY},this.project(h[0],h[1]),this.project(d[0],d[1]));u<this.pointerDistance&&u<i&&(i=u,e=r.id)}else"Polygon"===s.type&&f([t.lng,t.lat],s.coordinates)&&(i=0,e=r.id)}e?(this.selected=[e],this.onSelect(e)):this.selected.length&&(this.selected=[],this.onDeselect())},o.onKeyPress=function(t){var e=this;if("Delete"===t.key){if(!this.selected.length)return;this.selected.forEach(function(t){e.store.delete(t)}),this.selected=[],this.onDeselect()}else"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){this.selected.length&&this.onDeselect(),this.selected=[]},o.onMouseMove=function(){},o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect},o.onDeselect=function(){},o.onSelect=function(t){},e}(),_=/*#__PURE__*/function(){function t(){this.mode="static",this.styling={polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var e=t.prototype;return e.register=function(){},e.onKeyPress=function(){},e.onClick=function(){},e.onMouseMove=function(){},e.cleanUp=function(){},t}(),m=/*#__PURE__*/function(){function t(t){var e=this;this.store=void 0,this._onChange=void 0,this.store={},t&&t.data&&t.data.forEach(function(t){e.featureValidation(t),e.store[t.id]=t})}var e=t.prototype;return e.featureValidation=function(t){if(!t||!t.id)throw new Error("Feature has no id");if("string"!=typeof t.id||36!==t.id.length)throw new Error("Feature must have uuid4 ID "+t.id);if(!t.geometry)throw new Error("Feature has no geometry");if(!t.properties)throw new Error("Feature has no properties");if(!["Polygon","LineString","Point"].includes(t.geometry.type))throw new Error("Feature is not Point, LineString or Polygon");if(!Array.isArray(t.geometry.coordinates))throw new Error("Feature coordinates is not an array")},e.getId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},e.registerOnChange=function(t){this._onChange=function(e,o){t(e,o)}},e.updateGeometry=function(t,e){var o=this.store[t];if(!o)throw new Error("No feature with this id, can not update geometry");return o.geometry=JSON.parse(JSON.stringify(e)),this._onChange&&this._onChange(t,"update"),t},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id, can not get geometry copy");return JSON.parse(JSON.stringify(e.geometry))},e.create=function(t,e){void 0===e&&(e={});var o=this.getId();return this.store[o]={id:o,type:"Feature",geometry:t,properties:e},this._onChange&&this._onChange(o,"create"),o},e.delete=function(t){if(!this.store[t])throw new Error("No feature with this id, can not delete");delete this.store[t],this._onChange&&this._onChange(t,"delete")},e.copyAll=function(){var t=this;return JSON.parse(JSON.stringify(Object.keys(this.store).map(function(e){return t.store[e]})))},t}();exports.TerraDraw=/*#__PURE__*/function(){function e(e){var o=this;if(this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._adapter=e.adapter,this._mode=new _,this._modes=t({},e.modes,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[]},e.data){this._store=new m({data:e.data});var i=this._store.copyAll().filter(function(t){return!!Object.keys(o._modes).includes(t.properties.mode)||(o._store.delete(t.id),!1)});this._adapter.render(i,this.getModeStyles())}else this._store=new m;Object.keys(this._modes).forEach(function(t){o._modes[t].register({store:o._store,project:o._adapter.project,onChange:function(t,e){o._eventListeners.change.forEach(function(o){o(t,e)}),o._adapter.render(o._store.copyAll(),o.getModeStyles())},onSelect:function(t){o._eventListeners.select.forEach(function(e){e(t)});var e=o._store.copyAll();e.forEach(function(e){e.id===t&&(e.properties.selected=!0)}),o._adapter.render(e,o.getModeStyles())},onDeselect:function(){o._eventListeners.deselect.forEach(function(t){t()});var t=o._store.copyAll();o._adapter.render(t,o.getModeStyles())}})})}var o,i,n=e.prototype;return n.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(o){e[o]=t._modes[o].styling}),e},n.getSnapshot=function(){return this._store.copyAll()},n.changeMode=function(t){if(!this._modes[t])throw new Error("No mode with this name present");this._mode.cleanUp(),this._mode=this._modes[t]},n.start=function(){var t=this;this._enabled=!0,this._adapter.register({onClick:function(e){t._mode.onClick(e)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyPress:function(e){t._mode.onKeyPress(e)}})},n.stop=function(){this._enabled=!1,this._adapter.unregister()},n.on=function(t,e){var o=this._eventListeners[t];o.includes(e)||o.push(e)},n.off=function(t,e){var o=this._eventListeners[t];o.includes(e)&&o.splice(o.indexOf(e),1)},o=e,(i=[{key:"enabled",get:function(){return this._enabled}}])&&function(t,e){for(var o=0;o<e.length;o++){var i=e[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}(o.prototype,i),Object.defineProperty(o,"prototype",{writable:!1}),e}(),exports.TerraDrawCircleMode=a,exports.TerraDrawFreehandMode=c,exports.TerraDrawGoogleMapsAdapter=o,exports.TerraDrawLeafletAdapter=i,exports.TerraDrawLineStringMode=u,exports.TerraDrawMapboxGLAdapter=n,exports.TerraDrawPointMode=y,exports.TerraDrawPolygonMode=g,exports.TerraDrawSelectMode=C;
|
|
2
|
+
//# sourceMappingURL=terra-draw.cjs.map
|