Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Draw API #23

Merged
merged 12 commits into from
Jan 31, 2025
5 changes: 5 additions & 0 deletions .changeset/few-cats-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@feltmaps/js-sdk": minor
---

Adds APIs to use Felt's drawing tools on read-only maps
147 changes: 146 additions & 1 deletion docs/Main/FeltController.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ own to make it easier to find related methods and events.

## Extends

* [`ViewportController`](../Viewport/ViewportController.md).[`UiController`](../UI/UiController.md).[`LayersController`](../Layers/LayersController.md).[`ElementsController`](../Elements/ElementsController.md).[`SelectionController`](../Selection/SelectionController.md).[`InteractionsController`](../Interactions/InteractionsController.md)
* [`ViewportController`](../Viewport/ViewportController.md).[`UiController`](../UI/UiController.md).[`LayersController`](../Layers/LayersController.md).[`ElementsController`](../Elements/ElementsController.md).[`SelectionController`](../Selection/SelectionController.md).[`InteractionsController`](../Interactions/InteractionsController.md).[`ToolsController`](../Tools/ToolsController.md)

## Properties

Expand Down Expand Up @@ -696,6 +696,151 @@ felt.clearSelection({ elements: true });

***

### setTool()

> **setTool**(`tool`: `null` | `"note"` | `"pin"` | `"line"` | `"route"` | `"polygon"` | `"circle"` | `"marker"` | `"highlighter"` | `"text"` | `"link"`): `void`

Sets the tool to use for drawing elements on the map.

#### Parameters

| Parameter | Type | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| `tool` | `null` \| `"note"` \| `"pin"` \| `"line"` \| `"route"` \| `"polygon"` \| `"circle"` \| `"marker"` \| `"highlighter"` \| `"text"` \| `"link"` | The tool to set. |

#### Returns

`void`

#### Example

```ts
// Set the tool to "marker"
felt.setTool("marker");

// put down the tool
felt.setTool(null);
```

***

### getTool()

> **getTool**(): `Promise`\<`null` | `"note"` | `"pin"` | `"line"` | `"route"` | `"polygon"` | `"circle"` | `"marker"` | `"highlighter"` | `"text"` | `"link"`>

Gets the current tool, if any is in use.

#### Returns

`Promise`\<`null` | `"note"` | `"pin"` | `"line"` | `"route"` | `"polygon"` | `"circle"` | `"marker"` | `"highlighter"` | `"text"` | `"link"`>

The current tool, or `null` if no tool is in use.

#### Example

```ts
const tool = await felt.getTool(); // "marker", "polygon", etc.
```

***

### onToolChange()

> **onToolChange**(`args`: \{ `handler`: (`tool`: `null` | `"note"` | `"pin"` | `"line"` | `"route"` | `"polygon"` | `"circle"` | `"marker"` | `"highlighter"` | `"text"` | `"link"`) => `void`; }): `VoidFunction`

Listens for changes to the current tool.

#### Parameters

| Parameter | Type | Description |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `args` | \{ `handler`: (`tool`: `null` \| `"note"` \| `"pin"` \| `"line"` \| `"route"` \| `"polygon"` \| `"circle"` \| `"marker"` \| `"highlighter"` \| `"text"` \| `"link"`) => `void`; } | - |
| `args.handler` | (`tool`: `null` \| `"note"` \| `"pin"` \| `"line"` \| `"route"` \| `"polygon"` \| `"circle"` \| `"marker"` \| `"highlighter"` \| `"text"` \| `"link"`) => `void` | This callback is called with the current tool whenever the tool changes. |

#### Returns

`VoidFunction`

A function to unsubscribe from the listener

#### Example

```ts
const unsubscribe = felt.onToolChange({
handler: tool => console.log(tool),
});

// later on...
unsubscribe();
```

***

### setToolSettings()

> **setToolSettings**(`settings`: [`InputToolSettings`](../Tools/InputToolSettings.md)): `void`

