LazMapViewer: New TextPositionHor and TextPositionVert properties of TGPS|MapPointOfInterest.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9569 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2025-01-07 18:18:26 +00:00
parent ee3135daf1
commit da08930f63
3 changed files with 56 additions and 1 deletions

View File

@ -129,6 +129,8 @@ type
FImageAnchorX: Single;
FImageAnchorY: Single;
FImageIndex: Integer;
FTextPositionHor: TTextPositionHor;
FTextPositionVert: TTextPositionVert;
public
constructor Create(ALon, ALat: Double; AElevation: Double = NO_ELE;
ADateTime: TDateTime = NO_DATE);
@ -136,6 +138,8 @@ type
property ImageAnchorX: Single read FImageAnchorX write FImageAnchorX;
property ImageAnchorY: Single read FImageAnchorY write FImageAnchorY;
property ImageIndex: Integer read FImageIndex write FImageIndex default -1;
property TextPositionHor: TTextPositionHor read FTextPositionHor write FTextPositionHor default tphCenter;
property TextPositionVert: TTextPositionVert read FTextPositionVert write FTextPositionVert default tpvBelow;
end;
{ TGPSPolyLine }
@ -1120,6 +1124,8 @@ begin
FImageAnchorX := 0.5;
FImageAnchorY := 1.0;
FImageIndex := -1;
FTextPositionHor := tphCenter;
FTextPositionVert := tpvBelow;
end;
procedure TGPSPointOfInterest.Draw(AView: TObject; Area: TRealArea);

View File

