terra-draw 0.0.1-alpha.44 → 0.0.1-alpha.47
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 +2 -1
- package/dist/adapters/common/base.adapter.d.ts +4 -0
- package/dist/common.d.ts +7 -2
- package/dist/geometry/shape/create-bbox.d.ts +10 -0
- package/dist/modes/circle/circle.mode.d.ts +9 -4
- package/dist/modes/click-bounding-box.behavior.d.ts +1 -2
- package/dist/modes/freehand/freehand.mode.d.ts +7 -1
- package/dist/modes/greatcircle/great-circle.mode.d.ts +7 -1
- package/dist/modes/linestring/linestring.mode.d.ts +7 -1
- package/dist/modes/point/point.mode.d.ts +6 -1
- package/dist/modes/polygon/polygon.mode.d.ts +7 -1
- package/dist/modes/rectangle/rectangle.mode.d.ts +6 -1
- package/dist/modes/render/render.mode.d.ts +1 -0
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +1 -1
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +2 -2
- package/dist/modes/select/behaviors/feature-at-pointer-event.behavior.d.ts +15 -0
- package/dist/modes/select/select.mode.d.ts +11 -1
- package/dist/modes/snapping.behavior.d.ts +2 -0
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +27 -3
- 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/package.json +2 -1
- package/CHANGELOG.md +0 -409
- package/dist/adapters/common/base-adapter.d.ts +0 -31
- package/dist/bundle.js +0 -6
- package/dist/bundle.js.LICENSE.txt +0 -4
- package/dist/extend-types.d.ts +0 -4
- package/dist/geometry/create-circle.d.ts +0 -6
- package/dist/geometry/get-pixel-distance-to-line.d.ts +0 -10
- package/dist/geometry/get-pixel-distance.d.ts +0 -7
- package/dist/geometry/haversine-distance.d.ts +0 -1
- package/dist/geometry/point-in-polygon.d.ts +0 -1
- package/dist/geometry/self-intersects.d.ts +0 -2
- package/dist/modes/circle.mode.d.ts +0 -18
- package/dist/modes/freehand.mode.d.ts +0 -20
- package/dist/modes/line-string.mode.d.ts +0 -21
- package/dist/modes/point.mode.d.ts +0 -14
- package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +0 -11
- package/dist/modes/polygon.mode.d.ts +0 -21
- package/dist/modes/select.mode.d.ts +0 -21
- package/dist/modes/static.mode.d.ts +0 -10
- package/guides/CODE_OF_CONDUCT.md +0 -36
- package/guides/CONTRIBUTING.md +0 -17
- package/guides/DEVELOPMENT.md +0 -156
- package/guides/GETTING_STARTED.md +0 -332
- package/jest.config.ts +0 -27
- package/logo.png +0 -0
- package/scratch/release.sh +0 -5
- package/scripts/next-alpha-version.ts +0 -21
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
Contributor Covenant Code of Conduct
|
|
2
|
-
Our Pledge
|
|
3
|
-
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
4
|
-
|
|
5
|
-
Our Standards
|
|
6
|
-
Examples of behavior that contributes to creating a positive environment include:
|
|
7
|
-
|
|
8
|
-
Using welcoming and inclusive language
|
|
9
|
-
Being respectful of differing viewpoints and experiences
|
|
10
|
-
Gracefully accepting constructive criticism
|
|
11
|
-
Focusing on what is best for the community
|
|
12
|
-
Showing empathy towards other community members
|
|
13
|
-
Examples of unacceptable behavior by participants include:
|
|
14
|
-
|
|
15
|
-
The use of sexualized language or imagery and unwelcome sexual attention or advances
|
|
16
|
-
Trolling, insulting/derogatory comments, and personal or political attacks
|
|
17
|
-
Public or private harassment
|
|
18
|
-
Publishing others' private information, such as a physical or electronic address, without explicit permission
|
|
19
|
-
Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
20
|
-
Our Responsibilities
|
|
21
|
-
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
|
22
|
-
|
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
|
24
|
-
|
|
25
|
-
Scope
|
|
26
|
-
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
|
27
|
-
|
|
28
|
-
Enforcement
|
|
29
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at codeofconduct@loxo.industries. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
|
30
|
-
|
|
31
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
|
32
|
-
|
|
33
|
-
Attribution
|
|
34
|
-
This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
|
35
|
-
|
|
36
|
-
For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq
|
package/guides/CONTRIBUTING.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
## Instructions
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
## Code of Conduct
|
|
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).
|
package/guides/DEVELOPMENT.md
DELETED
|
@@ -1,156 +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
|
-
- `.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
|
-
```
|
|
@@ -1,332 +0,0 @@
|
|
|
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).
|
|
212
|
-
|
|
213
|
-
## Common Patterns
|
|
214
|
-
|
|
215
|
-
### Loading in External Data
|
|
216
|
-
|
|
217
|
-
It is common pattern to want to load in data from an external source (GeoJSON file, API call, etc). This can be achieved with the `addFeatures` method on the Terra Draw instance. The method call works out which mode to add the feature based on looking at its `mode` property in the Features `properties` property. All modes have a method called `validateFeature` that ensures that a given feature is valid for the mode. For example if you wanted to add a series of points to the TerraDrawPointMode you could do this by ensuring that the points you feed in have the `mode` property set to `point`.
|
|
218
|
-
|
|
219
|
-
```javascript
|
|
220
|
-
points.forEach((point) => {
|
|
221
|
-
point.properties.mode = "point";
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
draw.addFeatures(points);
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Render Only Modes with TerraDrawRenderMode
|
|
228
|
-
|
|
229
|
-
If you just want to render some data onto the map without it being editable, you can use `TerraDrawRenderMode` in combination with `addFeatures` like so:
|
|
230
|
-
|
|
231
|
-
```javascript
|
|
232
|
-
const draw = new TerraDraw({
|
|
233
|
-
adapter: new TerraDrawLeafletAdapter({
|
|
234
|
-
lib: L,
|
|
235
|
-
map,
|
|
236
|
-
coordinatePrecision: 9,
|
|
237
|
-
}),
|
|
238
|
-
modes: {
|
|
239
|
-
arbitary: new TerraDrawRenderMode(),
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
draw.start();
|
|
244
|
-
|
|
245
|
-
points.forEach((point) => {
|
|
246
|
-
point.properties.mode = "arbitary";
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
draw.addFeatures(points);
|
|
250
|
-
|
|
251
|
-
// This will add the points to hte TerraDrawRenderMode 'arbitary' rendering them to the screen
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
### Styling Selected Data
|
|
255
|
-
|
|
256
|
-
To style selected data you will want to past styles to the select mode you are using (probably TerraDrawSelectMode).
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
const draw = new TerraDraw({
|
|
260
|
-
adapter: new TerraDrawMapboxGLAdapter({
|
|
261
|
-
map,
|
|
262
|
-
coordinatePrecision: 9,
|
|
263
|
-
}),
|
|
264
|
-
modes: {
|
|
265
|
-
polygon: new TerraDrawPolygonMode(),
|
|
266
|
-
select: new TerraDrawSelectMode({
|
|
267
|
-
flags: {
|
|
268
|
-
polygon: {
|
|
269
|
-
feature: {
|
|
270
|
-
draggable: true,
|
|
271
|
-
coordinates: {
|
|
272
|
-
midpoints: true,
|
|
273
|
-
draggable: true,
|
|
274
|
-
deletable: true,
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
styles: {
|
|
280
|
-
selectedPolygonColor: "#222222", // Any hex color you like
|
|
281
|
-
selectedPolygonFillOpacity: 0.7, // 0 - 1
|
|
282
|
-
selectedPolygonOutlineColor: "#333333", // Any hex color you like
|
|
283
|
-
selectedPolygonOutlineWidth: 2, // Integer
|
|
284
|
-
},
|
|
285
|
-
}),
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
draw.start();
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
Please note at the moment it is not possible to style against specific modes but only universally against geometry type (Point, LineString, Polygon)
|
|
293
|
-
|
|
294
|
-
## Styling Specific Features
|
|
295
|
-
|
|
296
|
-
Terra Draw supports styling overrides of individual features if required. This can be achieved by providing a styling function rather than a string or a number to a feature. As an example here we can style each polygon feature as a random color:
|
|
297
|
-
|
|
298
|
-
```typescript
|
|
299
|
-
// Function to generate a random hex color - can adjust as needed
|
|
300
|
-
function getRandomColor() {
|
|
301
|
-
const letters = "0123456789ABCDEF";
|
|
302
|
-
let color = "#";
|
|
303
|
-
for (let i = 0; i < 6; i++) {
|
|
304
|
-
color += letters[Math.floor(Math.random() * 16)];
|
|
305
|
-
}
|
|
306
|
-
return color;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Cache for each feature id mapped to a hex color string
|
|
310
|
-
const colorCache: Record<string, HexColor> = {};
|
|
311
|
-
|
|
312
|
-
const draw = new TerraDraw({
|
|
313
|
-
adapter: new TerraDrawMapboxGLAdapter({
|
|
314
|
-
map, // Assume this is defined further up
|
|
315
|
-
coordinatePrecision: 9,
|
|
316
|
-
}),
|
|
317
|
-
modes: {
|
|
318
|
-
polygon: new TerraDrawPolygonMode({
|
|
319
|
-
styles: {
|
|
320
|
-
fillColor: ({ id }) => {
|
|
321
|
-
// Get the color from the cache or generate a new one
|
|
322
|
-
colorCache[id] = colorCache[id] || getRandomColor();
|
|
323
|
-
return colorCache[id];
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
}),
|
|
327
|
-
},
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
// Ensure the color cache is clead up on deletion of features
|
|
331
|
-
draw.on("delete", (ids) => ids.forEach((id) => delete cache[id]));
|
|
332
|
-
```
|
package/jest.config.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
let options = {};
|
|
2
|
-
|
|
3
|
-
if (process.env.NO_CHECK) {
|
|
4
|
-
options = {
|
|
5
|
-
transform: {
|
|
6
|
-
"^.+\\.(t|j)sx?$": "@swc/jest",
|
|
7
|
-
},
|
|
8
|
-
coveragePathIgnorePatterns: ["<rootDir>/src/test/"],
|
|
9
|
-
setupFilesAfterEnv: ["<rootDir>/src/test/jest.matchers.ts"],
|
|
10
|
-
};
|
|
11
|
-
} else {
|
|
12
|
-
options = {
|
|
13
|
-
preset: "ts-jest",
|
|
14
|
-
testEnvironment: "node",
|
|
15
|
-
coveragePathIgnorePatterns: ["<rootDir>/src/test/"],
|
|
16
|
-
setupFilesAfterEnv: ["<rootDir>/src/test/jest.matchers.ts"],
|
|
17
|
-
collectCoverage: true,
|
|
18
|
-
collectCoverageFrom: ["./src/**"],
|
|
19
|
-
coverageThreshold: {
|
|
20
|
-
global: {
|
|
21
|
-
lines: 65,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = options;
|
package/logo.png
DELETED
|
Binary file
|
package/scratch/release.sh
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
|
|
3
|
-
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
|
|
4
|
-
|
|
5
|
-
if (packageJson.version.includes("alpha")) {
|
|
6
|
-
const currentVersion = packageJson.version.split(".").pop();
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
currentVersion === undefined ||
|
|
10
|
-
currentVersion === null ||
|
|
11
|
-
isNaN(currentVersion)
|
|
12
|
-
) {
|
|
13
|
-
throw new Error("Could not get current version number");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const nextVersion = parseInt(currentVersion) + 1;
|
|
17
|
-
|
|
18
|
-
console.log(nextVersion);
|
|
19
|
-
} else {
|
|
20
|
-
throw new Error("This script is for alpha releases only");
|
|
21
|
-
}
|