terra-draw 1.0.0-beta.1 → 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 CHANGED
@@ -1,4 +1,10 @@
1
- <img src="./logo.png" alt="Terra Draw Logo" width="400"/>
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
  ![Terra Draw CI Badge](https://github.com/JamesLMilner/terra-draw/actions/workflows/ci.yml/badge.svg)
4
10
  [![npm version](https://badge.fury.io/js/terra-draw.svg)](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
- ![An example of drawing geodesic lines using Terra Draw with Leaflet](./readme.gif)
16
+ ![An example of drawing geodesic lines using Terra Draw with Leaflet](./assets/readme.gif)
17
+
11
18
 
12
19
  ### Library Support
13
20
 
@@ -22,7 +22,6 @@ export declare class TerraDrawMapboxGLAdapter extends TerraDrawBaseAdapter {
22
22
  private _addLayer;
23
23
  private _addGeoJSONLayer;
24
24
  private _setGeoJSONLayerData;
25
- private getEmptyGeometries;
26
25
  private changedIds;
27
26
  private updateChangedIds;
28
27
  /**
@@ -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 { toLonLat } from "ol/proj";
11
+ import { getUserProjection } from "ol/proj";
12
12
  import { BaseAdapterConfig, TerraDrawBaseAdapter } from "./common/base.adapter";
13
- type InjectableOL = {
14
- Circle: typeof CircleGeom;
13
+ export type InjectableOL = {
14
+ Fill: typeof Fill;
15
15
  Feature: typeof Feature;
16
16
  GeoJSON: typeof GeoJSON;
17
17
  Style: typeof Style;
18
- CircleStyle: typeof Circle;
18
+ Circle: typeof Circle;
19
19
  VectorLayer: typeof VectorLayer;
20
20
  VectorSource: typeof VectorSource;
21
21
  Stroke: typeof Stroke;
22
- toLonLat: typeof toLonLat;
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,10 @@
1
+ export declare function isClockwiseWebMercator(center: {
2
+ x: number;
3
+ y: number;
4
+ }, secondCoord: {
5
+ x: number;
6
+ y: number;
7
+ }, thirdCoord: {
8
+ x: number;
9
+ y: number;
10
+ }): boolean;
@@ -7,3 +7,4 @@ export declare function webMercatorBearing({ x: x1, y: y1 }: {
7
7
  x: number;
8
8
  y: number;
9
9
  }): number;
10
+ export declare function normalizeBearing(bearing: number): number;
@@ -1,6 +1,5 @@
1
1
  import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColorStyling, NumericStyling, Cursor } from "../../common";
2
2
  import { TerraDrawBaseDrawMode, BaseModeOptions, CustomStyling } from "../base.mode";
3
- import { BehaviorConfig } from "../base.behavior";
4
3
  import { GeoJSONStoreFeatures } from "../../store/store";
5
4
  type TerraDrawPolygonModeKeyEvents = {
6
5
  cancel?: KeyboardEvent["key"] | null;
@@ -27,14 +26,11 @@ export declare class TerraDrawAngledRectangleMode extends TerraDrawBaseDrawMode<
27
26
  private currentCoordinate;
28
27
  private currentId;
29
28
  private keyEvents;
30
- private pixelDistance;
31
29
  private cursors;
32
30
  private mouseMove;
33
31
  constructor(options?: TerraDrawPolygonModeOptions<PolygonStyling>);
34
32
  private close;
35
33
  /** @internal */
36
- registerBehaviors(config: BehaviorConfig): void;
37
- /** @internal */
38
34
  start(): void;
39
35
  /** @internal */
40
36
  stop(): void;
@@ -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 {};
@@ -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
- export type StoreChangeEvents = "delete" | "create" | "update" | "styling";
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
- export type GeoJSONStoreConfig<Id extends FeatureId> = {
18
+ type GeoJSONStoreConfig<Id extends FeatureId> = {
19
19
  idStrategy?: IdStrategy<Id>;
20
20
  tracked?: boolean;
21
21
  };