@@ -8,6 +8,8 @@ var _moment = require("moment");
88
99var _moment2 = _interopRequireDefault ( _moment ) ;
1010
11+ var _index = require ( "./index" ) ;
12+
1113function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
1214
1315_leaflet2 . default . Polyline . include ( {
@@ -69,7 +71,7 @@ _leaflet2.default.Polyline.include({
6971 if ( ! this . _snakeLatLngs ) this . _snakeLatLngs = this . _latlngs ;
7072 if ( this . _snakeLatLngs . length === params . points . length ) {
7173 this . setLatLngs ( this . _snakeLatLngs ) ;
72- this . _snaking = false ;
74+ if ( ! params . last ) this . _snaking = false ;
7375 } else {
7476 if ( params . points . length !== 1 ) {
7577 this . setLatLngs ( params . points ) ;
@@ -83,8 +85,11 @@ _leaflet2.default.Polyline.include({
8385 // delete LatLngs, but not remove polyline.
8486 removePosition : function removePosition ( ) {
8587 this . _play = false ;
88+ this . _now = 0 ;
89+ this . _forward = 0 ;
8690 this . _snakingTime = 0 ;
8791 this . _snakingDistance = 0 ;
92+ this . _snakingVertices = 0 ;
8893 this . _snaking = false ;
8994 this . _path . style . display = "none" ;
9095 this . setLatLngs ( [ this . _snakeLatLngs [ 0 ] , this . _snakeLatLngs [ 0 ] ] ) ;
@@ -327,7 +332,7 @@ _leaflet2.default.LayerGroup.include({
327332 } ,
328333
329334 // Is is progress for mode progressFormat === "distance"
330- procentProgress : function procentProgress ( e , point , progress ) {
335+ _procentProgress : function _procentProgress ( e , point , progress ) {
331336 var _this4 = this ;
332337
333338 if ( progress ) {
@@ -368,7 +373,7 @@ _leaflet2.default.LayerGroup.include({
368373 var self = this ;
369374 this . _latLngAnimation = function ( point , progress ) {
370375 if ( self . _options . progressFormat === "distance" ) {
371- self . procentProgress ( events . fly , point , progress ) ;
376+ self . _procentProgress ( events . fly , point , progress ) ;
372377 } else events . fly ( point ) ;
373378 } ;
374379 }
@@ -383,17 +388,37 @@ _leaflet2.default.LayerGroup.include({
383388 }
384389 this . clearLayers ( ) ;
385390 this . _detailDistance = this . _detailData . map ( function ( polyline ) {
386- return polyline . reduce ( function ( result , point , index ) {
387- if ( polyline [ index + 1 ] ) {
388- result = result + _leaflet2 . default . latLng ( point ) . distanceTo ( polyline [ index + 1 ] ) ;
389- }
390- return result ;
391- } , 0 ) ;
391+ return ( 0 , _index . getDistance ) ( polyline ) ;
392392 } ) ;
393- return this . _snakeNext ( ) ;
393+ if ( this . _options . startPosition ) {
394+ this . _initiateStartPosition ( ) ;
395+ } else {
396+ return this . _snakeNext ( ) ;
397+ }
398+ } ,
399+
400+ _initiateStartPosition : function _initiateStartPosition ( ) {
401+ if ( this . _options . startPosition === "full" ) {
402+ if ( this . _options . progressFormat === "default" ) {
403+ this . changePosition ( this . _originalLatlngs . length - 1 ) ;
404+ } else if ( this . _options . progressFormat === "distance" ) {
405+ var max = this . _detailDistance . reduce ( function ( result , item ) {
406+ result = result + item ;
407+ return result ;
408+ } , 0 ) ;
409+ this . changePosition ( max ) ;
410+ } else if ( this . _options . progressFormat === "time" ) {
411+ this . changePosition ( this . _originalLatlngs [ this . _originalLatlngs . length - 1 ] . t ) ;
412+ }
413+ this . _end ( true ) ;
414+ } else {
415+ this . changePosition ( this . _options . startPosition ) ;
416+ this . snakePlay ( ) ;
417+ }
394418 } ,
395419
396420 _snakeNext : function _snakeNext ( ) {
421+ console . log ( this ) ;
397422 if ( this . _snakingLayersDone >= this . _snakingLayers . length ) {
398423 this . _end ( true ) ;
399424 this . _snaking = false ;
@@ -405,5 +430,23 @@ _leaflet2.default.LayerGroup.include({
405430 this . addLayer ( currentLayer ) ;
406431 currentLayer . snakeIn ( this . _latLngAnimation ) ;
407432 } else currentLayer . snakePlay ( ) ;
433+ } ,
434+
435+ addPolyline : function addPolyline ( layers , detail ) {
436+ var _this5 = this ;
437+
438+ var prevRange = this . _snakingLayers . length ;
439+ layers . map ( function ( item , index ) {
440+ _this5 . addLayer ( item ) ;
441+ _this5 . _detailData . push ( detail [ index ] ) ;
442+ _this5 . _detailDistance . push ( ( 0 , _index . getDistance ) ( detail [ index ] ) ) ;
443+ _this5 . _snakingLayers . push ( item ) ;
444+ _this5 . _snakingLayers [ prevRange + index ] . initDefaultPosition ( {
445+ animate : _this5 . _latLngAnimation ,
446+ points : item
447+ } ) ;
448+ _this5 . _snakingLayers [ prevRange + index ] . removePosition ( ) ;
449+ } ) ;
450+ this . snakePlay ( ) ;
408451 }
409452} ) ;
0 commit comments