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,27 @@
|
|
|
1
|
+
name: Terra Draw CI Tasks
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
tests:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v2
|
|
14
|
+
- name: Use Node
|
|
15
|
+
uses: actions/setup-node@v1
|
|
16
|
+
with:
|
|
17
|
+
node-version: "16.x"
|
|
18
|
+
- name: Install Parent Folder
|
|
19
|
+
run: npm install
|
|
20
|
+
- name: Ensure no package-lock.json changes
|
|
21
|
+
run: git diff --exit-code
|
|
22
|
+
- name: Build
|
|
23
|
+
run: npm run build
|
|
24
|
+
- name: Test
|
|
25
|
+
run: npm run test
|
|
26
|
+
env:
|
|
27
|
+
CI: true
|
|
@@ -0,0 +1,36 @@
|
|
|
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/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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 garauntee 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/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2022 James Milner
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<img src="docs/logo.png" alt="Terra Draw Logo" width="400"/>
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Frictionless map drawing across mapping libraries.
|
|
6
|
+
|
|
7
|
+
TerraDraw centralises map drawing logic and provides a host of out the box drawing modes that work across map providers (currently Leaflet, Mapbox, Google) via adapters.
|
|
8
|
+
|
|
9
|
+
### Development
|
|
10
|
+
|
|
11
|
+
Please see the [the development documentation](./DEVELOPMENT.md)
|
|
12
|
+
|
|
13
|
+
### Contributing
|
|
14
|
+
|
|
15
|
+
Please see the [the contributing documentation](./CONTRIBUTING.md)
|
|
16
|
+
|
|
17
|
+
### License
|
|
18
|
+
|
|
19
|
+
MIT
|
package/ROADMAP.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
## Roadmap
|
|
2
|
+
|
|
3
|
+
A simple file for tracking what's being worked on.
|
|
4
|
+
|
|
5
|
+
## Doing
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## To do
|
|
9
|
+
|
|
10
|
+
### Bugs
|
|
11
|
+
|
|
12
|
+
- Cross Provider
|
|
13
|
+
- Bug: Possible to create zero area polygons which are unselectable
|
|
14
|
+
- Bug: Snapping can snap to same coordinate mulitple times (idential coordinate proptection?)
|
|
15
|
+
- Bug: Dragging doesn't trigger dragging cursor on mouse down
|
|
16
|
+
- Mapbox
|
|
17
|
+
- Bug (Mapbox): More robust implementation for fixing zIndexing for layers for Mapbox
|
|
18
|
+
- Bug (Mapbox): When drawing second coordinate the line can stop rendering at certain angles
|
|
19
|
+
- Google Maps
|
|
20
|
+
- Bug (Google Maps): Figure out why Polygons move so much slower selection points when dragged
|
|
21
|
+
- Bug (Google Maps): Does not respect midpoint insertion crosshair
|
|
22
|
+
|
|
23
|
+
### Chores
|
|
24
|
+
|
|
25
|
+
- Chore: Figure a more robust way to handle project/unproject in tests
|
|
26
|
+
- Chore: Identical coordinate protection
|
|
27
|
+
- Chore: Type properties for different mode features
|
|
28
|
+
- Chore: Add unit tests for rotation/scaling in Select mode
|
|
29
|
+
|
|
30
|
+
Could Do:
|
|
31
|
+
|
|
32
|
+
- Consider Tablets/Mobile devices
|
|
33
|
+
- Feature: Undo/Redo
|
|
34
|
+
|
|
35
|
+
## Done
|
|
36
|
+
|
|
37
|
+
- Chore: Enable TypeScript strict mode
|
|
38
|
+
- Bug (Leaflet): On click event triggered after dragging coordinate which deselects feature
|
|
39
|
+
- Chore: Demo that can run on GitHub
|
|
40
|
+
- Feature: Select - Scale
|
|
41
|
+
- Feature: Select - Rotation
|
|
42
|
+
- Chore: Come up with strategy for layering functionality/behaviors
|
|
43
|
+
- Bug: Can drag feature when cursor is not dragging over the feature
|
|
44
|
+
- Bug (Leaflet): Dragging coordinate deselects coordinate after drag
|
|
45
|
+
- Feature: Select renders Polygon and LineString coordinates
|
|
46
|
+
- Feature: Drag drawn feature
|
|
47
|
+
- Feature: Configurable keybindings
|
|
48
|
+
- Bug: Can't drag any more
|
|
49
|
+
- Chore: Make store take an array for updates/create etc
|
|
50
|
+
- Chore: Use Position instead of [number,number] for typing
|
|
51
|
+
- Feature: Set cursor
|
|
52
|
+
- Chore: Lifecycle state machine - registered -> start -> stop
|
|
53
|
+
- Chore: Create mock terra draw config
|
|
54
|
+
- Feature: Drag coordinates
|
|
55
|
+
- Chore: Code coverage back to 100% - test custom key bindings
|
|
56
|
+
- Chore: Spatial indexing
|
|
57
|
+
- Bug (Mapbox): Correct zIndexing for layers for Mapbox
|
|
58
|
+
- Feature: Snapping
|
|
59
|
+
- Feature: Insert midpoints
|
|
60
|
+
- Chore: Remove geometry logic from selection mode
|
|
61
|
+
- Feature: Right click to delete coordinate
|
|
62
|
+
- Chore: Show crosshairs when on inserting midpoints
|
|
63
|
+
- Bug (Mapbox): First two points of Mapbox Adapter polygons don't render
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TerraDraw } from "../src/terra-draw";
|
|
2
|
+
|
|
3
|
+
export const addModeChangeHandler = (
|
|
4
|
+
draw: TerraDraw,
|
|
5
|
+
currentSelected: { button: undefined | HTMLButtonElement; mode: string }
|
|
6
|
+
) => {
|
|
7
|
+
["select", "point", "linestring", "polygon", "freehand", "circle"].forEach(
|
|
8
|
+
(mode) => {
|
|
9
|
+
(document.getElementById(mode) as HTMLButtonElement).addEventListener(
|
|
10
|
+
"click",
|
|
11
|
+
() => {
|
|
12
|
+
currentSelected.mode = mode;
|
|
13
|
+
draw.changeMode(currentSelected.mode);
|
|
14
|
+
|
|
15
|
+
if (currentSelected.button) {
|
|
16
|
+
currentSelected.button.style.color = "565656";
|
|
17
|
+
}
|
|
18
|
+
currentSelected.button = document.getElementById(
|
|
19
|
+
mode
|
|
20
|
+
) as HTMLButtonElement;
|
|
21
|
+
currentSelected.button.style.color = "#27ccff";
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
};
|