# ht-leaflet-utils

> Leaflet utils

Latest version **0.1.1** (published 2017-03-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ht-leaflet-utils
pnpm add ht-leaflet-utils
yarn add ht-leaflet-utils
bun add ht-leaflet-utils
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-03-14 |
| First published | 2017-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | gaurav mukherjee |
| Maintainers | gaurav.mk |
| Keywords | leaflet, typescript, library, map, hypertrack |

## Links

- npm: https://www.npmjs.com/package/ht-leaflet-utils
- Repository: https://github.com/hypertrack/leaflet-utils
- Homepage: https://github.com/hypertrack/leaflet-utils#readme
- Issues: https://github.com/hypertrack/leaflet-utils/issues
- npm.io page: https://npm.io/package/ht-leaflet-utils

## Dependencies (2)

- [underscore](https://npm.io/package/underscore.md) ^1.8.3
- [time-aware-polyline](https://npm.io/package/time-aware-polyline.md) ^0.1.18

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2017-03-14
- 0.1.0 — 2017-03-14

## README

# leaflet-utils
This library exposes `ht` as a global variable. 

### Replay
ht object exposes a class `replay`, which can be instantiated with encoded timeAwarePolyline and a callbackback function which is called on every replay tick.

```
var ht = require('ht-leaflet-utils');
var encodePolyline = "cdmsBcus{LqsjhwwAsJoEg@rAn@A??Ah@VA??AnEpBA??]?JECp@EADE??W??O??U??I??]??Q??W??O??U??I??]??kf@"
var replay = ht.replay(encodedPolyline, function(head) {
 console.log(head) 
 /*
   { timePercent: 0,
   currentTime: '2017-03-10T07:36:05.440Z',
   currentPosition: [ 19.07813, 72.85101 ],
   bearing: -152.62 }
   */
})
```

#### Interfaces

1. Path segment: `TimeAwareArray` results after decoding `timeAwarePolyline`
2. Replay Head: Used for rendering replay marker on the map. Returned by the callback function after every replay tick.
3. Replay stats: Provides useful stats for the trip, like duration, start, end.

````
interface IPathSegment {
    path: number[][],
    bearing: number
}

type ITimeAwarePoint = [number, number, string];

interface IReplayHead {
    timePercent: number,
    currentTime: string,
    currentPosition: number[],
    bearing: number
}

interface IReplayStats {
    start: string,
    end: string,
    duration: number,
    distance?: number
}
````

#### API
1. Replay
````
replay.play()
````
Starts replay from current `IReplayHead`.
2. Pause

````
replay.pause()
````
Pauses replay at the current head
3. Stop
````
replay.stop()
````
Resets head to start of the trip. Also fires a tick event.
4. Go to timepercent
````
replay.gotToTimePercent(timepercent: number)
````
Pauses replay and fires a tick event with head at given time percent of the trip. 0 indicating start, 100 indicating end of the trip.
5. Get Timeline Array
````
var timelineArray = replay.getTimelineArray()
timelineArray[0] // lat
timelineArray[1] // lng
timelineArray[2] // timestamp as ISO string
````
Returns array of of `ITimeAwarePoint`. 
6. Set Callback
````
replay.setCallback(function(head) { console.log(head) })
````
Sets and updates tick callback function.
7. Update Polyline
````
var encodedTimeAwarePolyline = "cdmsBcus{LqsjhwwAsJoEg@rAn@A??Ah@VA??AnEpBA??]?JECp@EADE??W??O??U??I??]??Q??W??O??U??I??]??kf@";
replay.update(encodedTimeAwarePolyline)
````
Updates timeline of the trip. Useful for live trips, as this retails the timepercent of the replay and the heads current position remains unchanged with update.
8. Get Head
````
var head = replay.getFead()
````
Returns `IReplayHead` of the replay.
9. Get Stats
````
var stats = replay.getStats()
````
Returns `IReplayStats` of the trip.

---
_Source: https://npm.io/package/ht-leaflet-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