Sets the settings for the current tool.

#### Parameters

| Parameter | Type | Description |
| ---------- | ---------------------------------------------------- | -------------------- |
| `settings` | [`InputToolSettings`](../Tools/InputToolSettings.md) | The settings to set. |

#### Returns

`void`

***

### getToolSettings()

> **getToolSettings**\<`T`>(`tool`: `T`): `Promise`\<[`ToolSettingsMap`](../Tools/ToolSettingsMap.md)\[`T`]>

Gets the settings for the current tool.

#### Type Parameters

| Type Parameter |
| -------------------------------------------------------------------- |
| `T` *extends* keyof [`ToolSettingsMap`](../Tools/ToolSettingsMap.md) |

#### Parameters

| Parameter | Type |
| --------- | ---- |
| `tool` | `T` |

#### Returns

`Promise`\<[`ToolSettingsMap`](../Tools/ToolSettingsMap.md)\[`T`]>

The settings for the current tool.

***

### onToolSettingsChange()

> **onToolSettingsChange**(`args`: \{ `handler`: (`settings`: [`ToolSettingsChangeEvent`](../Tools/ToolSettingsChangeEvent.md)) => `void`; }): `VoidFunction`

Listens for changes to the settings on all tools.

#### Parameters

| Parameter | Type |
| -------------- | --------------------------------------------------------------------------------------------------------- |
| `args` | \{ `handler`: (`settings`: [`ToolSettingsChangeEvent`](../Tools/ToolSettingsChangeEvent.md)) => `void`; } |
| `args.handler` | (`settings`: [`ToolSettingsChangeEvent`](../Tools/ToolSettingsChangeEvent.md)) => `void` |

#### Returns

`VoidFunction`

A function to unsubscribe from the listener

***

### updateUiControls()

> **updateUiControls**(`controls`: [`UiControlsOptions`](../UI/UiControlsOptions.md)): `void`
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
* [Main](Main/README.md)
* [Selection](Selection/README.md)
* [Shared](Shared/README.md)
* [Tools](Tools/README.md)
* [UI](UI/README.md)
* [Viewport](Viewport/README.md)
37 changes: 37 additions & 0 deletions docs/Tools/CircleToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
***

## Properties

### color

> **color**: `string`

***

### fillOpacity

> **fillOpacity**: `number`

***

### strokeOpacity

> **strokeOpacity**: `number`

***

### strokeWidth

> **strokeWidth**: `number`

***

### strokeStyle

> **strokeStyle**: `"solid"` | `"dashed"` | `"dotted"`

***

### radiusMarker

> **radiusMarker**: `boolean`
3 changes: 3 additions & 0 deletions docs/Tools/ConfigurableToolType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
***

> **ConfigurableToolType**: keyof [`ToolSettingsMap`](ToolSettingsMap.md)
19 changes: 19 additions & 0 deletions docs/Tools/HighlighterToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
***

## Properties

### color

> **color**: `string`

***

### opacity

> **opacity**: `number`

***

### size

> **size**: `number`
3 changes: 3 additions & 0 deletions docs/Tools/InputToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
***

> **InputToolSettings**: `{ [K in ConfigurableToolType]: Partial<ToolSettingsMap[K]> & { tool: K } }`\[[`ConfigurableToolType`](ConfigurableToolType.md)]
31 changes: 31 additions & 0 deletions docs/Tools/LineToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
***

## Properties

### color

> **color**: `string`

***

### strokeOpacity

> **strokeOpacity**: `number`

***

### strokeWidth

> **strokeWidth**: `number`

***

### strokeStyle

> **strokeStyle**: `"solid"` | `"dashed"` | `"dotted"`

***

### distanceMarker

> **distanceMarker**: `boolean`
19 changes: 19 additions & 0 deletions docs/Tools/MarkerToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
***

## Properties

### color

> **color**: `string`

***

### opacity

> **opacity**: `number`

***

### size

