LazMapViewer: Add functions named "LatLon" in addition to the old ones named as "LonLat" and mark the old ones as deprecated.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9298 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-03-29 08:59:35 +00:00
parent 8b3ac7d175
commit d0103c8182
10 changed files with 508 additions and 460 deletions

View File

@ -15,8 +15,10 @@ object MainForm: TMainForm
Top = 0
Width = 614
Align = alClient
CacheOnDisk = False
DownloadEngine = MapView.BuiltInDLE
DrawingEngine = MapView.BuiltInDE
Layers = <>
Font.Color = clBlack
MapProvider = 'OpenStreetMap Mapnik'
UseThreads = True

View File

@ -158,7 +158,7 @@ var
R: TRect;
begin
// Screen coordinates of the GPS point
P := TMapView(Sender).LonLatToScreen(APoint.RealPoint);
P := TMapView(Sender).LatLonToScreen(APoint.RealPoint);
// Draw the point symbol
ADrawer.PenColor := clRed;
@ -198,7 +198,7 @@ var
begin
if (ssCtrl in Shift) then
begin
p := MapView.ScreenToLonLat(Point(X, Y));
p := MapView.ScreenToLatLon(Point(X, Y));
elev := GetElevation(p);
gpsPt := TGpsPoint.CreateFrom(p, elev);

View File

