LazMapViewer: Add utility functions for centering.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9562 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2025-01-01 23:56:23 +00:00
parent 9c6eef3b8c
commit 4c30141e1a
2 changed files with 30 additions and 7 deletions

View File

@ -199,8 +199,7 @@ begin
with GetMapView do
begin
Engine.ZoomOnArea(lBounds);
MapCenter.Longitude := (lBounds.TopLeft.Lon + lBounds.BottomRight.Lon) / 2;
MapCenter.Latitude := (lBounds.TopLeft.Lat + lBounds.BottomRight.Lat) / 2;
MapCenter.RealPt := Center;
end;
// Update the object tree

View File

@ -222,14 +222,17 @@ type
FLongitude: Double;
FView: TMapView;
function GetLatLonInDMS: Boolean;
function GetRealPt: TRealPoint;
procedure SetLatitude(AValue: Double);
procedure SetLongitude(AValue: Double);
procedure SetRealPt(AValue: TRealPoint);
procedure SetViewCenter;
protected
function GetOwner: TPersistent; override;
public
constructor Create(AView: TMapView);
property LatLonInDMS: Boolean read GetLatLonInDMS;
property RealPt: TRealPoint read GetRealPt write SetRealPt;
published
property Longitude: Double read FLongitude write SetLongitude;
property Latitude: Double read FLatitude write SetLatitude;
@ -655,10 +658,11 @@ type
procedure SaveToStream(AClass: TRasterImageClass; AStream: TStream);
function ScreenToLatLon(aPt: TPoint): TRealPoint;
function ScreenToLonLat(aPt: TPoint): TRealPoint; deprecated 'Use ScreenToLatLon';
procedure CenterOnObj(obj: TGPSObj);
procedure Redraw; inline;
function UsesDefaultDownloadEngine: Boolean;
function UsesDefaultDrawingEngine: Boolean;
procedure CenterOnArea(const aArea: TRealArea);
procedure CenterOnObj(obj: TGPSObj);
procedure ZoomOnArea(const aArea: TRealArea);
procedure ZoomOnObj(obj: TGPSObj);
procedure WaitEndOfRendering;
@ -1762,11 +1766,25 @@ begin
SetViewCenter;
end;
procedure TMapCenter.SetRealPt(AValue: TRealPoint);
begin
if (FLatitude = AValue.Lat) and (FLongitude = AValue.Lon) then Exit;
FLatitude := AValue.Lat;
FLongitude := AValue.Lon;
SetViewCenter;
end;
function TMapCenter.GetLatLonInDMS: Boolean;
begin
Result := Assigned(FView) and (mvoLatLonInDMS in FView.Options);
end;
function TMapCenter.GetRealPt: TRealPoint;
begin
Result.Lon := FLongitude;
Result.Lat := FLatitude;
end;
procedure TMapCenter.SetViewCenter;
var
R: TRealPoint;
@ -3651,15 +3669,21 @@ begin
Result := FindObjsAtScreenPt(X, Y, ATolerance, true);
end;
procedure TMapView.CenterOnArea(const aArea: TRealArea);
var
Pt: TRealPoint;
begin
Pt.Lon := (aArea.TopLeft.Lon + aArea.BottomRight.Lon) /2;
Pt.Lat := (aArea.TopLeft.Lat + aArea.BottomRight.Lat) /2;
Center := Pt;
end;
procedure TMapView.CenterOnObj(obj: TGPSObj);
var
Area: TRealArea;
Pt: TRealPoint;
begin
obj.GetArea(Area);
Pt.Lon := (Area.TopLeft.Lon + Area.BottomRight.Lon) /2;
Pt.Lat := (Area.TopLeft.Lat + Area.BottomRight.Lat) /2;
Center := Pt;
CenterOnArea(Area);
end;
procedure TMapView.ZoomOnObj(obj: TGPSObj);