@@ -111,12 +111,12 @@ function BlackboxLogViewer() {
111111 animationFrameIsQueued = false ,
112112
113113 playbackRate = PLAYBACK_DEFAULT_RATE ,
114-
114+
115115 graphZoom = GRAPH_DEFAULT_ZOOM ,
116116 lastGraphZoom = GRAPH_DEFAULT_ZOOM , // QuickZoom function.
117-
117+
118118 mapGrapher = new MapGrapher ( ) ;
119-
119+
120120
121121 function createNewBlackboxWindow ( fileToOpen ) {
122122
@@ -309,7 +309,7 @@ function BlackboxLogViewer() {
309309 if ( flightLog . hasGpsData ( ) ) {
310310 mapGrapher . resize ( width , height ) ;
311311 }
312-
312+
313313 invalidateGraph ( ) ;
314314 }
315315 }
@@ -918,28 +918,35 @@ function BlackboxLogViewer() {
918918 reader . readAsText ( file ) ;
919919 }
920920
921- function exportCsv ( file , options = { } ) {
922-
923- function onSuccess ( data ) {
924- console . debug ( "CSV export finished in" , ( performance . now ( ) - startTime ) / 1000 , "secs" ) ;
921+ function createExportCallback ( fileExtension , fileType , file , startTime ) {
922+ const callback = function ( data ) {
923+ console . debug ( `${ fileExtension . toUpperCase ( ) } export finished in ${ ( performance . now ( ) - startTime ) / 1000 } secs` ) ;
925924 if ( ! data ) {
926925 console . debug ( "Empty data, nothing to save" ) ;
927926 return ;
928927 }
929- let blob = new Blob ( [ data ] , { type : 'text/csv' } ) ,
928+ let blob = new Blob ( [ data ] , { type : fileType } ) ,
930929 e = document . createEvent ( 'MouseEvents' ) ,
931930 a = document . createElement ( 'a' ) ;
932- a . download = file || $ ( ".log-filename" ) . text ( ) + ".csv" ;
931+ a . download = file || $ ( ".log-filename" ) . text ( ) + "." + fileExtension ;
933932 a . href = window . URL . createObjectURL ( blob ) ;
934- a . dataset . downloadurl = [ 'text/csv' , a . download , a . href ] . join ( ':' ) ;
933+ a . dataset . downloadurl = [ fileType , a . download , a . href ] . join ( ':' ) ;
935934 e . initMouseEvent ( 'click' , true , false , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null ) ;
936935 a . dispatchEvent ( e ) ;
937- }
936+ } ;
937+ return callback ;
938+ }
938939
939- let startTime = performance . now ( ) ;
940+ function exportCsv ( file , options = { } ) {
941+ const onSuccess = createExportCallback ( 'csv' , 'text/csv' , file , performance . now ( ) ) ;
940942 CsvExporter ( flightLog , options ) . dump ( onSuccess ) ;
941943 }
942944
945+ function exportGpx ( file ) {
946+ const onSuccess = createExportCallback ( 'gpx' , 'GPX File' , file , performance . now ( ) ) ;
947+ GpxExporter ( flightLog ) . dump ( onSuccess ) ;
948+ }
949+
943950 function newGraphConfig ( newConfig ) {
944951 lastGraphConfig = graphConfig ; // Remember the last configuration.
945952 graphConfig = newConfig ;
@@ -1129,7 +1136,7 @@ function BlackboxLogViewer() {
11291136
11301137 $ ( ".view-map" ) . click ( function ( ) {
11311138 hasMap = ! hasMap ;
1132- html . toggleClass ( "has-map" , hasMap ) ;
1139+ html . toggleClass ( "has-map" , hasMap ) ;
11331140 prefs . set ( 'hasMap' , hasMap ) ;
11341141 if ( flightLog . hasGpsData ( ) ) {
11351142 mapGrapher . initialize ( userSettings ) ;
@@ -1470,6 +1477,11 @@ function BlackboxLogViewer() {
14701477 exportCsv ( ) ;
14711478 e . preventDefault ( ) ;
14721479 } ) ;
1480+ $ ( ".btn-gpx-export" ) . click ( function ( e ) {
1481+ setGraphState ( GRAPH_STATE_PAUSED ) ;
1482+ exportGpx ( ) ;
1483+ e . preventDefault ( ) ;
1484+ } ) ;
14731485
14741486 if ( FlightLogVideoRenderer . isSupported ( ) ) {
14751487 $ ( ".btn-video-export" ) . click ( function ( e ) {
0 commit comments