How to develop the Terra Draw project locally.
You will need to have the following installed:
.github
- used for all GitHub related configuration such as the GitHub Actions work flows.husky
- used to storing the precommit hooks that are used on the projectsrc
- source files for the projectdist
- the bundled distributed files of the projectdocs
- the demo app that is published to GitHub pagesguides
- learn how to use Terra Drawdevelopment
- the local development app that is used for developing locally (see below)common
- code that is used acrossdevelopment
anddocs
folder
- TypeScript - provides strong compile time typing for JavaScript
- Jest - used for testing (see more information below)
- microbundle - used for the production bundle
- Webpack - used for bundling locally in development (
development
anddocs
folders) - esno - for running tests quickly without type checking
To build the project, you will need to install the dependencies from the project root:
npm install
You may also need to change directory to e2e and install dependencies in there too.
You can then build the project using:
npm run build
You can also create a watching build that detects changes and rebuilds the project automatically. This can help when developing locally.
To create a watching build, first from the root level of the project go into the e2e
folder and install the dependencies for the tests.
cd e2e/
npm install
After that, from the root level go into the development
folder and install the dependencies.
cd development/
npm install
If you don't have the API keys for GoogleAPI and Mapbox, comment out the corresponding libraries inside development\src\config.ts
.
export const Config = {
libraries: [
Libraries.Leaflet,
Libraries.MapLibre,
// Libraries.Mapbox,
// Libraries.Google,
Libraries.OpenLayers,
Libraries.ArcGIS,
] as const,
};
If you do have the API keys, refer to the README.md
file inside the development
folder to see how to set up the .env
file with the APIs keys.
After that, you can run the following command to start the watching build, inside the development
folder.
npm run serve
In theory an adapter could be created for any mapping library that can fill out the Adapter abstract class (TerraDrawBaseAdapter
).
For example, in the LeafletAdapter
we create and update a GeoJSON layer that Leaflet knows how to render to the screen.
Assuming that an adapter extends from TerraDrawBaseAdapter
, these methods would need to be implemented:
public project(...args: Parameters<Project>): ReturnType<Project>;
public unproject(
...args: Parameters<Unproject>
): ReturnType<Unproject>;
public setCursor(
...args: Parameters<SetCursor>
): ReturnType<SetCursor>;
public getLngLatFromEvent(event: PointerEvent | MouseEvent): {
lng: number;
lat: number;
} | null;
public setDraggability(enabled: boolean): void;
public setDoubleClickToZoom(enabled: boolean): void;
public getMapEventElement(): HTMLElement;
public render(
changes: TerraDrawChanges,
styling: TerraDrawStylingFunction
): void;
You can see a very basic example adapter in the terra-draw.extensions.spec.ts
file. It shows how you can create your own adapter from the publicly exposed library imports.
Modes are not just limited to drawing features, for example the built-in TerraDrawSelectMode
allows for selection and editing of geometries that have previously been drawn. The TerraDrawRenderMode
is a "view only" Mode useful for showing non-editable data alongside editable data in your application.
Assuming that a mode extends from TerraDrawBaseMode
:
/** @internal */
start() {
this.setStarted();
}
/** @internal */
stop() {
this.setStopped();
}
/** @internal */
onClick(event: TerraDrawMouseEvent) {}
/** @internal */
onMouseMove(event: TerraDrawMouseEvent) {}
/** @internal */
onKeyDown(event: TerraDrawKeyboardEvent) {}
/** @internal */
onKeyUp(event: TerraDrawKeyboardEvent) {}
/** @internal */
onDragStart(event: TerraDrawMouseEvent) {}
/** @internal */
onDrag(event: TerraDrawMouseEvent) {}
/** @internal */
onDragEnd(event: TerraDrawMouseEvent) {}
/** @internal */
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling {}
You can see a very basic example mode in the terra-draw.extensions.spec.ts
file. It shows how you can create your own mode from the publicly exposed library imports.
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:
- Uses pre-commit hook to run lint rules (eslint/prettier) on code before commit.
- Uses pre-commit hook to ensure conventional commit messages are used.
Terra Draw uses Jest as it's testing framework. You can distinguish a test by it's .spec.ts
file name extension.
To run the tests as they would run in CI:
npm run test
You can also check the coverage by running:
npm run test:coverage
If coverage (either lines, branches, functions or statements) falls under 80%, this script will fail.
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.)
npm run test:nocheck
npm run test:nocheck:coverage
The development/
directory contains an App that aims to make developing Terra Draw locally easier.
It allows you to run each mapping provider adapter in parallel, allowing for fast development and testing in the browser as you make changes. See the development/
README for more information.
If you wish to contribute to Terra Draw, we request that you:
- Make an issue on GitHub describing the bug you intend to fix or the feature you intend to add.
- Create a fork of the project, and work on a branch that represents the issue.
- Ensure that the work you have done is unit tested, aiming for 80% code coverage.
- Create a PR that represents this work with a conventional commit title (this ensures the automated changelog is generated correctly). Please refer to the issue from the PR and follow the PR template.
- We will address the PR and give you feedback.
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.
We have a code of conduct which we expect individuals interacting with the project to respect. Please refer to the full Code of Conduct.
Guides