@ -325,12 +325,16 @@ type
private
FImageAnchor: Array[0..1] of Single;
FImageIndex: TImageIndex;
FTextPositionHor: TTextPositionHor;
FTextPositionVert: TTextPositionVert;
FOnDrawPoint: TMapPointOfInterestDrawEvent;
function GetImageAnchor(AIndex: Integer): Single;
function IsImageAnchorStored(AIndex: Integer): Boolean;
procedure SetImageAnchor(AIndex: Integer; AValue: Single);
procedure SetImageIndex(AValue: TImageIndex);
procedure SetOnDrawPoint(AValue: TMapPointOfInterestDrawEvent);
procedure SetTextPositionHor(AValue: TTextPositionHor);
procedure SetTextPositionVert(AValue: TTextPositionVert);
protected
procedure DrawPoint(Sender: TObject; {%H-}AGPSObj: TGPSObj; {%H-}AArea: TRealArea);
procedure ItemChanged; override;
@ -343,6 +347,8 @@ type
property ImageAnchorX: Single index 0 read GetImageAnchor write SetImageAnchor stored IsImageAnchorStored;
property ImageAnchorY: Single index 1 read GetImageAnchor write SetImageAnchor stored IsImageAnchorStored;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
property TextPositionHor: TTextPositionHor read FTextPositionHor write SetTextPositionHor default tphCenter;
property TextPositionVert: TTextPositionVert read FTextPositionVert write SetTextPositionVert default tpvBelow;
property OnDrawPoint: TMapPointOfInterestDrawEvent read FOnDrawPoint write SetOnDrawPoint;
end;
@ -1738,6 +1744,20 @@ begin
ItemChanged;
end;
procedure TMapPointOfInterest.SetTextPositionHor(AValue: TTextPositionHor);
begin
if FTextPositionHor = AValue then Exit;
FTextPositionHor := AValue;
ItemChanged;
end;
procedure TMapPointOfInterest.SetTextPositionVert(AValue: TTextPositionVert);
begin
if FTextPositionVert = AValue then Exit;
FTextPositionVert := AValue;
ItemChanged;
end;
procedure TMapPointOfInterest.DrawPoint(Sender: TObject; AGPSObj: TGPSObj;
AArea: TRealArea);
begin
@ -1750,6 +1770,8 @@ begin
TGPSPointOfInterest(FPoint).ImageIndex := FImageIndex;
TGPSPointOfInterest(FPoint).ImageAnchorX := FImageAnchor[0];
TGPSPointOfInterest(FPoint).ImageAnchorY := FImageAnchor[1];
TGPSPointOfInterest(FPoint).TextPositionHor := FTextPositionHor;
TGPSPointOfInterest(FPoint).TextPositionVert := FTextPositionVert;
inherited ItemChanged;
end;
@ -1759,6 +1781,8 @@ begin
TGPSPointOfInterest(Result).ImageIndex := FImageIndex;
TGPSPointOfInterest(Result).ImageAnchorX := FImageAnchor[0];
TGPSPointOfInterest(Result).ImageAnchorY := FImageAnchor[1];
TGPSPointOfInterest(Result).TextPositionHor := FTextPositionHor;
TGPSPointOfInterest(Result).TextPositionVert := FTextPositionVert;
Layer.ComboLayer.Add(Result, Pred(_TILELAYERS_ID_), Self.Index + BASE_Z_POI);
end;
@ -1774,6 +1798,8 @@ begin
FImageAnchor[0] := 0.5; // Anchor is a bottom center of icon
FImageAnchor[1] := 1.0;
FImageIndex := -1;
FTextPositionHor := tphCenter; // Text is centered below the point
FTextPositionVert := tpvBelow;
end;
procedure TMapPointOfInterest.AssignTo(Dest: TPersistent);
@ -1784,6 +1810,8 @@ begin
TMapPointOfInterest(Dest).ImageAnchorX := Self.ImageAnchorX;
TMapPointOfInterest(Dest).ImageAnchorY := Self.ImageAnchorY;
TMapPointOfInterest(Dest).ImageIndex := Self.ImageIndex;
TMapPointOfInterest(Dest).TextPositionHor := Self.TextPositionHor;
TMapPointOfInterest(Dest).TextPositionVert := Self.TextPositionVert;
end;
end;
@ -3138,12 +3166,15 @@ var
imgIndex: Integer = -1;
imgAnchorX: Double = 0.0;
imgAnchorY: Double = 0.0;
txtPosHor: TTextPositionHor = tphCenter;
txtPosVert: TTextPositionVert = tpvBelow;
savedOpacity: Single;
savedPen: TMvPen;
procedure DrawOne(P: TPoint);
const
SYMBOL_SIZE = 5;
TXT_DISTANCE = 5;
begin
// Draw as bitmap from ImageList...
if Assigned(bmp) then
@ -3168,7 +3199,20 @@ var
DrawingEngine.BrushStyle := bsSolid;
DrawingEngine.BrushColor := FPOITextBgColor;
end;
DrawingEngine.TextOut(P.X - txtExtent.CX div 2, P.Y + 5, txt);
// Text is at the left/centered/right of the GPS point...
case txtPosHor of
tphLeft: P.X := P.X - txtExtent.CX;
tphCenter: P.X := P.X - txtExtent.CX div 2;
tphRight: ;
end;
// ... and above/centered/below the GPS point
case txtPosVert of
tpvAbove: P.Y := P.Y - txtExtent.CY - TXT_DISTANCE;
tpvCenter: P.Y := P.Y - txtExtent.CY div 2;
tpvBelow: P.Y := P.Y + TXT_DISTANCE;
end;
DrawingEngine.TextOut(P.X, P.Y, txt);
end;
begin
@ -3185,6 +3229,8 @@ begin
imgIndex := TGpsPointOfInterest(APt).ImageIndex;
imgAnchorX := TGpsPointOfInterest(APt).ImageAnchorX;
imgAnchorY := TGpsPointOfInterest(APt).ImageAnchorY;
txtPosHor := TGpsPointOfInterest(APt).TextPositionHor;
txtPosVert := TGpsPointOfInterest(APt).TextPositionVert;
end;
savedOpacity := DrawingEngine.Opacity;

View File

@ -72,6 +72,9 @@ Type
Z: integer;
end;
TTextPositionHor = (tphLeft, tphCenter, tphRight);
TTextPositionVert = (tpvAbove, tpvCenter, tpvBelow);
function RealPoint(Lat, Lon: Double): TRealPoint;
// Call this to silence 'parameter is unused' hint