LazMapViewer: Save gps points in demo and reload as a gps track.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6911 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
4a63d093a6
commit
505f61a073
@ -1,17 +1,17 @@
|
||||
object GPSListViewer: TGPSListViewer
|
||||
Left = 282
|
||||
Height = 352
|
||||
Height = 356
|
||||
Top = 135
|
||||
Width = 557
|
||||
Width = 753
|
||||
Caption = 'GPS points'
|
||||
ClientHeight = 352
|
||||
ClientWidth = 557
|
||||
ClientHeight = 356
|
||||
ClientWidth = 753
|
||||
LCLVersion = '2.1.0.0'
|
||||
object ListView: TListView
|
||||
Left = 6
|
||||
Height = 308
|
||||
Height = 312
|
||||
Top = 6
|
||||
Width = 545
|
||||
Width = 741
|
||||
Align = alClient
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
@ -41,13 +41,13 @@ object GPSListViewer: TGPSListViewer
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Height = 38
|
||||
Top = 314
|
||||
Width = 557
|
||||
Top = 318
|
||||
Width = 753
|
||||
Align = alBottom
|
||||
AutoSize = True
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 38
|
||||
ClientWidth = 557
|
||||
ClientWidth = 753
|
||||
TabOrder = 1
|
||||
object BtnDeletePoint: TBitBtn
|
||||
AnchorSideLeft.Control = BtnGoToPoint
|
||||
@ -152,7 +152,7 @@ object GPSListViewer: TGPSListViewer
|
||||
AnchorSideTop.Control = Panel1
|
||||
AnchorSideRight.Control = Panel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 476
|
||||
Left = 672
|
||||
Height = 26
|
||||
Top = 6
|
||||
Width = 75
|
||||
@ -213,5 +213,45 @@ object GPSListViewer: TGPSListViewer
|
||||
OnClick = BtnCalcDistanceClick
|
||||
TabOrder = 3
|
||||
end
|
||||
object BtnSavePts: TButton
|
||||
AnchorSideLeft.Control = BtnCalcDistance
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Panel1
|
||||
Left = 443
|
||||
Height = 25
|
||||
Top = 6
|
||||
Width = 86
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Save points'
|
||||
OnClick = BtnSavePtsClick
|
||||
TabOrder = 4
|
||||
end
|
||||
object BtnLoadTrack: TButton
|
||||
AnchorSideLeft.Control = BtnSavePts
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Panel1
|
||||
Left = 535
|
||||
Height = 25
|
||||
Top = 6
|
||||
Width = 81
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Load track'
|
||||
OnClick = BtnLoadTrackClick
|
||||
TabOrder = 5
|
||||
end
|
||||
end
|
||||
object SaveDialog: TSaveDialog
|
||||
DefaultExt = '.*.gps'
|
||||
Filter = 'GPS points (*.gps)|*.gps|All files (*.*)|*.*'
|
||||
left = 472
|
||||
top = 256
|
||||
end
|
||||
object OpenDialog: TOpenDialog
|
||||
DefaultExt = '.gps'
|
||||
Filter = 'GPS points (*.gps)|*.gps|All files (*.*)|*.*'
|
||||
left = 560
|
||||
top = 256
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,7 @@ uses
|
||||
const
|
||||
// IDs of GPS items
|
||||
_CLICKED_POINTS_ = 10;
|
||||
_TRACK_POINTS_ = 20;
|
||||
|
||||
type
|
||||
|
||||
@ -21,12 +22,18 @@ type
|
||||
BtnGoToPoint: TBitBtn;
|
||||
BtnClose: TBitBtn;
|
||||
BtnCalcDistance: TButton;
|
||||
BtnSavePts: TButton;
|
||||
BtnLoadTrack: TButton;
|
||||
ListView: TListView;
|
||||
OpenDialog: TOpenDialog;
|
||||
Panel1: TPanel;
|
||||
SaveDialog: TSaveDialog;
|
||||
procedure BtnCalcDistanceClick(Sender: TObject);
|
||||
procedure BtnCloseClick(Sender: TObject);
|
||||
procedure BtnDeletePointClick(Sender: TObject);
|
||||
procedure BtnGoToPointClick(Sender: TObject);
|
||||
procedure BtnSavePtsClick(Sender: TObject);
|
||||
procedure BtnLoadTrackClick(Sender: TObject);
|
||||
private
|
||||
FViewer: TMapView;
|
||||
FList: TGpsObjList;
|
||||
@ -78,7 +85,6 @@ begin
|
||||
for i:=0 to FList.Count-1 do begin
|
||||
gpsObj := FList[i];
|
||||
item := ListView.Items.Add;
|
||||
// item.Caption := IntToStr(gpsObj.ID);
|
||||
if gpsObj is TGpsPoint then begin
|
||||
item.SubItems.Add(gpsObj.Name);
|
||||
item.Subitems.Add(LatToStr(TGpsPoint(gpsObj).Lat, true));
|
||||
@ -86,7 +92,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
ListView.items.EndUpdate;
|
||||
ListView.Items.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -177,6 +183,90 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TGPSListViewer.BtnSavePtsClick(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
gpsPt: TGpsPoint;
|
||||
gpsObj: TGpsObj;
|
||||
L: TStrings;
|
||||
s: String;
|
||||
begin
|
||||
if (OpenDialog.FileName <> '') and (SaveDialog.FileName = '') then
|
||||
SaveDialog.FileName := OpenDialog.FileName;
|
||||
if SaveDialog.FileName <> '' then
|
||||
SaveDialog.InitialDir := ExtractFileDir(SaveDialog.FileName);
|
||||
if not SaveDialog.Execute then exit;
|
||||
|
||||
L := TStringList.Create;
|
||||
try
|
||||
s := 'Index'#9'Name'#9'Longitude'#9'Latitude';
|
||||
L.Add(s);
|
||||
for i:=0 to FList.Count-1 do begin
|
||||
gpsObj := FList[i];
|
||||
if gpsObj is TGpsPoint then begin
|
||||
gpsPt := TGpsPoint(gpsObj);
|
||||
s := Format('%d'#9'%s'#9'%s'#9'%s', [
|
||||
i, gpsPt.Name, LonToStr(gpsPt.Lon, true), LatToStr(gpsPt.Lat, true)
|
||||
]);
|
||||
L.Add(s);
|
||||
end;
|
||||
L.SaveToFile(SaveDialog.FileName);
|
||||
end;
|
||||
finally
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TGPSListViewer.BtnLoadTrackClick(Sender: TObject);
|
||||
var
|
||||
L: TStrings;
|
||||
gpsTrack: TGpsTrack;
|
||||
gpsPt: TGpsPoint;
|
||||
sa: TStringArray;
|
||||
lon, lat: Double;
|
||||
i: Integer;
|
||||
item: TListItem;
|
||||
begin
|
||||
if (SaveDialog.FileName <> '') and (OpenDialog.FileName = '') then
|
||||
OpenDialog.FileName := SaveDialog.FileName;
|
||||
if OpenDialog.FileName <> '' then
|
||||
OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
|
||||
if not OpenDialog.Execute then exit;
|
||||
|
||||
gpsTrack := TGpsTrack.Create;
|
||||
L := TStringList.Create;
|
||||
try
|
||||
L.LoadFromFile(OpenDialog.FileName);
|
||||
for i := 1 to L.Count - 1 do begin // i=1 --> skip header line
|
||||
if L[i] = '' then Continue;
|
||||
sa := L[i].Split(#9);
|
||||
if TryStrToGps(sa[2], lon) and TryStrToGps(sa[3], lat) then begin
|
||||
gpsPt := TGpsPoint.Create(lon, lat);
|
||||
gpsPt.Name := sa[1];
|
||||
gpsTrack.Points.Add(gpsPt);
|
||||
end;
|
||||
end;
|
||||
FViewer.GPSItems.Add(gpsTrack, _TRACK_POINTS_);
|
||||
FViewer.Center := gpsPt.RealPoint;
|
||||
finally
|
||||
L.Free;
|
||||
end;
|
||||
|
||||
ListView.Items.BeginUpdate;
|
||||
try
|
||||
ListView.Items.Clear;
|
||||
for i:=0 to gpsTrack.Points.Count - 1 do begin
|
||||
gpsPt := gpsTrack.Points[i];
|
||||
item := ListView.Items.Add;
|
||||
item.SubItems.Add(gpsPt.Name);
|
||||
item.SubItems.Add(LatToStr(gpsPt.Lat, true));
|
||||
item.SubItems.Add(LonToStr(gpsPt.Lon, true));
|
||||
end;
|
||||
finally
|
||||
ListView.Items.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TGPSListViewer.SetViewer(AValue: TMapView);
|
||||
begin
|
||||
if FViewer = AValue then
|
||||
|
@ -63,7 +63,7 @@ type
|
||||
function GetLat: Double;
|
||||
function GetLon: Double;
|
||||
public
|
||||
constructor Create(ALon,ALat : double;AEle : double=NO_ELE;ADateTime : TDateTime=NO_DATE);
|
||||
constructor Create(ALon,ALat: double; AEle: double=NO_ELE; ADateTime: TDateTime=NO_DATE);
|
||||
class function CreateFrom(aPt: TRealPoint): TGPSPoint;
|
||||
|
||||
procedure GetArea(out Area: TRealArea);override;
|
||||
|
@ -64,7 +64,7 @@ Type
|
||||
procedure DoAsyncInvalidate({%H-}Data: PtrInt);
|
||||
procedure DrawObjects(const {%H-}TileId: TTileId; aLeft, aTop, aRight,aBottom: integer);
|
||||
procedure DrawPt(const {%H-}Area: TRealArea;aPOI: TGPSPoint);
|
||||
procedure DrawTrack(const Area: TRealArea;trk: TGPSTrack);
|
||||
procedure DrawTrack(const Area: TRealArea; trk: TGPSTrack);
|
||||
function GetCacheOnDisk: boolean;
|
||||
function GetCachePath: String;
|
||||
function GetCenter: TRealPoint;
|
||||
|
Loading…
Reference in New Issue
Block a user