@ -1,20 +1,20 @@
object MainForm: TMainForm
Left = 332
Height = 828
Height = 662
Top = 183
Width = 1178
Width = 942
Caption = 'Flights - LazMapViewer'
ClientHeight = 828
ClientWidth = 1178
DesignTimePPI = 120
ClientHeight = 662
ClientWidth = 942
ShowHint = True
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
ShowHint = True
object MapView: TMapView
Left = 0
Height = 828
Height = 662
Top = 0
Width = 780
Width = 624
Active = True
Align = alClient
CacheOnDisk = False
@ -28015,18 +28015,18 @@ object MainForm: TMainForm
OnMouseMove = MapViewMouseMove
end
object PageControl: TPageControl
Left = 780
Height = 828
Left = 624
Height = 662
Top = 0
Width = 398
Width = 318
ActivePage = PgData
Align = alRight
TabIndex = 0
TabOrder = 1
object PgData: TTabSheet
Caption = 'Tracking'
ClientHeight = 795
ClientWidth = 390
ClientHeight = 634
ClientWidth = 310
object ZoomTrackBar: TTrackBar
AnchorSideLeft.Control = PgData
AnchorSideTop.Control = LblZoom
@ -28034,13 +28034,13 @@ object MainForm: TMainForm
AnchorSideRight.Control = PgData
AnchorSideRight.Side = asrBottom
Left = 2
Height = 50
Top = 28
Width = 386
Height = 40
Top = 21
Width = 306
Min = 1
OnChange = ZoomTrackBarChange
Position = 4
TickMarks = tmBoth
OnChange = ZoomTrackBarChange
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 2
BorderSpacing.Right = 2
@ -28049,12 +28049,12 @@ object MainForm: TMainForm
object LblZoom: TLabel
AnchorSideLeft.Control = PgData
AnchorSideTop.Control = PgData
Left = 8
Height = 20
Top = 8
Width = 43
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Left = 6
Height = 15
Top = 6
Width = 35
BorderSpacing.Left = 6
BorderSpacing.Top = 6
Caption = 'Zoom:'
ParentColor = False
end
@ -28064,43 +28064,43 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = PgData
AnchorSideRight.Side = asrBottom
Left = 8
Height = 90
Top = 88
Width = 374
Left = 6
Height = 70
Top = 69
Width = 298
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 10
BorderSpacing.Right = 8
BorderSpacing.InnerBorder = 5
BorderSpacing.Left = 6
BorderSpacing.Top = 8
BorderSpacing.Right = 6
BorderSpacing.InnerBorder = 4
Caption = 'Mouse position'
ClientHeight = 65
ClientWidth = 370
ClientHeight = 50
ClientWidth = 294
TabOrder = 1
object lblMouseLon: TLabel
AnchorSideLeft.Control = gbMouse
AnchorSideTop.Control = lblMouseLat
AnchorSideTop.Side = asrBottom
Left = 10
Height = 20
Top = 35
Width = 67
BorderSpacing.Left = 10
BorderSpacing.Top = 5
Left = 8
Height = 15
Top = 27
Width = 54
BorderSpacing.Left = 8
BorderSpacing.Top = 4
Caption = 'Longitude'
ParentColor = False
end
object lblMouseLat: TLabel
AnchorSideLeft.Control = gbMouse
AnchorSideTop.Control = gbMouse
Left = 10
Height = 20
Top = 5
Width = 54
BorderSpacing.Left = 10
BorderSpacing.Top = 5
BorderSpacing.Bottom = 10
Left = 8
Height = 15
Top = 4
Width = 43
BorderSpacing.Left = 8
BorderSpacing.Top = 4
BorderSpacing.Bottom = 8
Caption = 'Latitude'
ParentColor = False
end
@ -28110,14 +28110,14 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = gbMouse
AnchorSideRight.Side = asrBottom
Left = 306
Height = 20
Top = 35
Width = 44
Left = 244
Height = 15
Top = 27
Width = 34
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 5
BorderSpacing.Right = 20
BorderSpacing.Top = 4
BorderSpacing.Right = 16
Caption = 'Label2'
ParentColor = False
end
@ -28126,15 +28126,15 @@ object MainForm: TMainForm
AnchorSideTop.Control = gbMouse
AnchorSideRight.Control = gbMouse
AnchorSideRight.Side = asrBottom
Left = 306
Height = 20
Top = 5
Width = 44
Left = 244
Height = 15
Top = 4
Width = 34
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 5
BorderSpacing.Right = 20
BorderSpacing.Bottom = 10
BorderSpacing.Top = 4
BorderSpacing.Right = 16
BorderSpacing.Bottom = 8
Caption = 'Label2'
ParentColor = False
end
@ -28145,41 +28145,41 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = gbMouse
AnchorSideRight.Side = asrBottom
Left = 8
Height = 90
Top = 188
Width = 374
Left = 6
Height = 70
Top = 147
Width = 298
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 10
BorderSpacing.InnerBorder = 5
BorderSpacing.Top = 8
BorderSpacing.InnerBorder = 4
Caption = 'Center'
ClientHeight = 65
ClientWidth = 370
ClientHeight = 50
ClientWidth = 294
TabOrder = 2
object lblCenterLon: TLabel
AnchorSideLeft.Control = gbCenter
AnchorSideTop.Control = lblCenterLat
AnchorSideTop.Side = asrBottom
Left = 10
Height = 20
Top = 35
Width = 67
BorderSpacing.Left = 10
BorderSpacing.Top = 5
Left = 8
Height = 15
Top = 27
Width = 54
BorderSpacing.Left = 8
BorderSpacing.Top = 4
Caption = 'Longitude'
ParentColor = False
end
object lblCenterLat: TLabel
AnchorSideLeft.Control = gbCenter
AnchorSideTop.Control = gbCenter
Left = 10
Height = 20
Top = 5
Width = 54
BorderSpacing.Left = 10
BorderSpacing.Top = 5
BorderSpacing.Bottom = 10
Left = 8
Height = 15
Top = 4
Width = 43
BorderSpacing.Left = 8
BorderSpacing.Top = 4
BorderSpacing.Bottom = 8
Caption = 'Latitude'
ParentColor = False
end
@ -28189,14 +28189,14 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = gbCenter
AnchorSideRight.Side = asrBottom
Left = 306
Height = 20
Top = 35
Width = 44
Left = 244
Height = 15
Top = 27
Width = 34
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 5
BorderSpacing.Right = 20
BorderSpacing.Top = 4
BorderSpacing.Right = 16
Caption = 'Label2'
ParentColor = False
end
@ -28205,15 +28205,15 @@ object MainForm: TMainForm
AnchorSideTop.Control = gbCenter
AnchorSideRight.Control = gbCenter
AnchorSideRight.Side = asrBottom
Left = 306
Height = 20
Top = 5
Width = 44
Left = 244
Height = 15
Top = 4
Width = 34
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 5
BorderSpacing.Right = 20
BorderSpacing.Bottom = 10
BorderSpacing.Top = 4
BorderSpacing.Right = 16
BorderSpacing.Bottom = 8
Caption = 'Label2'
ParentColor = False
end
@ -28223,38 +28223,38 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = plInfo
Left = 8
Height = 304
Top = 288
Width = 374
Left = 6
Height = 246
Top = 225
Width = 298
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFillColumns = True
BorderSpacing.Top = 10
BorderSpacing.Top = 8
ColCount = 3
Columns = <
item
MinSize = 12
MaxSize = 250
MinSize = 10
MaxSize = 200
SizePriority = 0
Title.Alignment = taCenter
Title.Caption = 'Flight'
Width = 88
Width = 70
ValueChecked = '-1'
end
item
ButtonStyle = cbsPickList
MinSize = 12
MaxSize = 250
MinSize = 10
MaxSize = 200
Title.Alignment = taCenter
Title.Caption = 'Latitude'
Width = 141
Width = 112
end
item
MinSize = 12
MaxSize = 250
MinSize = 10
MaxSize = 200
Title.Alignment = taCenter
Title.Caption = 'Longitude'
Width = 141
Width = 112
end>
FixedCols = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect, goSmoothScroll]
@ -28262,9 +28262,9 @@ object MainForm: TMainForm
TabOrder = 3
OnDblClick = sgTracksDblClick
ColWidths = (
88
141
141
70
112
112
)
end
object pnlFlightControl: TPanel
@ -28274,9 +28274,9 @@ object MainForm: TMainForm
AnchorSideBottom.Control = PgData
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 62
Top = 733
Width = 390
Height = 50
Top = 584
Width = 310
Anchors = [akLeft, akRight, akBottom]
BevelOuter = bvNone
ChildSizing.LeftRightSpacing = 5
@ -28288,14 +28288,14 @@ object MainForm: TMainForm
ChildSizing.ShrinkVertical = crsHomogenousChildResize
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 99
ClientHeight = 62
ClientWidth = 390
ClientHeight = 50
ClientWidth = 310
TabOrder = 4
object btnPlay: TSpeedButton
Left = 5
Height = 52
Height = 40
Top = 5
Width = 84
Width = 67
Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000000000000000
@ -28335,10 +28335,10 @@ object MainForm: TMainForm
OnClick = btnPlayClick
end
object btnPause: TSpeedButton
Left = 94
Height = 52
Left = 77
Height = 40
Top = 5
Width = 84
Width = 67
Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000000000000000
@ -28378,10 +28378,10 @@ object MainForm: TMainForm
OnClick = btnPauseClick
end
object btnStop: TSpeedButton
Left = 183
Height = 52
Left = 149
Height = 40
Top = 5
Width = 84
Width = 67
Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000000000000000
@ -28421,10 +28421,10 @@ object MainForm: TMainForm
OnClick = btnStopClick
end
object btnWarp: TSpeedButton
Left = 272
Height = 52
Left = 221
Height = 40
Top = 5
Width = 113
Width = 84
Caption = 'Warp+'
OnClick = btnWarpClick
end
@ -28432,12 +28432,12 @@ object MainForm: TMainForm
object pnlWarpInfo: TPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = pnlFlightControl
Left = 8
Height = 41
Top = 682
Width = 374
Left = 6
Height = 33
Top = 543
Width = 298
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Bottom = 10
BorderSpacing.Bottom = 8
TabOrder = 5
end
object plInfo: TPanel
@ -28445,25 +28445,26 @@ object MainForm: TMainForm
AnchorSideRight.Control = sgTracks
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = pnlWarpInfo
Left = 8
Height = 90
Top = 592
Width = 374
Left = 6
Height = 72
Top = 471
Width = 298
Anchors = [akLeft, akRight, akBottom]
ClientHeight = 90
ClientWidth = 374
ClientHeight = 72
ClientWidth = 298
Color = clCream
ParentBackground = False
ParentColor = False
TabOrder = 6
object lblInfo: TLabel
Left = 7
Height = 76
Top = 7
Width = 360
Left = 6
Height = 60
Top = 6
Width = 286
Align = alClient
AutoSize = False
BorderSpacing.Around = 6
BorderSpacing.InnerBorder = 6
BorderSpacing.Around = 5
BorderSpacing.InnerBorder = 5
Caption = 'Select a flight to follow. Double-click to center map on the aircraft.'
ParentColor = False
WordWrap = True
@ -28474,8 +28475,8 @@ object MainForm: TMainForm
object ilPOIs: TImageList
Height = 32
Width = 32
Left = 150
Top = 380
Left = 120
Top = 304
Bitmap = {
4C7A020000002000000020000000DA0900000000000078DAD5576B5055E51A5E
6A84658EE5D4E8517104B25272622C6DAC8E5D469B31D26329CD343193933595
@ -28562,8 +28563,8 @@ object MainForm: TMainForm
object ilJetSprites: TImageList
Height = 32
Width = 32
Left = 150
Top = 300
Left = 120
Top = 240
Bitmap = {
4C7A180000002000000020000000E04100000000000078DAED9D5F8C655775E6
BB6E951D648A2840812DA88409348128154266CA99312A621995A58109044D19
@ -29099,7 +29100,7 @@ object MainForm: TMainForm
Enabled = False
Interval = 100
OnTimer = tmrStepTimer
Left = 150
Top = 230
Left = 120
Top = 184
end
end

View File

@ -353,7 +353,7 @@ begin
if X <> MaxInt then
begin
RP := MapView.ScreenToLonLat(Point(X, Y));
RP := MapView.ScreenToLatLon(Point(X, Y));
lblMouseLonVal.Caption := LonToStr(RP.Lon, UseDMS);
lblMouseLatVal.Caption := LatToStr(RP.Lat, UseDMS);
end

View File

@ -19,11 +19,13 @@ object MainForm: TMainForm
Top = 0
Width = 475
Align = alClient
CacheOnDisk = False
Cyclic = True
DefaultTrackColor = clBlue
DefaultTrackWidth = 3
DownloadEngine = MapView.BuiltInDLE
DrawingEngine = MapView.BuiltInDE
Layers = <>
Font.Color = clBlack
MapProvider = 'OpenStreetMap Mapnik'
POIImages = POIImages

View File

@ -592,7 +592,7 @@ var
extent: TSize;
begin
// Screen coordinates of the GPS point
P := TMapView(Sender).LonLatToScreen(APoint.RealPoint);
P := TMapView(Sender).LatLonToScreen(APoint.RealPoint);
// Draw the GPS point as specified by the data in the point's ExtraData
if not (APoint.ExtraData is TGPSExtraData) then
@ -714,7 +714,7 @@ var
gpsImageIndex: Integer = -1;
begin
if (Button = mbRight) then begin
rPt := MapView.ScreenToLonLat(Point(X, Y));
rPt := MapView.ScreenToLatLon(Point(X, Y));
case rgPOIMode.ItemIndex of
0, 1:
@ -934,7 +934,7 @@ begin
InfoCenterLatitude.Caption := LatToStr(rPt.Lat, USE_DMS);
if (X <> MaxInt) and (Y <> MaxInt) then begin
rPt := MapView.ScreenToLonLat(Point(X, Y));
rPt := MapView.ScreenToLatLon(Point(X, Y));
InfoPositionLongitude.Caption := LonToStr(rPt.Lon, USE_DMS);
InfoPositionLatitude.Caption := LatToStr(rPt.Lat, USE_DMS);
end else begin

View File

@ -612,7 +612,7 @@ var
ext: TSize;
begin
// Screen coordinates of the GPS point
P := TMapView(Sender).LonLatToScreen(APoint.RealPoint);
P := TMapView(Sender).LatLonToScreen(APoint.RealPoint);
// Draw the GPS point with MapMarker bitmap
{
@ -652,8 +652,8 @@ var
begin
UpdateCoords(X, Y);
rArea.TopLeft := MapView.ScreenToLonLat(Point(X-DELTA, Y-DELTA));
rArea.BottomRight := MapView.ScreenToLonLat(Point(X+DELTA, Y+DELTA));
rArea.TopLeft := MapView.ScreenToLatLon(Point(X-DELTA, Y-DELTA));
rArea.BottomRight := MapView.ScreenToLatLon(Point(X+DELTA, Y+DELTA));
gpsList := MapView.GpsItems.GetObjectsInArea(rArea);
try
if gpsList.Count > 0 then begin
@ -686,7 +686,7 @@ begin
if (Button = mbRight) then begin
if not InputQuery('Name of GPS location', 'Please enter name', gpsName) then
exit;
rPt := MapView.ScreenToLonLat(Point(X, Y));
rPt := MapView.ScreenToLatLon(Point(X, Y));
gpsPt := TGpsPoint.CreateFrom(rPt);
gpsPt.Name := gpsName;
MapView.GpsItems.Add(gpsPt, _CLICKED_POINTS_);
@ -801,7 +801,7 @@ begin
InfoCenterLatitude.Caption := LatToStr(rPt.Lat, USE_DMS);
if (X <> MaxInt) and (Y <> MaxInt) then begin
rPt := MapView.ScreenToLonLat(Point(X, Y));
rPt := MapView.ScreenToLatLon(Point(X, Y));
InfoPositionLongitude.Caption := LonToStr(rPt.Lon, USE_DMS);
InfoPositionLatitude.Caption := LatToStr(rPt.Lat, USE_DMS);
end else begin

View File

@ -114,13 +114,13 @@ type
procedure SetWidth(AValue: integer);
procedure SetZoom(AValue: Integer); overload;
procedure SetZoom(AValue: integer; AZoomToCursor: Boolean); overload;
function DegreesToMapPixels(const AWin: TMapWindow; ALonLat: TRealPoint): TPoint;
function DegreesToMapPixels(const AWin: TMapWindow; APt: TRealPoint): TPoint;
function MapPixelsToDegrees(const AWin: TMapWindow; APoint: TPoint): TRealPoint;
function PixelsToDegreesEPSG3395(APoint: TPoint; Zoom: Integer): TRealPoint;
function PixelsToDegreesEPSG3857(APoint: TPoint; Zoom: Integer): TRealPoint;
procedure CalculateWin(var AWin: TMapWindow);
function DegreesToPixelsEPSG3395(const AWin: TMapWindow; ALonLat: TRealPoint): TPoint;
function DegreesToPixelsEPSG3857(const AWin: TMapWindow; ALonLat: TRealPoint): TPoint;
function DegreesToPixelsEPSG3395(const AWin: TMapWindow; APt: TRealPoint): TPoint;
function DegreesToPixelsEPSG3857(const AWin: TMapWindow; APt: TRealPoint): TPoint;
procedure Redraw(const aWin: TMapWindow; const paintOnly: Boolean = False);
function CalculateVisibleTiles(const aWin: TMapWindow; out Area: TArea): Boolean;
function IsCurrentWin(const aWin: TMapWindow) : boolean;
@ -149,14 +149,18 @@ type
function CrossesDateline: Boolean;
procedure GetMapProviders(AList: TStrings);
function MapProviderByName(AName: String): TMapProvider;
function LonLatToScreen(ALonLat: TRealPoint): TPoint;
function LonLatToWorldScreen(ALonLat: TRealPoint): TPoint;
function LatLonToScreen(APt: TRealPoint): TPoint;
function LonLatToScreen(APt: TRealPoint): TPoint; deprecated 'Use LatLonToScreen';
function LatLonToWorldScreen(APt: TRealPoint): TPoint;
function LonLatToWorldScreen(APt: TRealPoint): TPoint; deprecated 'Use LatLonToWorldScreen';
function ReadProvidersFromXML(AFileName: String; out AMsg: String): Boolean;
procedure Redraw;
Procedure RegisterProviders;
function ScreenToLonLat(aPt: TPoint): TRealPoint;
function ScreenToLatLon(aPt: TPoint): TRealPoint;
function ScreenToLonLat(aPt: TPoint): TRealPoint; deprecated 'Use ScreenToLatLon';
procedure SetSize(aWidth, aHeight: integer);
function WorldScreenToLonLat(aPt: TPoint): TRealPoint;
function WorldScreenToLatLon(aPt: TPoint): TRealPoint;
function WorldScreenToLonLat(aPt: TPoint): TRealPoint; deprecated 'Use WorldScreenToLatLon';
procedure WriteProvidersToXML(AFileName: String);
procedure DblClick(Sender: TObject);
@ -369,8 +373,8 @@ var
ptMouseCursor: TPoint;
rPtAdjustedCenter: TRealPoint;
begin
ptMouseCursor := LonLatToScreen(AWin.ZoomCenter);
rPtAdjustedCenter := ScreenToLonLat(ptMouseCursor.Add(AWin.ZoomOffset));
ptMouseCursor := LatLonToScreen(AWin.ZoomCenter);
rPtAdjustedCenter := ScreenToLatLon(ptMouseCursor.Add(AWin.ZoomOffset));
AWin.Center := rPtAdjustedCenter;
CalculateWin(AWin);
end;
@ -466,8 +470,8 @@ begin
Result := (MapWin.Width > mapWidth);
if not Result then
begin
visArea.TopLeft := ScreenToLonLat(Point(0, 0));
visArea.BottomRight := ScreenToLonLat(Point(Width, Height));
visArea.TopLeft := ScreenToLatLon(Point(0, 0));
visArea.BottomRight := ScreenToLatLon(Point(Width, Height));
Result := (visArea.TopLeft.Lon > 0) and (visArea.BottomRight.Lon < 0);
end;
end;
@ -478,7 +482,7 @@ var
begin
pt.X := FDragObj.MouseX;
pt.Y := FDragObj.MouseY;
SetCenter(ScreenToLonLat(pt));
SetCenter(ScreenToLatLon(pt));
end;
procedure TMapViewerEngine.DoDrag(Sender: TDragObj);
@ -659,7 +663,7 @@ begin
end;
function TMapViewerEngine.DegreesToMapPixels(const AWin: TMapWindow;
ALonLat: TRealPoint): TPoint;
APt: TRealPoint): TPoint;
var
pixelLocation: TPoint;
mapWidth: Int64;
@ -667,9 +671,9 @@ var
begin
PType := GetProjectionType(AWin);
case PType of
ptEPSG3395: pixelLocation := DegreesToPixelsEPSG3395(AWin, ALonLat);
ptEPSG3857: pixelLocation := DegreesToPixelsEPSG3857(AWin, ALonLat);
else pixelLocation := DegreesToPixelsEPSG3857(AWin, ALonLat);
ptEPSG3395: pixelLocation := DegreesToPixelsEPSG3395(AWin, APt);
ptEPSG3857: pixelLocation := DegreesToPixelsEPSG3857(AWin, APt);
else pixelLocation := DegreesToPixelsEPSG3857(AWin, APt);
end;
Result.X := pixelLocation.x + AWin.X;
if FCyclic and CrossesDateline then
@ -685,7 +689,7 @@ end;
// review: coth: Should it use Int64?
function TMapViewerEngine.DegreesToPixelsEPSG3857(const AWin: TMapWindow;
ALonLat: TRealPoint): TPoint;
APt: TRealPoint): TPoint;
const
MIN_LATITUDE = -85.05112878;
MAX_LATITUDE = 85.05112878;
@ -699,8 +703,8 @@ begin
// https://epsg.io/3857
// https://pubs.usgs.gov/pp/1395/report.pdf, page 41
// https://en.wikipedia.org/wiki/Web_Mercator_projection
pt.Lat := Math.EnsureRange(ALonLat.Lat, MIN_LATITUDE, MAX_LATITUDE);
pt.Lon := Math.EnsureRange(ALonLat.Lon, MIN_LONGITUDE, MAX_LONGITUDE);
pt.Lat := Math.EnsureRange(APt.Lat, MIN_LATITUDE, MAX_LATITUDE);
pt.Lon := Math.EnsureRange(APt.Lon, MIN_LONGITUDE, MAX_LONGITUDE);
factor := TILE_SIZE / TWO_PI * ZoomFactor(AWin.Zoom);
px := factor * (pt.LonRad + pi);
@ -712,7 +716,7 @@ end;
// review: coth: Should it use Int64?
function TMapViewerEngine.DegreesToPixelsEPSG3395(const AWin: TMapWindow;
ALonLat: TRealPoint): TPoint;
APt: TRealPoint): TPoint;
const
MIN_LATITUDE = -80;
MAX_LATITUDE = 84;
@ -727,8 +731,8 @@ var
begin
// https://epsg.io/3395
// https://pubs.usgs.gov/pp/1395/report.pdf, page 44
pt.Lat := Math.EnsureRange(ALonLat.Lat, MIN_LATITUDE, MAX_LATITUDE);
pt.Lon := Math.EnsureRange(ALonLat.Lon, MIN_LONGITUDE, MAX_LONGITUDE);
pt.Lat := Math.EnsureRange(APt.Lat, MIN_LATITUDE, MAX_LATITUDE);
pt.Lon := Math.EnsureRange(APt.Lon, MIN_LONGITUDE, MAX_LONGITUDE);
Z := 23 - AWin.Zoom;
zoomfac := ZoomFactor(Z);
@ -744,18 +748,28 @@ begin
Result.y := Round(py);
end;
function TMapViewerEngine.LonLatToScreen(ALonLat: TRealPoint): TPoint;
Begin
Result := DegreesToMapPixels(MapWin, ALonLat);
function TMapViewerEngine.LatLonToScreen(APt: TRealPoint): TPoint;
begin
Result := DegreesToMapPixels(MapWin, APt);
end;
function TMapViewerEngine.LonLatToWorldScreen(ALonLat: TRealPoint): TPoint;
function TMapViewerEngine.LonLatToScreen(APt: TRealPoint): TPoint;
Begin
Result := DegreesToMapPixels(MapWin, APt);
end;
function TMapViewerEngine.LatLonToWorldScreen(APt: TRealPoint): TPoint;
begin
Result := LonLatToScreen(ALonLat);
Result := LatLonToScreen(APt);
Result.X := Result.X + MapWin.X;
Result.Y := Result.Y + MapWin.Y;
end;
function TMapViewerEngine.LonLatToWorldScreen(APt: TRealPoint): TPoint;
begin
Result := LatLonToScreen(APt);
end;
function TMapViewerEngine.MapPixelsToDegrees(const AWin: TMapWindow;
APoint: TPoint): TRealPoint;
var
@ -906,8 +920,8 @@ begin
begin
if ZoomToCursor then
begin
MapWin.ZoomCenter := ScreenToLonLat(MousePos);
MapWin.ZoomOffset := LonLatToScreen(Center).Subtract(MousePos);
MapWin.ZoomCenter := ScreenToLatLon(MousePos);
MapWin.ZoomOffset := LatLonToScreen(Center).Subtract(MousePos);
bZoomToCursor := True;
end;
SetZoom(nZoom, bZoomToCursor);
@ -1172,6 +1186,11 @@ begin
MapWin.MapProvider := Nil; // Undo the OSM Mapnik default selection
end;
function TMapViewerEngine.ScreenToLatLon(aPt: TPoint): TRealPoint;
begin
Result := MapPixelsToDegrees(MapWin, aPt);
end;
function TMapViewerEngine.ScreenToLonLat(aPt: TPoint): TRealPoint;
begin
Result := MapPixelsToDegrees(MapWin, aPt);
@ -1387,12 +1406,16 @@ begin
end;
end;
function TMapViewerEngine.WorldScreenToLonLat(aPt: TPoint): TRealPoint;
function TMapViewerengine.WorldScreenToLatLon(aPt: TPoint): TRealPoint;
begin
aPt.X := aPt.X - MapWin.X;
aPt.Y := aPt.Y - MapWin.Y;
Result := ScreenToLonLat(aPt);
Result := ScreenToLatLon(aPt);
end;
function TMapViewerEngine.WorldScreenToLonLat(aPt: TPoint): TRealPoint;
begin
Result := WorldScreenToLatLon(aPt);
end;
procedure TMapViewerEngine.WriteProvidersToXML(AFileName: String);

