LazMapViewer: Fix loss of coordinate accuracy when dragging points at small zoom factor. Issue #39114.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9675 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2025-03-12 09:46:35 +00:00
parent adc968308b
commit 12eb71ee4e
2 changed files with 30 additions and 8 deletions

View File

@ -38,13 +38,16 @@ Type
FEndX,FEndY : integer; FEndX,FEndY : integer;
FOnDrag: TDragEvent; FOnDrag: TDragEvent;
FOnEndDrag: TDragEvent; FOnEndDrag: TDragEvent;
function GetEndPt: TPoint;
function GetOfsPt: TPoint;
function GetStartPt: TPoint;
procedure SetDest(X,Y : Integer); procedure SetDest(X,Y : Integer);
procedure SetLnkObj(AValue: TObject); procedure SetLnkObj(AValue: TObject);
procedure SetOnDrag(AValue: TDragEvent); procedure SetOnDrag(AValue: TDragEvent);
procedure SetOnEndDrag(AValue: TDragEvent); procedure SetOnEndDrag(AValue: TDragEvent);
Procedure DostartDrag(X,Y: Integer); Procedure DoStartDrag(X,Y: Integer);
Procedure DoDrag(X,Y: integer); Procedure DoDrag(X,Y: integer);
Procedure DoEndDrag(X,Y: integer); Procedure DoEndDrag(X,Y: integer);
Function HasMoved(X,Y: integer) : Boolean; Function HasMoved(X,Y: integer) : Boolean;
@ -58,12 +61,15 @@ Type
property OnDrag: TDragEvent read FOnDrag write SetOnDrag; property OnDrag: TDragEvent read FOnDrag write SetOnDrag;
property OnEndDrag: TDragEvent read FOnEndDrag write SetOnEndDrag; property OnEndDrag: TDragEvent read FOnEndDrag write SetOnEndDrag;
property OfsPt: TPoint read GetOfsPt;
property OfsX: integer read FOfsX; property OfsX: integer read FOfsX;
property OfsY: integer read FOfsY; property OfsY: integer read FOfsY;
property StartPt: TPoint read GetStartPt;
property StartX: integer read FStartX; property StartX: integer read FStartX;
property StartY: integer read FStartY; property StartY: integer read FStartY;
property MouseX: Integer read FMouseX; property MouseX: Integer read FMouseX;
property MouseY: integer read FMouseY; property MouseY: integer read FMouseY;
property EndPt: TPoint read GetEndPt;
property EndX: integer read FEndX; property EndX: integer read FEndX;
property EndY: integer read FEndY; property EndY: integer read FEndY;
Property LnkObj: TObject Read FLnkObj write SetLnkObj; Property LnkObj: TObject Read FLnkObj write SetLnkObj;
@ -130,6 +136,21 @@ begin
FInDrag := False; FInDrag := False;
end; end;
function TDragObj.GetEndPt: TPoint;
begin
Result := Point(FEndX, FEndY);
end;
function TDragObj.GetOfsPt: TPoint;
begin
Result := Point(FOfsX, FOfsY);
end;
function TDragObj.GetStartPt: TPoint;
begin
Result := Point(FStartX, FStartY);
end;
function TDragObj.HasMoved(X, Y: integer): Boolean; function TDragObj.HasMoved(X, Y: integer): Boolean;
begin begin
Result := (X <> FStartX) or (Y <> FStartY); Result := (X <> FStartX) or (Y <> FStartY);
@ -139,10 +160,10 @@ procedure TDragObj.AbortDrag;
begin begin
if FInDrag then if FInDrag then
Begin Begin
DoDrag(FstartX,FStartY); DoDrag(FStartX, FStartY);
FInDrag := False; FInDrag := False;
FMouseDown := False; FMouseDown := False;
FDragSrc :=nil; FDragSrc := nil;
FStartSrc := nil; FStartSrc := nil;
FreeAndNil(FLnkObj); FreeAndNil(FLnkObj);
end; end;

View File

@ -4781,7 +4781,7 @@ end;
procedure TMapEditMark.DoDrag(Sender: TDragObj); procedure TMapEditMark.DoDrag(Sender: TDragObj);
var var
I: Integer = 0; I: Integer = 0;
RPt: TRealPoint; RptStart, RPtEnd: TRealPoint;
MapPoint: TMapPoint; MapPoint: TMapPoint;
begin begin
if not FDragStarted then if not FDragStarted then
@ -4804,10 +4804,11 @@ begin
for MapPoint in FSelection.Points do for MapPoint in FSelection.Points do
begin begin
MarkDirty; MarkDirty;
Rpt := FMapView.ScreenToLatLon(FMapView.LatLonToScreen(FOrigins[I]) + // Apply positions of drag start and end points from pixel space to real world space
Point(Sender.OfsX, Sender.OfsY)); RPtStart := FMapView.ScreenToLatLon(Sender.StartPt);
MapPoint.Longitude := RPt.Lon; RPtEnd := FMapView.ScreenToLatLon(Sender.EndPt);
MapPoint.Latitude := RPt.Lat; MapPoint.Longitude := FOrigins[I].Lon + (RPtEnd.Lon - RPtStart.Lon);
MapPoint.Latitude := FOrigins[I].Lat + (RPtEnd.Lat - RPtStart.Lat);
Inc(I); Inc(I);
end; end;
//FMapView.Invalidate; // No need to //FMapView.Invalidate; // No need to