> **size**: `number`
19 changes: 19 additions & 0 deletions docs/Tools/NoteToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
***

## Properties

### color

> **color**: `string`

***

### align

> **align**: `"left"` | `"center"` | `"right"`

***

### style

> **style**: `"italic"` | `"light"` | `"regular"` | `"caps"`
3 changes: 3 additions & 0 deletions docs/Tools/PinFrame.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
***

> **PinFrame**: `"frame-circle"` | `"frame-square"` | `null`
3 changes: 3 additions & 0 deletions docs/Tools/PinSymbol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
***

> **PinSymbol**: `"dot"` | `"square"` | `"diamond"` | `"triangle"` | `"x"` | `"plus"` | `"circle-line"` | `"circle-slash"` | `"star"` | `"heart"` | `"hexagon"` | `"octagon"` | `"pedestrian"` | `"bicycle"` | `"wheelchair"` | `"airport"` | `"car"` | `"bus"` | `"train"` | `"truck"` | `"ferry"` | `"sailboat"` | `"electric-service"` | `"gas-service"` | `"blood-clinic"` | `"badge"` | `"traffic-light"` | `"traffic-cone"` | `"road-sign-caution"` | `"person"` | `"restroom"` | `"house"` | `"work"` | `"letter"` | `"hotel"` | `"factory"` | `"hospital"` | `"religious-facility"` | `"school"` | `"government"` | `"university"` | `"bank"` | `"landmark"` | `"museum"` | `"clothing"` | `"shopping"` | `"store"` | `"bar"` | `"pub"` | `"cafe"` | `"food"` | `"park"` | `"amusement-park"` | `"camping-tent"` | `"cabin"` | `"picnic"` | `"water-refill"` | `"trailhead"` | `"guidepost"` | `"viewpoint"` | `"camera"` | `"us-football"` | `"football"` | `"tennis"` | `"binoculars"` | `"swimming"` | `"zap"` | `"battery-full"` | `"battery-half"` | `"battery-low"` | `"boom"` | `"radar"` | `"wind-turbine"` | `"solar-panel"` | `"antenna"` | `"telephone-pole"` | `"oil-well"` | `"oil-barrel"` | `"railroad-track"` | `"bridge"` | `"lighthouse"` | `"lock-closed"` | `"lock-open"` | `"wifi"` | `"trash"` | `"recycle"` | `"tree"` | `"flower"` | `"leaf"` | `"fire"` | `"mountain"` | `"snowy-mountain"` | `"volcano"` | `"island"` | `"wave"` | `"hot-springs"` | `"water"` | `"lake"` | `"ocean"` | `"animal"` | `"bird"` | `"duck"` | `"dog"` | `"fish"` | `"beach"` | `"wetland"` | `"sun"` | `"moon"` | `"cloud"` | `"partial-sun"` | `"rain"` | `"lightning"` | `"snowflake"` | `"wind"` | `"snow"` | `"fog"` | `"sleet"` | `"hurricane"` | `"warning"` | `"parking"` | `"info"` | `"circle-exclamation"` | `"circle-triangle"` | `"circle-x"` | `"circle-plus"` | `` `:${string}:` `` & \{}
19 changes: 19 additions & 0 deletions docs/Tools/PinToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
***

## Properties

### color

> **color**: `string`

***

### frame

> **frame**: `null` | `"frame-circle"` | `"frame-square"`

***

### symbol

> **symbol**: [`PinSymbol`](PinSymbol.md)
37 changes: 37 additions & 0 deletions docs/Tools/PolygonToolSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
***

## Properties

### color

> **color**: `string`

***

### fillOpacity

> **fillOpacity**: `number`

***

### strokeOpacity

> **strokeOpacity**: `number`

***

### strokeWidth

> **strokeWidth**: `number`

***

### strokeStyle

> **strokeStyle**: `"solid"` | `"dashed"` | `"dotted"`

***

### areaMarker

> **areaMarker**: `boolean`
Loading