@@ -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} ) ;
0 commit comments