From 7b8cf5cf0bf7c1bb37d0727bf7e148a7f94b80e2 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 21 Apr 2023 10:36:50 +0000 Subject: [PATCH] LazMapviewer: Partial fix of gps points created near E/W border not showing. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8798 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../lazmapviewer/source/mvmapviewer.pas | 21 ++++++++++++++----- components/lazmapviewer/source/mvtypes.pas | 18 ++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/components/lazmapviewer/source/mvmapviewer.pas b/components/lazmapviewer/source/mvmapviewer.pas index ca9598d8e..abe743f18 100644 --- a/components/lazmapviewer/source/mvmapviewer.pas +++ b/components/lazmapviewer/source/mvmapviewer.pas @@ -793,8 +793,7 @@ var begin Area.TopLeft := Engine.ScreenToLonLat(Point(aLeft, aTop)); Area.BottomRight := Engine.ScreenToLonLat(Point(aRight, aBottom)); - while Area.BottomRight.Lon < Area.TopLeft.Lon do - Area.BottomRight.Lon := Area.BottomRight.Lon + 360.0; + Area.Normalize; if GPSItems.Count > 0 then begin @@ -1016,13 +1015,25 @@ end; function TMapView.GetVisibleArea: TRealArea; var aPt: TPoint; + w, mapWidth: Int64; begin aPt.X := 0; aPt.Y := 0; Result.TopLeft := Engine.ScreenToLonLat(aPt); - aPt.X := Width; - aPt.Y := Height; - Result.BottomRight := Engine.ScreenToLonLat(aPt);; + + mapWidth := ZoomFactor(Engine.Zoom) * TILE_SIZE; + w := Width; + if w >= mapWidth then + begin + Result.TopLeft.Lon := -180; + Result.BottomRight.Lon := 180; + end else + begin + aPt.X := w; + aPt.Y := Height; + Result.BottomRight := Engine.ScreenToLonLat(aPt); + Result.Normalize; + end; end; procedure TMapView.ClearBuffer; diff --git a/components/lazmapviewer/source/mvtypes.pas b/components/lazmapviewer/source/mvtypes.pas index c66299332..b1341bdf4 100644 --- a/components/lazmapviewer/source/mvtypes.pas +++ b/components/lazmapviewer/source/mvtypes.pas @@ -47,11 +47,15 @@ Type TRealArea = Record TopLeft : TRealPoint; BottomRight : TRealPoint; + procedure Normalize; + function Normalized: TRealArea; end; implementation +{ TRealPoint } + function TRealPoint.GetLonRad: Extended; begin Result := DegToRad(Self.Lon); @@ -72,5 +76,19 @@ begin Self.Lat := RadToDeg(AValue); end; +{ TRealArea } + +procedure TRealArea.Normalize; +begin + while BottomRight.Lon < TopLeft.Lon do + BottomRight.Lon := BottomRight.Lon + 360.0; +end; + +function TRealArea.Normalized: TRealArea; +begin + Result := Self; + Result.Normalize; +end; + end.