Skip to content

Commit 0effabd

Browse files
committed
version 1.3.0
1 parent 9e8c39b commit 0effabd

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ yarn add leaflet-react-track-player
8383
| useControl | Bollean | false | Show or hide control panel |
8484
| streamData | Bollean | false | Update player after add new points |
8585
| showDots | Bollean | false | Show or hide points in progress line |
86+
| defaultSpeed | Number | undefined | Constant for speed (pixel/second) |
8687
| callbackFinish | Function | () => {} | Called after one full track run |
8788
| callbackNext | Function | () => {} | Called after next point in the polyline is reached |
8889
| callbackPrev | Function | () => {} | Called after previous point in the polyline is reached |

lib/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ var LeafletReactTrackPlayer = function (_MapLayer) {
318318
iconSize: [35, 35]
319319
});
320320
};
321-
var course = this.props.customMarker && this.props.customCourse && this.state.track[0] && this.state.track[0].course ? this.state.track[0].course : null;
321+
var course = this.props.customMarker && this.props.customCourse && this.props.track[0] && this.props.track[0].course ? this.props.track[0].course : null;
322322
var finishMarker = _leaflet2.default.marker(this.props.track[0], {
323323
icon: this.createIcon(course)
324324
});
@@ -327,7 +327,8 @@ var LeafletReactTrackPlayer = function (_MapLayer) {
327327
var snakePolyline = _leaflet2.default.multiColorsPolyline(this.props.track, _extends({}, paramsForMultiPolyline(this.props), {
328328
timeFormat: this.props.timeFormat,
329329
progressFormat: this.props.progressFormat,
330-
startPosition: this.props.startPosition
330+
startPosition: this.props.startPosition,
331+
defaultSpeed: this.props.defaultSpeed
331332
}));
332333
this.props.leaflet.map.addLayer(snakePolyline);
333334
return {
@@ -353,7 +354,7 @@ var LeafletReactTrackPlayer = function (_MapLayer) {
353354
if (fromProps.track.length !== toProps.track.length && this.state.activeStream) {
354355
this.setState({ active: true });
355356
var newPointsPolyline = this.props.progressFormat === "default" || this.props.progressFormat === "distance" ? _leaflet2.default.multiColorsPolyline(toProps.track.slice(fromProps.track.length - 1), paramsForMultiPolyline(this.props)) : _leaflet2.default.multiColorsPolyline(toProps.track.filter(function (item) {
356-
return Number(item.t) > Number(fromProps.track[fromProps.track.length - 1].t);
357+
return Number(item.t) >= Number(fromProps.track[fromProps.track.length - 1].t);
357358
}), paramsForMultiPolyline(this.props));
358359
var keys = Object.keys(newPointsPolyline._layers);
359360
var values = keys.reduce(function (result, item) {
@@ -545,6 +546,7 @@ LeafletReactTrackPlayer.propTypes = {
545546
startPosition: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]),
546547
streamData: _propTypes2.default.bool,
547548
showDots: _propTypes2.default.bool,
549+
defaultSpeed: _propTypes2.default.number,
548550
callbackNext: _propTypes2.default.func,
549551
callbackPrev: _propTypes2.default.func,
550552
callbackSpeed: _propTypes2.default.func,

lib/snake.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ _leaflet2.default.Polyline.include({
2626
// It initialization polyline with animation
2727
snakeIn: function snakeIn(e) {
2828
if (e && !this._latLngAnimation) this._latLngAnimation = e;
29+
for (var i in this._eventParents) {
30+
if (this._eventParents[i]._options.defaultSpeed) {
31+
this._defaultSpeed = this._eventParents[i]._options.defaultSpeed;
32+
}
33+
}
2934
if (this._snaking) {
3035
return;
3136
}
@@ -135,6 +140,9 @@ _leaflet2.default.Polyline.include({
135140
var time = this._timeDistance ? this._timeDistance / this._xSpeed : 1 / this._xSpeed;
136141
var diff = this._now - this._snakingTime;
137142
var forward = this.maxDistance ? diff * (this.maxDistance / time) / 1000 : diff * (1 / time) / 1000;
143+
if (this._defaultSpeed) {
144+
forward = diff * (this._defaultSpeed * this._xSpeed) / 1000;
145+
}
138146
this._snakingTime = this._now;
139147
this._latlngs.pop();
140148
this._forward = forward;
@@ -233,9 +241,16 @@ _leaflet2.default.LayerGroup.include({
233241
},
234242

235243
snakePlay: function snakePlay() {
244+
var findLast = this._snakingLayers.some(function (itm) {
245+
return itm._snaking;
246+
});
247+
var goPlay = null;
236248
this._snakingLayers.map(function (item) {
237249
if (item._map && item._snaking) item.snakePlay();
238250
});
251+
if (findLast) {
252+
if (goPlay) goPlay.snakePlay();
253+
} else this._snakeNext();
239254
},
240255
// change position. This function stopping work of animation and initiate polylines with default state. Need timestamp
241256
changePosition: function changePosition(value) {
@@ -390,6 +405,7 @@ _leaflet2.default.LayerGroup.include({
390405
this._detailDistance = this._detailData.map(function (polyline) {
391406
return (0, _index.getDistance)(polyline);
392407
});
408+
console.log(this);
393409
if (this._options.startPosition) {
394410
this._initiateStartPosition();
395411
} else {
@@ -400,16 +416,17 @@ _leaflet2.default.LayerGroup.include({
400416
_initiateStartPosition: function _initiateStartPosition() {
401417
if (this._options.startPosition === "full") {
402418
if (this._options.progressFormat === "default") {
403-
this.changePosition(this._originalLatlngs.length - 1);
419+
this.changePosition(this._originalLatlngs.length);
404420
} else if (this._options.progressFormat === "distance") {
405421
var max = this._detailDistance.reduce(function (result, item) {
406422
result = result + item;
407423
return result;
408424
}, 0);
409-
this.changePosition(max);
425+
this.changePosition(max + 1);
410426
} else if (this._options.progressFormat === "time") {
411-
this.changePosition(this._originalLatlngs[this._originalLatlngs.length - 1].t);
427+
this.changePosition(this._originalLatlngs[this._originalLatlngs.length - 1].t + 1);
412428
}
429+
this._snaking = false;
413430
this._end(true);
414431
} else {
415432
this.changePosition(this._options.startPosition);
@@ -418,7 +435,9 @@ _leaflet2.default.LayerGroup.include({
418435
},
419436

420437
_snakeNext: function _snakeNext() {
421-
console.log(this);
438+
if (!this._snaking && this._snakingLayersDone < this._snakingLayers.length) {
439+
this._snaking = true;
440+
}
422441
if (this._snakingLayersDone >= this._snakingLayers.length) {
423442
this._end(true);
424443
this._snaking = false;
@@ -447,6 +466,8 @@ _leaflet2.default.LayerGroup.include({
447466
});
448467
_this5._snakingLayers[prevRange + index].removePosition();
449468
});
450-
this.snakePlay();
469+
if (!this._snaking) {
470+
this.snakePlay();
471+
}
451472
}
452473
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "leaflet-react-track-player",
33
"description": "This is plugin to react-leaflet. It create player for control of track.",
4-
"version": "1.2.4",
4+
"version": "1.3.0",
55
"private": false,
66
"main": "lib/index.js",
77
"homepage": "https://github.com/argonavt11/leaflet-react-track-player",

0 commit comments

Comments
 (0)