# leaflet-temporal-geojson

> Animate GeoJSON features using an arbitrary time property

Latest version **0.4.0** (published 2020-08-19) · SEE LICENSE IN LICENCE license · 0 weekly downloads

## Install

```sh
npm install leaflet-temporal-geojson
pnpm add leaflet-temporal-geojson
yarn add leaflet-temporal-geojson
bun add leaflet-temporal-geojson
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2020-08-19 |
| First published | 2020-07-31 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENCE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 39 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | daniel.wild@csiro.au |
| Maintainers | danwild |
| Keywords | leaflet, visualization, visualisation, geojson, overlay |

## Links

- npm: https://www.npmjs.com/package/leaflet-temporal-geojson
- Repository: https://github.com/onaci/leaflet-temporal-geojson
- Homepage: https://github.com/onaci/leaflet-temporal-geojson#readme
- Issues: https://github.com/onaci/leaflet-temporal-geojson/issues
- npm.io page: https://npm.io/package/leaflet-temporal-geojson

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.4.0 (latest) — 2020-08-19
- 0.3.0 — 2020-08-18
- 0.2.0 — 2020-08-18
- 0.1.0 — 2020-08-04
- 0.0.2 — 2020-07-31
- 0.0.1 — 2020-07-31
- 0.0.0 — 2020-07-31

## README

# leaflet-temporal-geojson [![NPM version][npm-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url]

A somewhat unopinionated leaflet (v1+) plugin to animate GeoJSON features using an arbitrary time property:

- You decide how to change frames (event driven range slider components, methods calls, whatever 🤷‍♂️)
- You control feature styling (static, dynamic, whatever 🤷‍♀️)

![Screenshot](/screenshots/keyframes.gif?raw=true)

## how does it work

- features are clustered into layer 'keyframes' using supplied time property
- keyframes are rendered depending on time key
- features may have custom styles applied using properties

## notes
- to improve rendering performance, points are rendered as `L.circleMarker` vectors using L.geoJSON's `pointToLayer` function (i.e. to avoid use of DOM `<img>` for markers)

## install
```shell
npm install leaflet-temporal-geojson --save
```

## development
```shell
npm install 
npm run build
```

## use and options

See [demo](https://onaci.github.io/leaflet-temporal-geojson/) for detailed example.

```javascript
const layer = L.temporalGeoJSONLayer({

  // which property to use for time (expects ISO 8601 string)
  timeKey: "time",
  
  // optional function to return style 
  // see path options: https://leafletjs.com/reference-1.6.0.html#path-option
  style: function(feature) { 
    return {}; 
  },
  
  // array of geojson features
  features: [
    {
      "type": "Feature",
      "properties": {
        "age": 1,
        "time": "2005-08-22T09:01:00Z"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          156,
          -45
        ]
      }
    },
  ],

  // OPTIONAL - supply the name of a custom pane,
  // will be created if doesn't exist, defaults to overlayPane
  // https://leafletjs.com/reference-1.6.0.html#map-pane
  paneName: 'myCustomPane',

  // OPTIONAL - additional options to style point data (e.g. radius)
  // this has lower priority than styles from style()
  // https://leafletjs.com/reference-1.6.0.html#circlemarker
  circleMarkerOptions: {},

  // OPTIONAL - renderer factory
  // One of: L.canvas, L.svg (defaults to canvas)
  // Note: L.svg is not recommended due to performance overhead
  rendererFactory: L.canvas,

  // OPTIONAL - callbacks when layer is added/removed from map
  onAdd: function(){},
  onRemove: function(){},

  // OPTIONAL - function to control feature popups
  // https://leafletjs.com/reference-1.6.0.html#geojson
  popupFunction(layer) {
    return `the time here is: ${layer.feature.properties.time}`
  }

});
```

## public methods

|method|params|description|
|---|---|---|
|`getFrame`||Get the current frame time (-1 if not set)|
|`getFrameKeys`||Get an ascending array of all ISO times (can then be used to call `setFrame`)|
|`isActive`||check if the layer is currently active on the map|
|`setFrame`|`time: {string}`|display the features at the given ISO time (if calling from something like a range slider, recommended to throttle - see demo). 
|`setStyle`|`style: {function}`|Changes styles of GeoJSON vector layers with the given style function. Set falsey for defaults.|
|`getBounds`|`time {string}`|Get the bounds at given time (falls back to bounds of current keyframe, and then bounds of first keyframe if not set).|


## example data

The included example data is fictional and intended for demonstration purposes only, however - if you're interested in marine connectivity modelling you should check out some of CSIRO's work on connectivity modelling [here](https://connie.csiro.au), and [here](https://www.csiro.au/en/Research/OandA/Areas/Marine-resources-and-industries/Marine-biodiversity/CONNIE).

[npm-image]: https://badge.fury.io/js/leaflet-temporal-geojson.svg
[npm-url]: https://www.npmjs.com/package/leaflet-temporal-geojson
[npm-downloads-image]: https://img.shields.io/npm/dt/leaflet-temporal-geojson.svg

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