@@ -93,10 +93,33 @@ function drawTrack(trackData, addStartMarker = true, animatedCursor = false) {
9393 anchorOrigin : 'bottom-right' , anchor : [ 0.15 , 0 ] } )
9494 } ) ;
9595 for ( var itrk = 0 ; itrk < trackData . length ; itrk ++ ) {
96- nseg = trackData [ itrk ] . coords . length ;
96+ var nseg = trackData [ itrk ] . coords . length ;
97+ var lastidx = 0 ;
9798 for ( var iseg = 0 ; iseg < nseg ; iseg ++ ) {
98- allpoints . push ( ...trackData [ itrk ] . coords [ iseg ] ) ;
99- trkGeom = new ol . geom . LineString ( trackData [ itrk ] . coords [ iseg ] ) ;
99+ var curCoords = trackData [ itrk ] . coords [ iseg ] ;
100+ for ( var ipt = 1 ; ipt < curCoords . length ; ipt ++ ) {
101+ if ( Math . sign ( curCoords [ ipt ] [ 0 ] ) != Math . sign ( curCoords [ ipt - 1 ] [ 0 ] ) &&
102+ Math . abs ( curCoords [ ipt ] [ 0 ] - curCoords [ ipt - 1 ] [ 0 ] ) > 180 ) {
103+ // crossing date line: interpolate and cut track
104+ var x1 = curCoords [ ipt - 1 ] [ 0 ] ;
105+ var x2 = curCoords [ ipt ] [ 0 ] ;
106+ if ( x1 < 0 ) x1 += 180 ;
107+ if ( x2 < 0 ) x2 += 180 ;
108+ var lat = curCoords [ ipt - 1 ] [ 1 ] + ( 180 - x2 ) * ( curCoords [ ipt ] [ 1 ] - curCoords [ ipt - 1 ] [ 0 ] ) / ( x2 - x1 ) ;
109+ var tmpCoords = curCoords . slice ( lastidx , ipt ) ;
110+ allpoints . push ( ...tmpCoords ) ;
111+ tmpCoords . push ( [ Math . sign ( curCoords [ ipt - 1 ] [ 0 ] ) * 180.0 , lat ] ) ;
112+ var trkGeom = new ol . geom . LineString ( tmpCoords ) ;
113+ trkGeom . transform ( 'EPSG:4326' , jtgView . getProjection ( ) ) ;
114+ gpsTracks . getSource ( ) . addFeature ( new ol . Feature ( { geometry : trkGeom , name : trackData [ itrk ] . name } ) ) ;
115+ curCoords [ ipt - 1 ] [ 0 ] = Math . sign ( curCoords [ ipt ] [ 0 ] ) * 180.0 ;
116+ curCoords [ ipt - 1 ] [ 1 ] = lat ;
117+ lastidx = ipt - 1 ;
118+ }
119+ }
120+ tmpCoords = curCoords . slice ( lastidx , curCoords . length ) ;
121+ allpoints . push ( ...tmpCoords ) ;
122+ trkGeom = new ol . geom . LineString ( tmpCoords ) ;
100123 trkGeom . transform ( 'EPSG:4326' , jtgView . getProjection ( ) ) ;
101124 gpsTracks . getSource ( ) . addFeature ( new ol . Feature ( { geometry : trkGeom , name : trackData [ itrk ] . name } ) ) ;
102125 }
0 commit comments