Skip to content

Instantly share code, notes, and snippets.

@drecodeam
Created December 17, 2018 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drecodeam/7ee29d221f7e40fbf8e64a1b6d0c89e8 to your computer and use it in GitHub Desktop.
Save drecodeam/7ee29d221f7e40fbf8e64a1b6d0c89e8 to your computer and use it in GitHub Desktop.
drive_step = 0.004
drive_interval = 0.0001
# Animate a drive segment
animateDrive = (response) ->
path = response.routes[0].geometry.coordinates
path = turf.linestring(path)
temp_coordinates = []
pathLength = turf.lineDistance(path, 'miles')
steps = Math.floor(pathLength/drive_step)
i=0
interval_size = drive_interval
current_movement_interval = Utils.interval interval_size, ->
if i!=steps
iPoint = turf.along( path, drive_step*i, 'miles' )
pointCoordinates = iPoint.geometry.coordinates
initialMarker.setLngLat( pointCoordinates )
pulseMarker.setLngLat( pointCoordinates )
moveMap( [ pointCoordinates[1] , pointCoordinates[0]], 13)
else
clearInterval current_movement_interval
i++
getRoute( origin, destination ).then( ( data ) ->
drawRoute( data )
animateDrive( data )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment