# leaflet-drift-marker

> Leaflet plugin for animated markers that move smoothly to a new position. Ideal for live GPS and vehicle tracking. TypeScript, with ESM, CommonJS and CDN builds.

Latest version **2.1.0** (published 2026-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install leaflet-drift-marker
pnpm add leaflet-drift-marker
yarn add leaflet-drift-marker
bun add leaflet-drift-marker
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-11-27 |
| First published | 2019-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Hugo Barragon |
| Maintainers | hugobarragon |
| Keywords | leaflet, leaflet-plugin, leaflet-marker, marker, animated-marker, moving-marker, sliding-marker, marker-animation, slideto, animation, map, gps, tracking, real-time, vehicle-tracking, typescript |

## Links

- npm: https://www.npmjs.com/package/leaflet-drift-marker
- Repository: https://github.com/hugobarragon/leaflet-drift-marker
- Homepage: https://github.com/hugobarragon/leaflet-drift-marker#readme
- Issues: https://github.com/hugobarragon/leaflet-drift-marker/issues
- npm.io page: https://npm.io/package/leaflet-drift-marker

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2026-11-27
- 3.0.0-beta.1 (next) — 2026-11-27
- 3.0.0-beta.0 — 2026-11-27
- 2.0.0 — 2021-04-02
- 2.0.0-next.0 — 2021-04-02
- 1.0.3 — 2019-08-20
- 1.0.2 — 2019-08-20
- 1.0.1 — 2019-08-20
- 1.0.0 — 2019-08-19

## README

# leaflet-drift-marker

[![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![npm version](https://img.shields.io/npm/v/leaflet-drift-marker.svg)](https://www.npmjs.com/package/leaflet-drift-marker)
[![CI](https://github.com/hugobarragon/leaflet-drift-marker/actions/workflows/ci.yml/badge.svg)](https://github.com/hugobarragon/leaflet-drift-marker/actions/workflows/ci.yml)

![DriftMarker example](./docs/driftmarker.gif "example")

**[Live demo](https://hugobarragon.github.io/leaflet-drift-marker/)**

A Leaflet marker that moves smoothly to a new position instead of jumping. Written in TypeScript and framework-agnostic, so it works with plain Leaflet, Vue, Angular and others. Ported from [Leaflet.Marker.SlideTo](https://gitlab.com/IvanSanchez/Leaflet.Marker.SlideTo).

Using React? See [react-leaflet-drift-marker](https://github.com/hugobarragon/react-leaflet-drift-marker).

Works with Leaflet 1.x and is tested with Leaflet 1.9. For many markers, use Leaflet's canvas renderer for better performance.

## Installation

```bash
npm install leaflet-drift-marker leaflet
```

`leaflet` is a [peer dependency](https://docs.npmjs.com/cli/configuring-npm/package-json#peerdependencies).

## Usage

### With a bundler

```javascript
import DriftMarker from "leaflet-drift-marker";
// CommonJS: const { DriftMarker } = require("leaflet-drift-marker");

const marker = new DriftMarker([10, 10]).addTo(map);

marker.slideTo([20, 20], {
  duration: 2000,
  keepAtCenter: true,
});
```

### With a `<script>` tag

Load Leaflet first; the script reads the global `L` and sets `window.DriftMarker`.

```html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-drift-marker@2.1.0/lib/index.js"></script>

<div id="map" style="height: 400px"></div>
<script>
  const map = L.map("map").setView([0, 0], 4);
  L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
    attribution: "&copy; OpenStreetMap contributors",
  }).addTo(map);

  const marker = new DriftMarker([0, 0]).addTo(map);
  marker.slideTo([10, 10], { duration: 1000 });
</script>
```

[![Edit leaflet_DriftMarker](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/static-bcdhq?fontsize=14)

### With ES modules in the browser

Use a module script and an import map so `leaflet` resolves to Leaflet's ESM build (Leaflet 1.9).

```html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script type="importmap">
  {
    "imports": {
      "leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
      "leaflet-drift-marker": "https://unpkg.com/leaflet-drift-marker@2.1.0/lib/index.mjs"
    }
  }
</script>

<div id="map" style="height: 400px"></div>
<script type="module">
  import * as L from "leaflet";
  import DriftMarker from "leaflet-drift-marker";

  const map = L.map("map").setView([0, 0], 4);
  L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
    attribution: "&copy; OpenStreetMap contributors",
  }).addTo(map);

  const marker = new DriftMarker([0, 0]).addTo(map);
  marker.slideTo([10, 10], { duration: 1000 });
</script>
```

## API

`DriftMarker` accepts everything [`L.Marker`](https://leafletjs.com/reference.html#marker) does, and adds:

- `.slideTo(latlng, options)`: animates the marker to `latlng`. Fires `movestart` and `moveend`.
  - `options.duration` (number, required): animation length in ms.
  - `options.keepAtCenter` (boolean, optional): pans the map with the marker and locks dragging and zoom-to-point until the slide ends.
- `.slideCancel()`: stops the current slide and restores map interaction.

Calling `setLatLng` or removing the marker during a slide cancels the slide. A `duration` of 0 moves the marker straight to the target.

## Contributing

See [AGENTS.md](./AGENTS.md) for layout, commands and conventions.

## License

MIT

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