@@ -73,9 +73,7 @@ export class AnimatePointAnimation extends AnimationManager {
7373}
7474
7575export class AnimateLineAnimation extends AnimationManager {
76- run = ( line ) => {
77- map . setZoom ( 15 )
78- map . setPitch ( 60 )
76+ run = ( line , follow = true , steps = 500 ) => {
7977 const path = {
8078 type : line . type ,
8179 geometry : {
@@ -85,7 +83,7 @@ export class AnimateLineAnimation extends AnimationManager {
8583 }
8684 const lineLength = length ( path , 'kilometers' )
8785 console . log ( 'Line length: ' + lineLength + ' km' )
88- const steps = 500
86+ const self = this
8987 let counter = 1
9088
9189 function animate ( _frame ) {
@@ -99,18 +97,20 @@ export class AnimateLineAnimation extends AnimationManager {
9997 redrawGeojson ( false )
10098
10199 // Update camera position
102- map . setCenter ( coordinate )
100+ if ( follow ) { map . setCenter ( coordinate ) }
103101 // map.setBearing(map.getBearing() + 1)
104102 counter ++
105103
106104 if ( counter <= steps ) {
107- requestAnimationFrame ( animate )
105+ self . animationId = requestAnimationFrame ( animate )
106+ } else {
107+ self . animationId = null
108108 }
109109 }
110110
111111 line . geometry . coordinates = [ line . geometry . coordinates [ 0 ] ]
112112 //redrawGeojson(false)
113- animate ( 0 )
113+ this . animationId = requestAnimationFrame ( animate )
114114 }
115115}
116116
@@ -119,6 +119,7 @@ export class AnimatePolygonAnimation extends AnimationManager {
119119 const height = polygon . properties [ 'fill-extrusion-height' ]
120120 console . log ( 'Polygon height: ' + height + 'm' )
121121 const steps = 100
122+ const self = this
122123 let counter = 0
123124
124125 function animate ( _timestamp ) {
@@ -130,13 +131,15 @@ export class AnimatePolygonAnimation extends AnimationManager {
130131 counter ++
131132
132133 if ( counter <= steps ) {
133- requestAnimationFrame ( animate )
134+ self . animationId = requestAnimationFrame ( animate )
135+ } else {
136+ self . animationId = null
134137 }
135138 }
136139
137140 polygon . properties [ 'fill-extrusion-height' ] = 0
138141 redrawGeojson ( )
139- animate ( 0 )
142+ this . animationId = requestAnimationFrame ( animate )
140143 }
141144}
142145
0 commit comments