Skip to content

Commit

Permalink
docs(terra-draw): add details to the STORE guide about valid geometry…
Browse files Browse the repository at this point in the history
… types for addFeatures (#426)
  • Loading branch information
JamesLMilner authored Jan 19, 2025
1 parent 5ec8e39 commit cdcb3aa
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions guides/2.STORE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ The data contained with the store is exposed via the `getSnapshot` method, which
const features = draw.getSnapshot();
```

> [!TIP]
> The `getSnapshot` method returns a deep copy of the Store, so you can safely mutate the returned array without affecting the Store.
We can then filter through this array to get the features we're looking for, as an example only returning `TerraDrawPolygonMode` features:

```javascript
Expand All @@ -56,10 +59,14 @@ features.filter((feature) => feature.properties.mode === 'polygon')

Features are added to the Store when interacting with the Map using a number of available drawing Modes (such as `TerraDrawRectangleMode` or `TerraDrawPolygonMode`).

> [!TIP]
> The `getSnapshot` method returns a deep copy of the Store, so you can safely mutate the returned array without affecting the Store.

Features can also be added to the Store programmatically using the `addFeatures` method:
Features can also be added to the Store programmatically using the `addFeatures` method. The method takes a valid array of Point, LineString and/or Polygon features which have a mode that is enabled in the current Terra Draw instance and adds them to that mode. It returns an array of success/failures with any reasons for given failures.

> [!IMPORTANT]
> The addFeatures method only accepts features of type Point, LineString and Polygon. Multi feature types like MultiPolygon, MultiLineString and MultiPoint are not supported. You can break down these multi features programmatically and add them individually if required.

Here is an example of how to use addFeatures:

```javascript
// Add a Point to the Store
Expand All @@ -85,7 +92,7 @@ console.log(result)
// }]
```

`addFeatures` returns an array of objects providing information about the added features such as the id and the feature was valid. Only valid features are added to the store. This allows developers to handle failure cases how they see fit:
As mentioned above, `addFeatures` returns an array of objects providing information about the added features such as the id and the feature was valid. Only valid features are added to the store. This allows developers to handle failure cases how they see fit:

```typescript
// Create a list of features that did not pass validation
Expand Down

0 comments on commit cdcb3aa

Please sign in to comment.