@@ -125,6 +125,7 @@ private void but_mincommands_Click(object sender, System.EventArgs e)
125125 private DateTime mapupdate = DateTime . MinValue ;
126126 private string mobileGpsLog = string . Empty ;
127127 private PointLatLng MouseDownStart ;
128+ private Point MouseDownStartLocal ;
128129 private PointLatLngAlt mouseposdisplay = new PointLatLngAlt ( 0 , 0 ) ;
129130 private WPOverlay wpOverlay ;
130131 private bool polygongridmode ;
@@ -1035,7 +1036,9 @@ public void redrawPolygonSurvey(List<PointLatLngAlt> list)
10351036 if ( now == null || next == null )
10361037 continue ;
10371038
1038- var mid = new PointLatLngAlt ( ( now . Lat + next . Lat ) / 2 , ( now . Lng + next . Lng ) / 2 , 0 ) ;
1039+ var p1 = MainMap . FromLatLngToLocal ( now ) ;
1040+ var p2 = MainMap . FromLatLngToLocal ( next ) ;
1041+ var mid = new PointLatLngAlt ( MainMap . FromLocalToLatLng ( ( int ) ( ( p1 . X + p2 . X ) / 2 ) , ( int ) ( ( p1 . Y + p2 . Y ) / 2 ) ) ) ;
10391042
10401043 var pnt = new GMapMarkerPlus ( mid ) ;
10411044 pnt . Tag = new midline ( ) { now = now , next = next } ;
@@ -1480,8 +1483,10 @@ public void writeKML()
14801483 if ( now == null || next == null )
14811484 continue ;
14821485
1483- var mid = new PointLatLngAlt ( ( now . Lat + next . Lat ) / 2 , ( now . Lng + next . Lng ) / 2 ,
1484- ( now . Alt + next . Alt ) / 2 ) ;
1486+ var p1 = MainMap . FromLatLngToLocal ( now ) ;
1487+ var p2 = MainMap . FromLatLngToLocal ( next ) ;
1488+ var mid = new PointLatLngAlt ( MainMap . FromLocalToLatLng ( ( int ) ( ( p1 . X + p2 . X ) / 2 ) , ( int ) ( ( p1 . Y + p2 . Y ) / 2 ) ) ) ;
1489+ mid . Alt = ( now . Alt + next . Alt ) / 2 ;
14851490
14861491 var pnt = new GMapMarkerPlus ( mid ) ;
14871492 pnt . Tag = new midline ( ) { now = now , next = next } ;
@@ -1557,7 +1562,9 @@ public void writeKML()
15571562 if ( now == null || next == null )
15581563 continue ;
15591564
1560- var mid = new PointLatLngAlt ( ( now . Lat + next . Lat ) / 2 , ( now . Lng + next . Lng ) / 2 , 0 ) ;
1565+ var p1 = MainMap . FromLatLngToLocal ( now ) ;
1566+ var p2 = MainMap . FromLatLngToLocal ( next ) ;
1567+ var mid = new PointLatLngAlt ( MainMap . FromLocalToLatLng ( ( int ) ( ( p1 . X + p2 . X ) / 2 ) , ( int ) ( ( p1 . Y + p2 . Y ) / 2 ) ) ) ;
15611568
15621569 var pnt = new GMapMarkerPlus ( mid ) ;
15631570 pnt . Tag = new midline ( ) { now = now , next = next } ;
@@ -7357,6 +7364,7 @@ private void MainMap_MouseDown(object sender, MouseEventArgs e)
73577364 return ;
73587365
73597366 MouseDownStart = MainMap . FromLocalToLatLng ( e . X , e . Y ) ;
7367+ MouseDownStartLocal = e . Location ;
73607368
73617369 // Console.WriteLine("MainMap MD");
73627370
@@ -7526,16 +7534,34 @@ private void MainMap_MouseMove(object sender, MouseEventArgs e)
75267534 }
75277535 else // left click pan
75287536 {
7529- double latdif = MouseDownStart . Lat - point . Lat ;
7530- double lngdif = MouseDownStart . Lng - point . Lng ;
7531-
75327537 try
75337538 {
75347539 lock ( thisLock )
75357540 {
75367541 if ( ! isMouseClickOffMenu )
7537- MainMap . Position = new PointLatLng ( center . Position . Lat + latdif ,
7538- center . Position . Lng + lngdif ) ;
7542+ {
7543+ // incremental delta avoids direction lock when crossing pole singularities
7544+ int dx = e . X - MouseDownStartLocal . X ;
7545+ int dy = e . Y - MouseDownStartLocal . Y ;
7546+
7547+ if ( dx == 0 && dy == 0 )
7548+ return ;
7549+
7550+ double absLat = Math . Abs ( MainMap . Position . Lat ) ;
7551+
7552+ PointLatLng newCenter = MainMap . FromLocalToLatLng (
7553+ MainMap . Width / 2 - dx ,
7554+ MainMap . Height / 2 - dy ) ;
7555+
7556+ if ( ! double . IsNaN ( newCenter . Lat ) && ! double . IsNaN ( newCenter . Lng ) &&
7557+ ! double . IsInfinity ( newCenter . Lat ) && ! double . IsInfinity ( newCenter . Lng ) )
7558+ {
7559+ MainMap . Position = newCenter ;
7560+ }
7561+
7562+ // key part: consume this step so next move is relative to current state
7563+ MouseDownStartLocal = e . Location ;
7564+ }
75397565 }
75407566 }
75417567 catch ( Exception ex )
0 commit comments