LazMapViewer: Add new properties LineColor and LineWidth to TGpsTrack. Add demo showing several individually colored tracks. Add some utility functions.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8102 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-09-29 15:11:12 +00:00
parent 68da1ac936
commit 9fcf5de570
12 changed files with 14439 additions and 12 deletions

View File

@ -169,8 +169,10 @@ function RealPoint(Lat, Lon: Double): TRealPoint;
function CalcGeoDistance(Lat1, Lon1, Lat2, Lon2: double;
AUnits: TDistanceUnits = duKilometers): double;
function DMSToDeg(Deg, Min: Word; Sec: Double): Double;
function GPSToDMS(Angle: Double): string;
function LatToStr(ALatitude: Double; DMS: Boolean): String;
function LonToStr(ALongitude: Double; DMS: Boolean): String;
function TryStrToGps(const AValue: String; out ADeg: Double): Boolean;
@ -1498,5 +1500,12 @@ begin
end;
end;
{ Converts an angle given as degrees, minutes and seconds to a single
floating point degrees value. }
function DMSToDeg(Deg, Min: Word; Sec: Double): Double;
begin
Result := Deg + Min/60.0 + Sec/3600.0;
end;
end.

View File

@ -16,7 +16,7 @@ unit mvGpsObj;
interface
uses
Classes, SysUtils,fgl,mvtypes,contnrs,syncobjs;
Classes, SysUtils, Graphics, fgl, mvtypes, contnrs, syncobjs;
const
NO_ELE = -10000000;
@ -87,6 +87,9 @@ type
private
FDateTime: TDateTime;
FPoints: TGPSPointList;
FLineWidth: Double; // Line width in mm
FLineColor: TColor;
FVisible: Boolean;
function GetDateTime: TDateTime;
public
constructor Create;
@ -97,6 +100,9 @@ type
property Points: TGPSPointList read FPoints;
property DateTime: TDateTime read GetDateTime write FDateTime;
property LineColor: TColor read FLineColor write FLineColor;
property Visible: Boolean read FVisible write FVisible;
property LineWidth: Double read FLineWidth write FLineWidth;
end;
TGPSObjList_ = specialize TFPGObjectList<TGPSObj>;
@ -144,6 +150,7 @@ type
function Add(aItem: TGpsObj; AIdOwner: integer): integer;
procedure DeleteById(const Ids: Array of integer);
function FindTrackByID(const id: Integer): TGpsTrack;
procedure BeginUpdate;
procedure EndUpdate;
@ -645,6 +652,19 @@ begin
end;
end;
function TGPSObjectList.FindTrackByID(const ID: Integer): TGpsTrack;
var
i: Integer;
begin
for i:=0 to pred(FItems.Count) do
if (ID = FItems[i].IdOwner) and (FItems[i] is TGpsTrack) then
begin
Result := TGpsTrack(FItems[i]);
exit;
end;
Result := nil;
end;
{ TGPSTrack }
@ -662,6 +682,9 @@ constructor TGPSTrack.Create;
begin
inherited;
FPoints := TGPSPointList.Create(true);
FVisible := true;
FLineColor := clDefault; // --> use MapView.DefaultTrackColor
FLineWidth := -1; // --> use MapView.DefaultTrackWidth
end;
destructor TGPSTrack.Destroy;

View File

@ -33,7 +33,9 @@ type
procedure ReadTrackSegment(ANode: TDOMNode; ATrack: TGpsTrack);
procedure ReadWayPoints(ANode: TDOMNode; AList: TGpsObjectList);
public
function LoadFromFile(AFileName: String; AList: TGpsObjectList): Integer;
function LoadFromFile(AFileName: String; AList: TGpsObjectList; out ABounds: TRealArea): Integer;
function LoadFromStream(AStream: TStream; AList: TGpsObjectList): Integer;
function LoadFromStream(AStream: TStream; AList: TGpsObjectList; out ABounds: TRealArea): Integer;
end;
@ -83,6 +85,7 @@ begin
mn := 10*NUMBER[M[0]] + NUMBER[M[1]];
sec := 10*NUMBER[S[0]] + NUMBER[S[1]];
s1000 := 100*NUMBER[MS[0]] + 10*NUMBER[MS[1]] + NUMBER[MS[2]];
if (s1000 < 0) or (s1000 > 1000) then s1000 := 0;
end;
Result := EncodeDate(yr, mon, dy) + EncodeTime(hr, mn, sec, s1000);
end else
@ -166,6 +169,13 @@ begin
end;
end;
function TGpxReader.LoadFromFile(AFileName: String; AList: TGpsObjectList): Integer;
var
area: TRealArea;
begin
Result := LoadFromFile(AFileName, AList, area);
end;
{ See LoadFromFile. }
function TGpxReader.LoadFromStream(AStream: TStream; AList: TGpsObjectList;
out ABounds: TRealArea): Integer;
@ -190,6 +200,13 @@ begin
end;
end;
function TGpxReader.LoadFromStream(AStream: TStream; AList: TGpsObjectList): Integer;
var
area: TRealArea;
begin
Result := LoadFromStream(AStream, AList, area);
end;
procedure TGpxReader.ReadExtensions(ANode: TDOMNode; ATrack: TGpsTrack);
var
linenode: TDOMNode;

View File

@ -166,6 +166,13 @@ uses
GraphType, Types,
mvJobQueue, mvExtraData, mvDLEFpc, mvDE_IntfGraphics;
{ Converts a length given in millimeters to screen pixels }
function mmToPx(AValue: Double): Integer;
begin
Result := round(AValue / 25.4 * ScreenInfo.PixelsPerInchX);
end;
type
{ TDrawObjJob }
@ -575,18 +582,27 @@ var
trkColor: TColor;
trkWidth: Integer;
begin
if trk.Points.Count > 0 then
if trk.Visible and (trk.Points.Count > 0) then
begin
trkColor := ColorToRGB(FDefaultTrackColor);
trkWidth := FDefaultTrackWidth;
if trk.ExtraData <> nil then
// Determine track color
if trk.LineColor = clDefault then
begin
if trk.ExtraData.InheritsFrom(TDrawingExtraData) then
trkColor := ColorToRGB(FDefaultTrackColor);
if (trk.ExtraData <> nil) and trk.ExtraData.InheritsFrom(TDrawingExtraData) then
trkColor := TDrawingExtraData(trk.ExtraData).Color;
if trk.ExtraData.InheritsFrom(TTrackExtraData) then
trkWidth := round(ScreenInfo.PixelsPerInchX * TTrackExtraData(trk.ExtraData).Width / 25.4);
end;
end else
trkColor := ColorToRGB(trk.LineColor);
// Determine track width
if trk.LineWidth = -1 then
begin
trkWidth := FDefaultTrackWidth;
if (trk.ExtraData <> nil) and trk.ExtraData.InheritsFrom(TTrackExtraData) then
trkWidth := mmToPx(TTrackExtraData(trk.ExtraData).Width);
end else
trkWidth := mmToPx(trk.LineWidth);
if trkWidth < 1 then trkWidth := 1;
LastInside := false;
DrawingEngine.PenColor := trkColor;
DrawingEngine.PenWidth := trkWidth;