README.md 1.57 KB
Newer Older
Iván Sánchez Ortega's avatar
Iván Sánchez Ortega committed
1
2
3
4
5
6
# Leaflet.Marker.SlideTo

A plugin for [LeafletJS](http://www.leafletjs.com) to smoothly move (slide) markers to a new location.

Tested with Leaflet 1.0.0-rc3. Do not expect this to work in Leaflet 0.7.x.

Iván Sánchez Ortega's avatar
Iván Sánchez Ortega committed
7
See the [demo](http://ivansanchez.gitlab.io/Leaflet.Marker.SlideTo/demo.html).
Iván Sánchez Ortega's avatar
Iván Sánchez Ortega committed
8
9
10

### API

11
12
13
This plugin adds two new methods to all `L.Marker`s, `L.Circle`s and `L.CircleMarker`s:
* `.slideTo(latlng, slideOptions)`.
* `.slideCancel()`
Iván Sánchez Ortega's avatar
Iván Sánchez Ortega committed
14

15
The `slideTo` method will start moving the marker (or circle) towards `latlng`, taking
Iván Sánchez Ortega's avatar
Iván Sánchez Ortega committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
some time to do so, using a linear animation.

Two options are available:
* `duration` is the number of milliseconds the slide animation will last.
* `keepAtCenter` is a boolean, whether the map center will follow the marker for the duration of the animation. If set to true, the map's dragging handler will be disabled momentarily.

```
var marker = L.marker([10,10]);

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

```

32
33
34
The `slideCancel` method will stop the sliding animation (if applicable). Running
`setLatLng` or dragging the marker will also stop the animation.

35
36
37
38
39
40
### Installation through `npm`

```
npm install leaflet.marker.slideto
```

41
42
(Idem for `yarn add`)

43
44
45
### Usage through unpkg

```
46
<script src='https://unpkg.com/leaflet.marker.slideto@0.2.0/Leaflet.Marker.SlideTo.js'></script>
47
```
Iván Sánchez Ortega's avatar
Iván Sánchez Ortega committed
48
49
50
51
52
53
54
55
56
57

### Legalese


"THE BEER-WARE LICENSE":
<ivan@sanchezortega.es> wrote this file. As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy me a beer in return.