@@ -26,6 +26,11 @@ _leaflet2.default.Polyline.include({
26
26
// It initialization polyline with animation
27
27
snakeIn : function snakeIn ( e ) {
28
28
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
+ }
29
34
if ( this . _snaking ) {
30
35
return ;
31
36
}
@@ -135,6 +140,9 @@ _leaflet2.default.Polyline.include({
135
140
var time = this . _timeDistance ? this . _timeDistance / this . _xSpeed : 1 / this . _xSpeed ;
136
141
var diff = this . _now - this . _snakingTime ;
137
142
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
+ }
138
146
this . _snakingTime = this . _now ;
139
147
this . _latlngs . pop ( ) ;
140
148
this . _forward = forward ;
@@ -233,9 +241,16 @@ _leaflet2.default.LayerGroup.include({
233
241
} ,
234
242
235
243
snakePlay : function snakePlay ( ) {
244
+ var findLast = this . _snakingLayers . some ( function ( itm ) {
245
+ return itm . _snaking ;
246
+ } ) ;
247
+ var goPlay = null ;
236
248
this . _snakingLayers . map ( function ( item ) {
237
249
if ( item . _map && item . _snaking ) item . snakePlay ( ) ;
238
250
} ) ;
251
+ if ( findLast ) {
252
+ if ( goPlay ) goPlay . snakePlay ( ) ;
253
+ } else this . _snakeNext ( ) ;
239
254
} ,
240
255
// change position. This function stopping work of animation and initiate polylines with default state. Need timestamp
241
256
changePosition : function changePosition ( value ) {
@@ -390,6 +405,7 @@ _leaflet2.default.LayerGroup.include({
390
405
this . _detailDistance = this . _detailData . map ( function ( polyline ) {
391
406
return ( 0 , _index . getDistance ) ( polyline ) ;
392
407
} ) ;
408
+ console . log ( this ) ;
393
409
if ( this . _options . startPosition ) {
394
410
this . _initiateStartPosition ( ) ;
395
411
} else {
@@ -400,16 +416,17 @@ _leaflet2.default.LayerGroup.include({
400
416
_initiateStartPosition : function _initiateStartPosition ( ) {
401
417
if ( this . _options . startPosition === "full" ) {
402
418
if ( this . _options . progressFormat === "default" ) {
403
- this . changePosition ( this . _originalLatlngs . length - 1 ) ;
419
+ this . changePosition ( this . _originalLatlngs . length ) ;
404
420
} else if ( this . _options . progressFormat === "distance" ) {
405
421
var max = this . _detailDistance . reduce ( function ( result , item ) {
406
422
result = result + item ;
407
423
return result ;
408
424
} , 0 ) ;
409
- this . changePosition ( max ) ;
425
+ this . changePosition ( max + 1 ) ;
410
426
} 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 ) ;
412
428
}
429
+ this . _snaking = false ;
413
430
this . _end ( true ) ;
414
431
} else {
415
432
this . changePosition ( this . _options . startPosition ) ;
@@ -418,7 +435,9 @@ _leaflet2.default.LayerGroup.include({
418
435
} ,
419
436
420
437
_snakeNext : function _snakeNext ( ) {
421
- console . log ( this ) ;
438
+ if ( ! this . _snaking && this . _snakingLayersDone < this . _snakingLayers . length ) {
439
+ this . _snaking = true ;
440
+ }
422
441
if ( this . _snakingLayersDone >= this . _snakingLayers . length ) {
423
442
this . _end ( true ) ;
424
443
this . _snaking = false ;
@@ -447,6 +466,8 @@ _leaflet2.default.LayerGroup.include({
447
466
} ) ;
448
467
_this5 . _snakingLayers [ prevRange + index ] . removePosition ( ) ;
449
468
} ) ;
450
- this . snakePlay ( ) ;
469
+ if ( ! this . _snaking ) {
470
+ this . snakePlay ( ) ;
471
+ }
451
472
}
452
473
} ) ;
0 commit comments