GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit 71e8deff authored by Iván Sánchez Ortega's avatar Iván Sánchez Ortega
Browse files

Add sliceCancel(), bump to 0.2.0

parent 363bee1d
Pipeline #4773962 passed with stage
......@@ -23,12 +23,14 @@ L.Marker.include({
this._slideKeepAtCenter = !!options.keepAtCenter;
this._slideDraggingWasAllowed =
this._slideDraggingWasAllowed !== undefined ?
this._slideDraggingWasAllowed :
this._map.dragging.enabled();
this._slideDraggingWasAllowed :
this._map.dragging.enabled();
if (this._slideKeepAtCenter) {
this._map.dragging.disable();
this._map.doubleClickZoom.disable();
this._map.options.touchZoom = 'center';
this._map.options.scrollWheelZoom = 'center';
}
this.fire('movestart');
......@@ -37,6 +39,12 @@ L.Marker.include({
return this;
},
// 🍂method slideCancel(): this
// Cancels the sliding animation from `slideTo`, if applicable.
slideCancel: function slideCancel() {
L.Util.cancelAnimFrame(this._slideFrame);
},
_slideTo: function _slideTo() {
if (!this._map) return;
......@@ -47,7 +55,9 @@ L.Marker.include({
this.fire('moveend');
if (this._slideDraggingWasAllowed ) {
this._map.dragging.enable();
this._map.doubleClickZoom.enable();
this._map.options.touchZoom = true;
this._map.options.scrollWheelZoom = true;
}
this._slideDraggingWasAllowed = undefined;
return this;
......@@ -67,11 +77,14 @@ L.Marker.include({
this._map.panTo(currLatLng, {animate: false})
}
L.Util.requestAnimFrame(this._slideTo, this);
this._slideFrame = L.Util.requestAnimFrame(this._slideTo, this);
}
});
L.Marker.addInitHook(function(){
this.on('move', this.slideCancel, this);
});
/*
🍂miniclass Slide options (Marker)
......@@ -93,5 +106,12 @@ L.CircleMarker.include({
// Moves this circle until `latlng`, like `setLatLng()`, but with a smooth
// sliding animation. Fires `movestart` and `moveend` events.
slideTo: L.Marker.prototype.slideTo,
// 🍂method slideCancel(): this
// Cancels the sliding animation from `slideTo`, if applicable.
slideCancel: L.Marker.prototype.slideCancel,
_slideTo: L.Marker.prototype._slideTo
});
L.CircleMarker.addInitHook(function(){
this.on('move', this.slideCancel, this);
});
......@@ -8,16 +8,17 @@ See the [demo](http://ivansanchez.gitlab.io/Leaflet.Marker.SlideTo/demo.html).
### API
This plugin adds a new method to all `L.Marker`s, `L.Circle`s and `L.CircleMarker`s: `.slideTo(latlng, slideOptions)`.
This plugin adds two new methods to all `L.Marker`s, `L.Circle`s and `L.CircleMarker`s:
* `.slideTo(latlng, slideOptions)`.
* `.slideCancel()`
This new method will start moving the marker (or circle) towards `latlng`, taking
The `slideTo` method will start moving the marker (or circle) towards `latlng`, taking
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]);
......@@ -28,16 +29,21 @@ marker.slideTo( [20, 20], {
```
The `slideCancel` method will stop the sliding animation (if applicable). Running
`setLatLng` or dragging the marker will also stop the animation.
### Installation through `npm`
```
npm install leaflet.marker.slideto
```
(Idem for `yarn add`)
### Usage through unpkg
```
<script src='https://unpkg.com/leaflet.marker.slideto@0.1.0/Leaflet.Marker.SlideTo.js'></script>
<script src='https://unpkg.com/leaflet.marker.slideto@0.2.0/Leaflet.Marker.SlideTo.js'></script>
```
### Legalese
......
{
"name": "leaflet.marker.slideto",
"version": "0.1.0",
"version": "0.2.0",
"description": "A plugin for LeafletJS to smoothly move (slide) markers to a new location.",
"main": "Leaflet.Marker.SlideTo.js",
"scripts": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment