Skip to content

Commit

Permalink
Fire loop and unloop events
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Sep 1, 2021
1 parent 9e04dc8 commit b6cfa95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ The event data is an object with the following shape:
}
```

#### MapboxPathControl.loop

Fired when a Loop is activated.
The event data is an object with the following shape:

```ts
{
featureCollection: GeoJSON.FeatureCollection<GeoJSON.Geometry>,
}
```

#### MapboxPathControl.unLoop

Fired when a Loop is deactivated.
The event data is an object with the following shape:

```ts
{
featureCollection: GeoJSON.FeatureCollection<GeoJSON.Geometry>,
}
```

## Run Locally

Clone the project
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,14 @@ export default class MapboxPathControl implements IControl {
);

this.referencePoints = this.referencePoints.slice(0, -1);

this.updateSource();

this.actionsPanel.remove();

this.map!.fire("MapboxPathControl.loop", {
featureCollection: this.getFeatureCollection(),
});
}

public async setOneWayTrail(): Promise<void> {
Expand All @@ -977,7 +982,12 @@ export default class MapboxPathControl implements IControl {
this.deletePoint();

this.updateSource();

this.actionsPanel.remove();

this.map!.fire("MapboxPathControl.unLoop", {
featureCollection: this.getFeatureCollection(),
});
}

private updateSource(fireEvent: boolean = true): void {
Expand Down

0 comments on commit b6cfa95

Please # to comment.