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