You've already forked lazarus-ccr
LazMapViewer: Center gpx track after loading.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6920 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
object MainForm: TMainForm
|
object MainForm: TMainForm
|
||||||
Left = 345
|
Left = 304
|
||||||
Height = 640
|
Height = 640
|
||||||
Top = 121
|
Top = 109
|
||||||
Width = 883
|
Width = 883
|
||||||
Caption = 'MainForm'
|
Caption = 'MainForm'
|
||||||
ClientHeight = 640
|
ClientHeight = 640
|
||||||
|
@ -195,22 +195,20 @@ end;
|
|||||||
procedure TMainForm.BtnLoadGPXFileClick(Sender: TObject);
|
procedure TMainForm.BtnLoadGPXFileClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
reader: TGpxReader;
|
reader: TGpxReader;
|
||||||
pt: TGpsPoint;
|
|
||||||
item: TGpsObj;
|
item: TGpsObj;
|
||||||
|
b: TRealArea;
|
||||||
|
pt: TRealPoint;
|
||||||
begin
|
begin
|
||||||
if OpenDialog.FileName <> '' then
|
if OpenDialog.FileName <> '' then
|
||||||
OpenDialog.InitialDir := ExtractFileDir(OpenDialog.Filename);
|
OpenDialog.InitialDir := ExtractFileDir(OpenDialog.Filename);
|
||||||
if OpenDialog.Execute then begin
|
if OpenDialog.Execute then begin
|
||||||
reader := TGpxReader.Create;
|
reader := TGpxReader.Create;
|
||||||
try
|
try
|
||||||
reader.LoadFromFile(OpenDialog.FileName, MapView.GPSItems);
|
reader.LoadFromFile(OpenDialog.FileName, MapView.GPSItems, b);
|
||||||
item := MapView.GPSItems.Items[MapView.GPSItems.Count-1];
|
item := MapView.GPSItems.Items[MapView.GPSItems.Count-1];
|
||||||
if item is TGpsPoint then
|
pt.Lon := (b.TopLeft.Lon + b.BottomRight.Lon) * 0.5;
|
||||||
pt := TGpsPoint(item)
|
pt.Lat := (b.TopLeft.Lat + b.BottomRight.Lat) * 0.5;
|
||||||
else
|
MapView.Center := pt;
|
||||||
if item is TGpsTrack then
|
|
||||||
pt := TGpsTrack(item).Points[0];
|
|
||||||
MapView.Center := pt.RealPoint;
|
|
||||||
finally
|
finally
|
||||||
reader.Free;
|
reader.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -14,6 +14,7 @@ type
|
|||||||
TGpxReader = class
|
TGpxReader = class
|
||||||
private
|
private
|
||||||
ID: Integer;
|
ID: Integer;
|
||||||
|
FMinLat, FMinLon, FMaxLat, FMaxLon: Double;
|
||||||
protected
|
protected
|
||||||
procedure ReadExtensions(ANode: TDOMNode; ATrack: TGpsTrack);
|
procedure ReadExtensions(ANode: TDOMNode; ATrack: TGpsTrack);
|
||||||
function ReadPoint(ANode: TDOMNode): TGpsPoint;
|
function ReadPoint(ANode: TDOMNode): TGpsPoint;
|
||||||
@ -23,14 +24,15 @@ type
|
|||||||
procedure ReadTrackSegment(ANode: TDOMNode; ATrack: TGpsTrack);
|
procedure ReadTrackSegment(ANode: TDOMNode; ATrack: TGpsTrack);
|
||||||
procedure ReadWayPoints(ANode: TDOMNode; AList: TGpsObjectList);
|
procedure ReadWayPoints(ANode: TDOMNode; AList: TGpsObjectList);
|
||||||
public
|
public
|
||||||
procedure LoadFromFile(AFileName: String; AList: TGpsObjectList);
|
procedure LoadFromFile(AFileName: String; AList: TGpsObjectList; out ABounds: TRealArea);
|
||||||
procedure LoadFromStream(AStream: TStream; AList: TGpsObjectList);
|
procedure LoadFromStream(AStream: TStream; AList: TGpsObjectList; out ABounds: TRealArea);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
|
Math,
|
||||||
mvExtraData;
|
mvExtraData;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -141,29 +143,37 @@ end;
|
|||||||
|
|
||||||
{ TGpxReader }
|
{ TGpxReader }
|
||||||
|
|
||||||
procedure TGpxReader.LoadFromFile(AFileName: String; AList: TGpsObjectList);
|
procedure TGpxReader.LoadFromFile(AFileName: String; AList: TGpsObjectList;
|
||||||
|
out ABounds: TRealArea);
|
||||||
var
|
var
|
||||||
stream: TStream;
|
stream: TStream;
|
||||||
begin
|
begin
|
||||||
stream := TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone);
|
stream := TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone);
|
||||||
try
|
try
|
||||||
LoadFromStream(stream, AList);
|
LoadFromStream(stream, AList, ABounds);
|
||||||
finally
|
finally
|
||||||
stream.Free;
|
stream.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGpxReader.LoadFromStream(AStream: TStream; AList: TGpsObjectList);
|
procedure TGpxReader.LoadFromStream(AStream: TStream; AList: TGpsObjectList;
|
||||||
|
out ABounds: TRealArea);
|
||||||
var
|
var
|
||||||
doc: TXMLDocument = nil;
|
doc: TXMLDocument = nil;
|
||||||
node: TDOMNode;
|
node: TDOMNode;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
ID := random(MaxInt - 1000) + 1000;
|
ID := random(MaxInt - 1000) + 1000;
|
||||||
|
FMinLon := 9999; FMinLat := 9999;
|
||||||
|
FMaxLon := -9999; FMaxLat := -9999;
|
||||||
ReadXMLFile(doc, AStream);
|
ReadXMLFile(doc, AStream);
|
||||||
ReadWayPoints(doc.DocumentElement.FindNode('wpt'), AList);
|
ReadWayPoints(doc.DocumentElement.FindNode('wpt'), AList);
|
||||||
ReadTracks(doc.DocumentElement.FindNode('trk'), AList);
|
ReadTracks(doc.DocumentElement.FindNode('trk'), AList);
|
||||||
ReadRoute(doc.DocumentElement.FindNode('rte'), AList);
|
ReadRoute(doc.DocumentElement.FindNode('rte'), AList);
|
||||||
|
ABounds.TopLeft.Lon := FMinLon;
|
||||||
|
ABounds.TopLeft.Lat := FMaxLat;
|
||||||
|
ABounds.BottomRight.Lon := FMaxLon;
|
||||||
|
ABounds.BottomRight.Lat := FMinLat;
|
||||||
finally
|
finally
|
||||||
doc.Free;
|
doc.Free;
|
||||||
end;
|
end;
|
||||||
@ -260,6 +270,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
Result := TGpsPoint.Create(lon, lat, ele, dt);
|
Result := TGpsPoint.Create(lon, lat, ele, dt);
|
||||||
Result.Name := sname;
|
Result.Name := sname;
|
||||||
|
FMinLon := Min(FMinLon, lon);
|
||||||
|
FMaxLon := Max(FMaxLon, lon);
|
||||||
|
FMinLat := Min(FMinLat, lat);
|
||||||
|
FMaxLat := Max(FMaxLat, lat);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGpxReader.ReadRoute(ANode: TDOMNode; AList: TGpsObjectlist);
|
procedure TGpxReader.ReadRoute(ANode: TDOMNode; AList: TGpsObjectlist);
|
||||||
|
Reference in New Issue
Block a user