terra-draw 0.0.1-alpha.31 → 0.0.1-alpha.32
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 +12 -0
- package/dist/geometry/boolean/is-valid-coordinate.d.ts +4 -0
- package/dist/geometry/boolean/is-valid-linestring-feature.d.ts +2 -0
- package/dist/geometry/boolean/is-valid-point.d.ts +2 -0
- package/dist/geometry/boolean/is-valid-polygon-feature.d.ts +3 -0
- package/dist/modes/base.mode.d.ts +1 -0
- package/dist/modes/circle/circle.mode.d.ts +1 -0
- package/dist/modes/freehand/freehand.mode.d.ts +1 -0
- package/dist/modes/greatcircle/great-circle.mode.d.ts +1 -0
- package/dist/modes/linestring/linestring.mode.d.ts +1 -0
- package/dist/modes/point/point.mode.d.ts +1 -0
- package/dist/modes/polygon/polygon.mode.d.ts +1 -0
- package/dist/modes/rectangle/rectangle.mode.d.ts +1 -0
- package/dist/modes/render/render.mode.d.ts +2 -0
- package/dist/store/store-feature-validation.d.ts +15 -0
- package/dist/store/store.d.ts +1 -3
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.d.ts +10 -1
- 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/guides/GETTING_STARTED.md +41 -0
- package/package.json +1 -1
|
@@ -198,6 +198,47 @@ Coming soon - please see development folder for example for now.
|
|
|
198
198
|
|
|
199
199
|
Coming soon - please see development folder for example for now.
|
|
200
200
|
|
|
201
|
+
## Common Patterns
|
|
202
|
+
|
|
203
|
+
### Loading in External Data
|
|
204
|
+
|
|
205
|
+
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`.
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
points.forEach((point) => {
|
|
209
|
+
point.properties.mode = "point";
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
draw.addFeatures(points);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Render Only Modes with TerraDrawRenderMode
|
|
216
|
+
|
|
217
|
+
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:
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
const draw = new TerraDraw({
|
|
221
|
+
adapter: new TerraDrawLeafletAdapter({
|
|
222
|
+
lib: L,
|
|
223
|
+
map,
|
|
224
|
+
coordinatePrecision: 9,
|
|
225
|
+
}),
|
|
226
|
+
modes: {
|
|
227
|
+
arbitary: new TerraDrawRenderMode(),
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
draw.start();
|
|
232
|
+
|
|
233
|
+
points.forEach((point) => {
|
|
234
|
+
point.properties.mode = "arbitary";
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
draw.addFeatures(points);
|
|
238
|
+
|
|
239
|
+
// This will add the points to hte TerraDrawRenderMode 'arbitary' rendering them to the screen
|
|
240
|
+
```
|
|
241
|
+
|
|
201
242
|
## Other Examples
|
|
202
243
|
|
|
203
244
|
There are a few other working examples that you can use as points of reference for creating a new app using Terra Draw.
|