terra-draw 0.0.1-alpha.21 → 0.0.1-alpha.23
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/CHANGELOG.md +48 -0
- package/README.md +10 -16
- package/dist/adapters/common/adapter-listener.d.ts +22 -14
- package/dist/adapters/common/base-adapter.d.ts +31 -0
- package/dist/adapters/common/base.adapter.d.ts +45 -0
- package/dist/adapters/google-maps.adapter.d.ts +80 -31
- package/dist/adapters/leaflet.adapter.d.ts +78 -30
- package/dist/adapters/mapbox-gl.adapter.d.ts +75 -34
- package/dist/adapters/maplibre-gl.adapter.d.ts +65 -20
- package/dist/adapters/openlayers.adapter.d.ts +107 -55
- package/dist/common.d.ts +100 -100
- package/dist/geometry/boolean/point-in-polygon.d.ts +2 -2
- package/dist/geometry/boolean/self-intersects.d.ts +2 -2
- package/dist/geometry/centroid.d.ts +2 -2
- package/dist/geometry/coordinates-identical.d.ts +2 -2
- package/dist/geometry/get-coordinates-as-points.d.ts +6 -6
- package/dist/geometry/get-midpoints.d.ts +8 -8
- package/dist/geometry/helpers.d.ts +4 -4
- package/dist/geometry/limit-decimal-precision.d.ts +1 -1
- package/dist/geometry/measure/haversine-distance.d.ts +2 -2
- package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -10
- package/dist/geometry/measure/pixel-distance.d.ts +7 -7
- package/dist/geometry/measure/rhumb-bearing.d.ts +2 -2
- package/dist/geometry/measure/rhumb-destination.d.ts +2 -2
- package/dist/geometry/measure/rhumb-distance.d.ts +2 -2
- package/dist/geometry/midpoint-coordinate.d.ts +3 -3
- package/dist/geometry/shape/create-circle.d.ts +8 -8
- package/dist/geometry/shape/great-circle-line.d.ts +12 -12
- package/dist/geometry/transform/rotate.d.ts +2 -2
- package/dist/geometry/transform/scale.d.ts +2 -2
- package/dist/modes/base.behavior.d.ts +19 -19
- package/dist/modes/base.mode.d.ts +37 -34
- package/dist/modes/circle/circle.mode.d.ts +48 -48
- package/dist/modes/click-bounding-box.behavior.d.ts +7 -7
- package/dist/modes/freehand/freehand.mode.d.ts +54 -54
- package/dist/modes/great-circle-snapping.behavior.d.ts +13 -13
- package/dist/modes/greatcircle/great-circle.mode.d.ts +57 -57
- package/dist/modes/linestring/linestring.mode.d.ts +60 -60
- package/dist/modes/pixel-distance.behavior.d.ts +7 -7
- package/dist/modes/point/point.mode.d.ts +38 -38
- package/dist/modes/polygon/behaviors/closing-points.behavior.d.ts +19 -19
- package/dist/modes/polygon/polygon.mode.d.ts +63 -63
- package/dist/modes/rectangle/rectangle.mode.d.ts +48 -48
- package/dist/modes/render/render.mode.d.ts +34 -34
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +13 -13
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +17 -17
- package/dist/modes/select/behaviors/features-at-mouse-event.behavior.d.ts +15 -15
- package/dist/modes/select/behaviors/midpoint.behavior.d.ts +18 -18
- package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +13 -13
- package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +13 -13
- package/dist/modes/select/behaviors/selection-point.behavior.d.ts +18 -18
- package/dist/modes/select/select.mode.d.ts +89 -89
- package/dist/modes/snapping.behavior.d.ts +13 -13
- package/dist/modes/static/static.mode.d.ts +30 -30
- package/dist/store/spatial-index/quickselect.d.ts +2 -2
- package/dist/store/spatial-index/rbush.d.ts +35 -35
- package/dist/store/spatial-index/spatial-index.d.ts +18 -18
- package/dist/store/store.d.ts +50 -50
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +129 -129
- 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/util/geoms.d.ts +3 -3
- package/dist/util/id.d.ts +1 -1
- package/dist/util/styling.d.ts +2 -2
- package/{CONTRIBUTING.md → guides/CONTRIBUTING.md} +7 -7
- package/guides/DEVELOPMENT.md +156 -0
- package/guides/GETTING_STARTED.md +211 -0
- package/package.json +6 -6
- package/scratch/release.sh +4 -2
- package/tsconfig.json +0 -1
- package/DEVELOPMENT.md +0 -77
- /package/{CODE_OF_CONDUCT.md → guides/CODE_OF_CONDUCT.md} +0 -0
package/dist/util/geoms.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Feature, LineString, Polygon, Position } from "geojson";
|
|
2
|
-
export declare function createPolygon(coordinates?: Position[][]): Feature<Polygon>;
|
|
3
|
-
export declare function createLineString(coordinates: Position[]): Feature<LineString>;
|
|
1
|
+
import { Feature, LineString, Polygon, Position } from "geojson";
|
|
2
|
+
export declare function createPolygon(coordinates?: Position[][]): Feature<Polygon>;
|
|
3
|
+
export declare function createLineString(coordinates: Position[]): Feature<LineString>;
|
package/dist/util/id.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const uuid4: () => string;
|
|
1
|
+
export declare const uuid4: () => string;
|
package/dist/util/styling.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TerraDrawAdapterStyling } from "../common";
|
|
2
|
-
export declare const getDefaultStyling: () => TerraDrawAdapterStyling;
|
|
1
|
+
import { TerraDrawAdapterStyling } from "../common";
|
|
2
|
+
export declare const getDefaultStyling: () => TerraDrawAdapterStyling;
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
This document will receive a more thorough update in the future. For the time being, if you wish to contribute to Terra Draw, we request that you:
|
|
6
6
|
|
|
7
|
-
1
|
|
8
|
-
2
|
|
9
|
-
3
|
|
10
|
-
4
|
|
11
|
-
5
|
|
7
|
+
1. Make an issue on GitHub describing the bug you intend to fix or the feature you intend to add.
|
|
8
|
+
2. Create a fork of the project, and work on a branch that represents the issue
|
|
9
|
+
3. Ensure that the work you have done is unit tested, aiming for 80% code coverage
|
|
10
|
+
4. Create a PR that represents this work. Please refer to the issue from the PR
|
|
11
|
+
5. We will address the PR and give you feedback
|
|
12
12
|
|
|
13
|
-
Please note that we can not
|
|
13
|
+
Please note that we can not guarantee that all PRs will be merged. There are cases where a PR may deviate from the long-term vision for Terra Draw and hence we may have to decline it. Creating the issue in advance helps us discuss any potential issues upfront before the PR is made.
|
|
14
14
|
|
|
15
15
|
## Code of Conduct
|
|
16
16
|
|
|
17
|
-
We have a code of conduct which we expect individuals interacting with the project to respect. Please see the [full Code of Conduct in the repository](./CODE_OF_CONDUCT.md).
|
|
17
|
+
We have a code of conduct which we expect individuals interacting with the project to respect. Please see the [full Code of Conduct in the repository](./CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Development
|
|
2
|
+
|
|
3
|
+
This file acts as a way to document how to develop the Terra Draw project locally.
|
|
4
|
+
|
|
5
|
+
### Prerequisites
|
|
6
|
+
|
|
7
|
+
A few things you will need to have installed in order to develop on this project:
|
|
8
|
+
|
|
9
|
+
- git
|
|
10
|
+
- Node LTS - currently v16
|
|
11
|
+
- npm 8
|
|
12
|
+
|
|
13
|
+
### Folder Structure
|
|
14
|
+
|
|
15
|
+
- `.github` - used for all GitHub related configuration such as the GitHub Actions work flows
|
|
16
|
+
- `.husky` - used to storing the precommit hooks that are used on the project
|
|
17
|
+
- `src` - source files for the project
|
|
18
|
+
- `dist` - the bundled distributed files of the project
|
|
19
|
+
- `docs` - the demo app that is published to GitHub pages
|
|
20
|
+
- `development` - the local development app that is used for developing locally (see below)
|
|
21
|
+
- `common` - code that is used across `development` and `docs` folder`
|
|
22
|
+
|
|
23
|
+
### Technologies Used
|
|
24
|
+
|
|
25
|
+
Terra Draw
|
|
26
|
+
|
|
27
|
+
- [TypeScript](https://www.typescriptlang.org/) - provides strong compile time typing for JavaScript
|
|
28
|
+
- Jest - used for testing (see more information below)
|
|
29
|
+
- microbundle - used for the production bundle
|
|
30
|
+
- Webpack - used for bundling locally in development (`development` and `docs` folders)
|
|
31
|
+
- esno - for running tests quickly without type checking
|
|
32
|
+
|
|
33
|
+
### Precommit Hooks
|
|
34
|
+
|
|
35
|
+
It is probably useful to be aware of the precommit hooks you will face when trying to run a git commit on the project. There are two currently in use, namely:
|
|
36
|
+
|
|
37
|
+
- Uses pre-commit hook to run lint rules (eslint/prettier) on code before commit
|
|
38
|
+
- Uses pre-commit hook to ensure [conventional commit messages](https://www.conventionalcommits.org/en/v1.0.0/) are used
|
|
39
|
+
|
|
40
|
+
### Testing
|
|
41
|
+
|
|
42
|
+
Terra Draw uses [jest](https://jestjs.io/) as it's testing framework. You can distinguish a test by it's `.spec.ts` prefix on the file name.
|
|
43
|
+
|
|
44
|
+
To run the tests as they would run in CI:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
npm run test
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You can also check the coverage by running:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
npm run test:coverage
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For local development you may benefit from the `nocheck` option which allows you to avoid running TypeScript type checking when running the tests. This option also only checks files which are explicitly tested (i.e. have a spec file.)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
npm run test:nocheck
|
|
60
|
+
npm run test:nocheck:coverage
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Developing Locally
|
|
64
|
+
|
|
65
|
+
A folder called `development` has been set up locally to allow you to test developing Terra Draw locally more easily. It allows you to run the different adapters and test different map providers in parallel, ensuring. You will need to update the .env file in the `development` folder in order to use the related adapters working. An example `.env` file in the `development` folder:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
GOOGLE_API_KEY=YOUR_KEY_HERE
|
|
69
|
+
MAPBOX_ACCESS_TOKEN=YOUR_KEY_HERE
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Terra Draw Concepts
|
|
73
|
+
|
|
74
|
+
Terra Draw has a few elementary concepts that allow it to stay strongly decoupled and relatively map library agnostic. Lets walk through them:
|
|
75
|
+
|
|
76
|
+
- **Store**: - at the heart of the library, where geometry data is stored, created, updated and deleted. Data is stored as standard GeoJSON.
|
|
77
|
+
- **Adapters**: thin wrappers that contain map library specific logic, for creating and updating layers that can rendered by the mapping library
|
|
78
|
+
- **Modes**: - modes represent the logic for a specific drawing tool, for example the point, line and polygon modes
|
|
79
|
+
|
|
80
|
+
### Adapters Explained
|
|
81
|
+
|
|
82
|
+
Adapters are a core aspect of Terra Draw - they are the layer between the core of the library and the external mapping libraries (Leaflet, Google Maps etc). In simple terms an adapter takes input events, passes them through to create geometries in the store and then passes them back to the adapter to be rendered specifically for the mapping library. For example, in the `LeafletAdapter` we create and update a GeoJSON layer that Leaflet knows how to render to the screen. In theory an adapter could be created for any mapping library that can fill out the Adapter abstract class (TerraDrawBaseAdapter). Namely these are methods that would need to be completed:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
public project(...args: Parameters<Project>): ReturnType<Project>;
|
|
86
|
+
|
|
87
|
+
public unproject(
|
|
88
|
+
...args: Parameters<Unproject>
|
|
89
|
+
): ReturnType<Unproject>;
|
|
90
|
+
|
|
91
|
+
public setCursor(
|
|
92
|
+
...args: Parameters<SetCursor>
|
|
93
|
+
): ReturnType<SetCursor>;
|
|
94
|
+
|
|
95
|
+
public getLngLatFromEvent(event: PointerEvent | MouseEvent): {
|
|
96
|
+
lng: number;
|
|
97
|
+
lat: number;
|
|
98
|
+
} | null;
|
|
99
|
+
|
|
100
|
+
public setDraggability(enabled: boolean): void;
|
|
101
|
+
|
|
102
|
+
public setDoubleClickToZoom(enabled: boolean): void;
|
|
103
|
+
|
|
104
|
+
public getMapContainer(): HTMLElement;
|
|
105
|
+
|
|
106
|
+
public render(
|
|
107
|
+
changes: TerraDrawChanges,
|
|
108
|
+
styling: TerraDrawStylingFunction
|
|
109
|
+
): void;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Modes Explained
|
|
113
|
+
|
|
114
|
+
Modes are another important concept in Terra Draw. Modes are a way to encapsulate specific logic for drawing a certain entity. For example, there are built in modes for drawing points, lines, polygons, circles and rectangles.
|
|
115
|
+
|
|
116
|
+
Modes can go beyond just drawing however, for example the built in `TerraDrawSelectMode` allows for selection and editing of geometries that have previously been drawn. Another example of a mode that is not explicitly just editing is `TerraDrawRenderMode` which can be considered to be a 'view only mode' and used if you wanted to show some contextual data in your application alongside data that you want to edit.
|
|
117
|
+
|
|
118
|
+
Assuming that a mode extends from `TerraDrawBaseMode`
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
/** @internal */
|
|
122
|
+
start() {
|
|
123
|
+
this.setStarted();
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @internal */
|
|
128
|
+
stop() {
|
|
129
|
+
this.setStopped();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** @internal */
|
|
133
|
+
onClick(event: TerraDrawMouseEvent) {}
|
|
134
|
+
|
|
135
|
+
/** @internal */
|
|
136
|
+
onMouseMove(event: TerraDrawMouseEvent) {}
|
|
137
|
+
|
|
138
|
+
/** @internal */
|
|
139
|
+
onKeyDown(event: TerraDrawKeyboardEvent) {}
|
|
140
|
+
|
|
141
|
+
/** @internal */
|
|
142
|
+
onKeyUp(event: TerraDrawKeyboardEvent) {}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/** @internal */
|
|
146
|
+
onDragStart(event: TerraDrawMouseEvent) {}
|
|
147
|
+
|
|
148
|
+
/** @internal */
|
|
149
|
+
onDrag(event: TerraDrawMouseEvent) {}
|
|
150
|
+
|
|
151
|
+
/** @internal */
|
|
152
|
+
onDragEnd(event: TerraDrawMouseEvent) {}
|
|
153
|
+
|
|
154
|
+
/** @internal */
|
|
155
|
+
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling {}
|
|
156
|
+
```
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
We start with the assumption that you have [Node.js](https://nodejs.org/en) installed and [npm](https://www.npmjs.com/) (node package manager).
|
|
6
|
+
|
|
7
|
+
You can install the Terra Draw into your project like so:
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install terra-draw
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Be aware Terra Draw is currently in alpha, the initial API is still being finalised. It is strongly advised to pin your installation to a specific version i.e. not using carat, asterix or tilde for versions but giving a version explicitly in your `package.json`
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
"terra-draw": "0.0.1-alpha.22"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Once terra-draw is out of alpha this suggestion will be removed as we will aim to move to semantic versioning.
|
|
20
|
+
|
|
21
|
+
## API Docs
|
|
22
|
+
|
|
23
|
+
You can find the full autogenerated [API docs on the terra draw website](https://terradraw.io/#/api)
|
|
24
|
+
|
|
25
|
+
## Using Terra Draw
|
|
26
|
+
|
|
27
|
+
Terra Draw can be used with a set of different adapters to allow you to use it with your mapping library of choice. Each adapter has slightly different configuration but the API is the same for them all. For a deeper explanation about what adapters are and how to write you own see the [development guide](./DEVELOPMENT.md).
|
|
28
|
+
|
|
29
|
+
### Leaflet
|
|
30
|
+
|
|
31
|
+
Here is some simple starter code for using Terra Draw with the popular open source mapping library Leaflet. It assumes you are going instantiate your map in a div with and id of `map`, which is assumed to exist within your HTML.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Import the leaflet mapping library
|
|
35
|
+
import * as L from "leaflet";
|
|
36
|
+
|
|
37
|
+
// Import Terra Draw, we will import the leaflet adapter, select mode and polygon mode
|
|
38
|
+
import {
|
|
39
|
+
TerraDraw,
|
|
40
|
+
TerraDrawLeafletAdapter,
|
|
41
|
+
TerraDrawSelectMode,
|
|
42
|
+
TerraDrawPolygonMode,
|
|
43
|
+
} from "terra-draw";
|
|
44
|
+
|
|
45
|
+
// Initialize a new Leaflet map, providing the id of the div to display the map
|
|
46
|
+
// Set the initial center (latitude, longitude) and the zoom level
|
|
47
|
+
const leafletMap = L.map("map", {
|
|
48
|
+
center: [lat, lng],
|
|
49
|
+
zoom: 4, // starting zoom,
|
|
50
|
+
minZoom: 3,
|
|
51
|
+
maxZoom: 20,
|
|
52
|
+
tapTolerance: 10,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Add a basemap from OpenStreetMap to the Leaflet map
|
|
56
|
+
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
57
|
+
maxZoom: 19,
|
|
58
|
+
attribution:
|
|
59
|
+
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
|
60
|
+
}).addTo(leafletMap);
|
|
61
|
+
|
|
62
|
+
// Instantiate the TerraDraw API with a Leaflet adapter and custom modes
|
|
63
|
+
const draw = new TerraDraw({
|
|
64
|
+
adapter: new TerraDrawLeafletAdapter({
|
|
65
|
+
// The leaflet library object
|
|
66
|
+
lib: leaflet,
|
|
67
|
+
|
|
68
|
+
// The leaflet map object we created
|
|
69
|
+
map: leafletMap,
|
|
70
|
+
|
|
71
|
+
// The decimal precision of the coordinates created
|
|
72
|
+
coordinatePrecision: 9,
|
|
73
|
+
}),
|
|
74
|
+
|
|
75
|
+
// Modes is an object containing all the modes we wish to
|
|
76
|
+
// instantiate Terra Draw with
|
|
77
|
+
modes: {
|
|
78
|
+
select: new TerraDrawSelectMode({
|
|
79
|
+
flags: {
|
|
80
|
+
// Following flags determine what you can do in
|
|
81
|
+
// select mode for features of a given mode - in this case polygon
|
|
82
|
+
polygon: {
|
|
83
|
+
feature: {
|
|
84
|
+
scaleable: true,
|
|
85
|
+
rotateable: true,
|
|
86
|
+
draggable: true,
|
|
87
|
+
coordinates: {
|
|
88
|
+
midpoints: true,
|
|
89
|
+
draggable: true,
|
|
90
|
+
deletable: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
polygon: new TerraDrawPolygonMode({
|
|
97
|
+
allowSelfIntersections: false,
|
|
98
|
+
pointerDistance: 30,
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Start drawing
|
|
104
|
+
draw.start();
|
|
105
|
+
|
|
106
|
+
// Set the mode to polygon
|
|
107
|
+
draw.setMode("polygon");
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Google Maps API
|
|
111
|
+
|
|
112
|
+
Here is some starter code for using Terra Draw with the Google Maps API. It assumes you are going instantiate your map in a div with and id of `map`, which is assumed to exist within your HTML.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// Import the google maps api loader
|
|
116
|
+
import { Loader } from "@googlemaps/js-api-loader";
|
|
117
|
+
|
|
118
|
+
// Import Terra Draw, we will import the leaflet adapter, select mode and polygon mode
|
|
119
|
+
import {
|
|
120
|
+
TerraDraw,
|
|
121
|
+
TerraDrawLeafletAdapter,
|
|
122
|
+
TerraDrawSelectMode,
|
|
123
|
+
TerraDrawPolygonMode,
|
|
124
|
+
} from "terra-draw";
|
|
125
|
+
|
|
126
|
+
const loader = new Loader({
|
|
127
|
+
apiKey: "INSERT_YOUR_API_KEY_HERE", // You need to provide your own API key here
|
|
128
|
+
version: "weekly",
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// We need to await the google maps api
|
|
132
|
+
loader.load().then((google) => {
|
|
133
|
+
// Create the map
|
|
134
|
+
const map = new google.maps.Map(document.getElementById("map"), {
|
|
135
|
+
disableDefaultUI: true,
|
|
136
|
+
center: { lat: this.lat, lng: this.lng },
|
|
137
|
+
zoom: this.zoom,
|
|
138
|
+
|
|
139
|
+
//Setting clickableIcons to false is used to disable the default behavior of the
|
|
140
|
+
// Google Maps API, which is to allow users to interact with clickable icons on the
|
|
141
|
+
// map, such as points of interest (POIs) or other interactive map elements.
|
|
142
|
+
clickableIcons: false,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// When using Google Maps, it's important to wrap the creation of custom overlays or other // map-related initializations inside the 'projection_changed' event listener to ensure
|
|
146
|
+
// that the map's projection is fully loaded before your code runs.
|
|
147
|
+
map.addListener("projection_changed", () => {
|
|
148
|
+
const draw = new TerraDraw({
|
|
149
|
+
adapter: new TerraDrawGoogleMapsAdapter({
|
|
150
|
+
lib: google.maps,
|
|
151
|
+
map,
|
|
152
|
+
coordinatePrecision: 9,
|
|
153
|
+
}),
|
|
154
|
+
modes: {
|
|
155
|
+
select: new TerraDrawSelectMode({
|
|
156
|
+
flags: {
|
|
157
|
+
// Following flags determine what you can do in
|
|
158
|
+
// select mode for features of a given mode - in this case polygon
|
|
159
|
+
polygon: {
|
|
160
|
+
feature: {
|
|
161
|
+
scaleable: true,
|
|
162
|
+
rotateable: true,
|
|
163
|
+
draggable: true,
|
|
164
|
+
coordinates: {
|
|
165
|
+
midpoints: true,
|
|
166
|
+
draggable: true,
|
|
167
|
+
deletable: true,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
polygon: new TerraDrawPolygonMode({
|
|
174
|
+
allowSelfIntersections: false,
|
|
175
|
+
pointerDistance: 30,
|
|
176
|
+
}),
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Start drawing
|
|
181
|
+
draw.start();
|
|
182
|
+
|
|
183
|
+
// Set the mode to polygon
|
|
184
|
+
draw.setMode("polygon");
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### OpenLayers
|
|
190
|
+
|
|
191
|
+
Coming soon - please see development folder for example for now.
|
|
192
|
+
|
|
193
|
+
### MapboxGL JS
|
|
194
|
+
|
|
195
|
+
Coming soon - please see development folder for example for now.
|
|
196
|
+
|
|
197
|
+
### MapLibreGL JS
|
|
198
|
+
|
|
199
|
+
Coming soon - please see development folder for example for now.
|
|
200
|
+
|
|
201
|
+
## Other Examples
|
|
202
|
+
|
|
203
|
+
There are a few other working examples that you can use as points of reference for creating a new app using Terra Draw.
|
|
204
|
+
|
|
205
|
+
### Development Example
|
|
206
|
+
|
|
207
|
+
The [development folder features an example](https://github.com/JamesLMilner/terra-draw/tree/main/development) of using Terra Draw with all the adapters. It is meant for local development but can also be used as a guide of how to use Terra Draw with each adapter without any frame work.
|
|
208
|
+
|
|
209
|
+
### Full Example
|
|
210
|
+
|
|
211
|
+
The [Terra Draw official website](https://github.com/JamesLMilner/terra-draw-website) is open source acts as a full working implementation of how to use Terra Draw. In this case it is used with popular framework Preact (has very similar API to React).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "terra-draw",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.23",
|
|
4
4
|
"description": "Frictionless map drawing across mapping provider",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"docs": "typedoc",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"@types/leaflet": "^1.7.11",
|
|
60
60
|
"@types/mapbox-gl": "^2.7.3",
|
|
61
61
|
"@types/rbush": "^3.0.0",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
63
|
-
"@typescript-eslint/parser": "^5.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
63
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
64
64
|
"eslint": "^8.24.0",
|
|
65
65
|
"eslint-config-prettier": "^8.5.0",
|
|
66
66
|
"eslint-plugin-prettier": "^4.2.1",
|
|
67
67
|
"husky": "^7.0.0",
|
|
68
68
|
"jest": "^29.3.1",
|
|
69
69
|
"leaflet": "^1.8.0",
|
|
70
|
-
"mapbox-gl": "^2.
|
|
70
|
+
"mapbox-gl": "^2.13.0",
|
|
71
71
|
"maplibre-gl": "^2.4.0",
|
|
72
72
|
"microbundle": "^0.15.0",
|
|
73
73
|
"ol": "^7.1.0",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"standard-version": "^9.5.0",
|
|
76
76
|
"ts-jest": "^29.0.3",
|
|
77
77
|
"ts-loader": "^9.4.2",
|
|
78
|
-
"typedoc": "^0.23.
|
|
79
|
-
"typescript": "^
|
|
78
|
+
"typedoc": "^0.23.28",
|
|
79
|
+
"typescript": "^5.0.3"
|
|
80
80
|
},
|
|
81
81
|
"commitlint": {
|
|
82
82
|
"extends": [
|
package/scratch/release.sh
CHANGED
package/tsconfig.json
CHANGED
package/DEVELOPMENT.md
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# Development
|
|
2
|
-
|
|
3
|
-
This file acts as a way to document how to develop the Terra Draw project locally.
|
|
4
|
-
|
|
5
|
-
### Prerequisites
|
|
6
|
-
|
|
7
|
-
A few things you will need to have installed in order to develop on this project:
|
|
8
|
-
|
|
9
|
-
* git
|
|
10
|
-
* Node LTS - currently v16
|
|
11
|
-
* npm 8
|
|
12
|
-
|
|
13
|
-
### Folder Structure
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* `.github` - used for all GitHub related configuration such as the GitHub Actions work flows
|
|
17
|
-
* `.husky` - used to storing the precommit hooks that are used on the project
|
|
18
|
-
* `src` - source files for the project
|
|
19
|
-
* `dist` - the bundled distributed files of the project
|
|
20
|
-
* `docs` - the demo app that is published to GitHub pages
|
|
21
|
-
* `development` - the local development app that is used for developing locally (see below)
|
|
22
|
-
* `common` - code that is used across `development` and `docs` folder`
|
|
23
|
-
|
|
24
|
-
### Technologies Used
|
|
25
|
-
|
|
26
|
-
Terra Draw
|
|
27
|
-
|
|
28
|
-
* [TypeScript](https://www.typescriptlang.org/) - provides strong compile time typing for JavaScript
|
|
29
|
-
* Jest - used for testing (see more information below)
|
|
30
|
-
* microbundle - used for the production bundle
|
|
31
|
-
* Webpack - used for bundling locally in development (`development` and `docs` folders)
|
|
32
|
-
* esno - for running tests quickly without type checking
|
|
33
|
-
|
|
34
|
-
### Precommit Hooks
|
|
35
|
-
|
|
36
|
-
It is probably useful to be aware of the precommit hooks you will face when trying to run a git commit on the project. There are two currently in use, namely:
|
|
37
|
-
|
|
38
|
-
* Uses pre-commit hook to run lint rules (eslint/prettier) on code before commit
|
|
39
|
-
* Uses pre-commit hook to ensure [conventional commit messages](https://www.conventionalcommits.org/en/v1.0.0/) are used
|
|
40
|
-
|
|
41
|
-
### Testing
|
|
42
|
-
|
|
43
|
-
Terra Draw uses [jest](https://jestjs.io/) as it's testing framework. You can distinguish a test by it's `.spec.ts` prefix on the file name.
|
|
44
|
-
|
|
45
|
-
To run the tests as they would run in CI:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
npm run test
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
You can also check the coverage by running:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
npm run test:coverage
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
For local development you may benefit from the `nocheck` option which allows you to avoid running TypeScript type checking when running the tests. This option also only checks files which are explicitly tested (i.e. have a spec file.)
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
npm run test:nocheck
|
|
62
|
-
npm run test:nocheck:coverage
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Developing Locally
|
|
66
|
-
|
|
67
|
-
A folder called `development` has been set up locally to allow you to test developing Terra Draw locally more easily. It allows you to run the different adapters and test different map providers in parallel, ensuring. You will need to update the .env file in the `development` folder in order to use the related adapters working. An example `.env` file in the `development` folder:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
GOOGLE_API_KEY=YOUR_KEY_HERE
|
|
72
|
-
MAPBOX_ACCESS_TOKEN=YOUR_KEY_HERE
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### GitHub Pages Example
|
|
76
|
-
|
|
77
|
-
We also provide a GitHub Pages example that can developed on in the `docs` folder. This automatically deploys from the `main` branch.
|
|
File without changes
|