View File

@ -3,7 +3,8 @@
Extensions:
(C) 2014 ti_dic@hotmail.com
(C) 2019 Werner Pamler (user wp at Lazarus forum https://forum.lazarus.freepascal.org
(C) 2019 Werner Pamler (user wp at Lazarus forum https://forum.lazarus.freepascal.org)
(C) 2023 Yuliyan Ivanov (user alpine at Lazarus forum https://forum.lazarus.freepascal.org)
License: modified LGPL with linking exception (like RTL, FCL and LCL)
@ -15,6 +16,10 @@
// ToDo: Make Active work at designtime.
// "Deprecated" warnings:
// - function names containing "LonLat" were copied and named to contain "LatLon"
// (will be removed in v1.0)
unit mvMapViewer;
{$MODE objfpc}{$H+}
@ -468,12 +473,14 @@ type
procedure ClearBuffer;
procedure GetMapProviders(lstProviders: TStrings);
function GetVisibleArea: TRealArea;
function LonLatToScreen(aPt: TRealPoint): TPoint;
function LatLonToScreen(aPt: TRealPoint): TPoint;
function LonLatToScreen(aPt: TRealPoint): TPoint; deprecated 'Use LatLonToScreen';
function ObjsAtScreenPt(X, Y: Integer; ATolerance: Integer = -1): TGPSObjarray;
procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String);
function SaveToImage(AClass: TRasterImageClass): TRasterImage;
procedure SaveToStream(AClass: TRasterImageClass; AStream: TStream);
function ScreenToLonLat(aPt: TPoint): TRealPoint;
function ScreenToLatLon(aPt: TPoint): TRealPoint;
function ScreenToLonLat(aPt: TPoint): TRealPoint; deprecated 'Use ScreenToLatLon';
procedure CenterOnObj(obj: TGPSObj);
procedure Redraw; inline;
procedure ZoomOnArea(const aArea: TRealArea);
@ -1029,7 +1036,7 @@ end;
function TMapPoint.GetToScreen: TPoint;
begin
Result := View.LonLatToScreen(RealPoint(Latitude, Longitude));
Result := View.LatLonToScreen(RealPoint(Latitude, Longitude));
end;
procedure TMapPoint.SetLatitude(AValue: Double);
@ -2111,12 +2118,12 @@ begin
end;
pt1 := trk.Points[0].RealPoint;
iPt1 := Engine.LonLatToScreen(pt1);
iPt1 := Engine.LatLonToScreen(pt1);
EndSegm := TSegmentExtraData.MarkOf(trk.Points[0].ExtraData) = smEnd;
for I := 1 to Pred(trk.Points.Count) do
begin
pt2 := trk.Points[I].RealPoint;
iPt2 := Engine.LonLatToScreen(pt2);
iPt2 := Engine.LatLonToScreen(pt2);
ToEast := GoingEast(pt1.Lon, pt2.Lon); // Eastwards?
iPt2 := CyclicPointOf(iPt2, iPt1.X, ToEast); // Nearest iPt2 to iPt1
@ -2185,7 +2192,7 @@ begin
SetLength(Pts, C);
for I := 0 to Pred(ar.Points.Count) do
Pts[I] := Engine.LonLatToScreen(ar.Points[I].RealPoint);
Pts[I] := Engine.LatLonToScreen(ar.Points[I].RealPoint);
if NoFill then
Pts[Pred(C)] := Pts[0];
@ -2244,7 +2251,7 @@ var
end;
begin
pt := Engine.LonLatToScreen(APt.RealPoint);
pt := Engine.LatLonToScreen(APt.RealPoint);
bmp := Nil;
try
@ -2320,7 +2327,7 @@ begin
exit;
end;
Pt := Engine.LonLatToScreen(APt.RealPoint);
Pt := Engine.LatLonToScreen(APt.RealPoint);
PtColor := clRed;
if APt.ExtraData <> nil then
begin
@ -2364,8 +2371,8 @@ var
lst: TGPSObjList;
I, J: Integer;
begin
Area.TopLeft := Engine.ScreenToLonLat(Point(aLeft, aTop));
Area.BottomRight := Engine.ScreenToLonLat(Point(aRight, aBottom));
Area.TopLeft := Engine.ScreenToLatLon(Point(aLeft, aTop));
Area.BottomRight := Engine.ScreenToLatLon(Point(aRight, aBottom));
for J := 0 to High(FGPSItems) do
if FGPSItems[J].Visible and (FGPSItems[J].Count > 0) then
@ -2617,14 +2624,24 @@ begin
end;
end;
function TMapView.ScreenToLatLon(aPt: TPoint): TRealPoint;
begin
Result := Engine.ScreenToLatLon(aPt);
end;
function TMapView.ScreenToLonLat(aPt: TPoint): TRealPoint;
begin
Result:=Engine.ScreenToLonLat(aPt);
Result := Engine.ScreenToLatLon(aPt);
end;
function TMapView.LatLonToScreen(aPt: TRealPoint): TPoint;
begin
Result := Engine.LatLonToScreen(aPt);
end;
function TMapView.LonLatToScreen(aPt: TRealPoint): TPoint;
begin
Result:=Engine.LonLatToScreen(aPt);
Result := Engine.LatLonToScreen(aPt);
end;
procedure TMapView.GetMapProviders(lstProviders: TStrings);
@ -2662,8 +2679,8 @@ begin
ATolerance := DELTA;
// Define area of +/-ATolerance pixels around the screen point
rArea.TopLeft := ScreenToLonLat(Point(X-ATolerance, Y-ATolerance));
rArea.BottomRight := ScreenToLonLat(Point(X+ATolerance, Y+ATolerance));
rArea.TopLeft := ScreenToLatLon(Point(X-ATolerance, Y-ATolerance));
rArea.BottomRight := ScreenToLatLon(Point(X+ATolerance, Y+ATolerance));
// Collect Objects in this are
for J := 0 to 9 do
@ -2713,8 +2730,8 @@ function TMapView.GetVisibleArea: TRealArea;
var
mapWidth: Int64;
begin
Result.TopLeft := Engine.ScreenToLonLat(Point(0, 0));
Result.BottomRight := Engine.ScreenToLonLat(Point(Width, Height));
Result.TopLeft := Engine.ScreenToLatLon(Point(0, 0));
Result.BottomRight := Engine.ScreenToLatLon(Point(Width, Height));
if Cyclic then
begin
mapWidth := ZoomFactor(Engine.Zoom) * TILE_SIZE;
@ -2918,8 +2935,8 @@ var
begin
inherited Draw(AView, Area);
V := FParentView;
PtTL := V.Engine.LonLatToWorldScreen(Area.TopLeft);
PtBR := V.Engine.LonLatToWorldScreen(Area.BottomRight);
PtTL := V.Engine.LatLonToWorldScreen(Area.TopLeft);
PtBR := V.Engine.LatLonToWorldScreen(Area.BottomRight);
X := -PtTL.X div TILE_SIZE;
Y := -PtTL.Y div TILE_SIZE;
Pt0 := Point(V.Engine.MapLeft + X * TILE_SIZE,