1.0.2 • Published 4 years ago

leaflet.timeline.control v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Leaflet Timeline Control

Examples

CodeSandbox

Installation

npm install "leaflet.timeline.control"

Import

import 'leaflet.timeline.control';

Control will be available as L.control.timeline.

Configuration

Here's the overview of the available control options (all of the standard L.Control options are accepted as well):

OptionTypeDefault
autoplaybooleanfalse
button{ pausedText: string, playingText: string, render: () => HTMLElement }undefined
timeline{ dateFormat: string, renderSlot: () => HTMLElement, renderActiveSlot: () => HTMLElement, range: Date[], step: Luxon.DurationObjectUnits }undefined
intervalnumberundefined
onNextStep(current: Date) => voidundefined

Plugin is written in TypeScript, here's the interface used to configure the control.

export type Tuple<T> = [T, T];
export type ArrayOfThreeOrMore<T> = [T, T, T, ...T[]];
export type HTMLElementOrNull = HTMLElement | void;

type Range = {
  range: Tuple<Date>;
  step: DurationObjectUnits;
} | {
  range: ArrayOfThreeOrMore<Date>;
};

interface TimelineOptions extends L.ControlOptions {
    autoplay?: boolean;
    button?: {
      pausedText?: string;
      playingText?: string;
      render?: () => HTMLElementOrNull;
    };
    timeline: {
      dateFormat: string;
      renderSlot?: () => HTMLElement;
      renderActiveSlot?: () => HTMLElement;
    } & Range;
    interval: number;
    onNextStep: (current: Date) => void;
}

Usage

const map = L.map('map', {
    center: [50, 19],
    zoom: 15,
});

const timelineControl = L.control.timeline({
    autoplay: false,
    position: 'bottomleft',
    onNextStep: (cur) => console.log(cur),
    interval: 1000,
    button: {
        pausedText: 'Play',
        playingText: 'Pause',
    },
    timeline: {
        dateFormat: 'yyyy-MM-dd',
        renderSlot: () => document.createElement('h5'),
        renderActiveSlot: () => document.createElement('h1'),
        range: [new Date('2020-09-01'), new Date('2020-09-10')],
        step: {
            day: 1,
        },
    },
});

CI

1.0.2

4 years ago

1.0.1

4 years ago