LazMapViewer: Update object tree with tracks/pois loaded as gpx from layer editor.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9558 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
72bb393e2f
commit
6c1f27b048
components/lazmapviewer/source
@ -123,7 +123,7 @@ begin
|
||||
Tzd := 0.0 // TZD is zero
|
||||
|
||||
// Check TZD
|
||||
else if ((L - I) in [2,4,5]) and (S[I] in ['+', '-']) then
|
||||
else if (ShortInt(L - I) in [2,4,5]) and (S[I] in ['+', '-']) then
|
||||
begin
|
||||
if S[I] = '-' then Sg := -1 else Sg := 1;
|
||||
case (L - I) of
|
||||
|
@ -6,7 +6,9 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
|
||||
ComCtrls, ActnList, CollectionPropEditForm, mvMapViewer, mvGpsObj, mvTypes;
|
||||
ComCtrls, ActnList,
|
||||
PropEdits, IDEImagesIntf, ComponentEditors, CollectionPropEditForm,
|
||||
mvMapViewer, mvGpsObj, mvGPX, mvTypes;
|
||||
|
||||
type
|
||||
|
||||
@ -39,11 +41,6 @@ var
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
PropEdits, IDEImagesIntf,
|
||||
mvGPX;
|
||||
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TLayersPropertyEditForm }
|
||||
@ -69,8 +66,12 @@ var
|
||||
begin
|
||||
if not Assigned(Collection) then
|
||||
Exit;
|
||||
|
||||
I := CollectionListBox.ItemIndex;
|
||||
L := Collection.Items[I] as TMapLayer;
|
||||
if I = -1 then
|
||||
L := Collection.Add as TMapLayer
|
||||
else
|
||||
L := Collection.Items[I] as TMapLayer;
|
||||
with TOpenDialog.Create(Nil) do
|
||||
try
|
||||
DefaultExt := '.gpx';
|
||||
@ -135,16 +136,47 @@ end;
|
||||
|
||||
procedure TLayersPropertyEditForm.LoadFromFile(AFileName: String;
|
||||
ALayer: TMapLayer);
|
||||
const
|
||||
DO_NOT_CLEAR = false;
|
||||
var
|
||||
List: TGpsObjectList;
|
||||
LBounds: TRealArea;
|
||||
tracks, pois: TFPList;
|
||||
T: TMapTrack;
|
||||
P: TMapPoint;
|
||||
begin
|
||||
with TGpxReader.Create do
|
||||
try
|
||||
List := TGPSObjectList.Create;
|
||||
try
|
||||
LoadFromFile(AFileName, List, LBounds);
|
||||
ALayer.AssignFromGPSList(List);
|
||||
|
||||
// Update the object tree
|
||||
tracks := TFPList.Create;
|
||||
pois := TFPList.Create;
|
||||
try
|
||||
ALayer.AssignFromGPSList(List, DO_NOT_CLEAR, tracks, pois);
|
||||
if GlobalDesignHook <> nil then
|
||||
begin
|
||||
// Add the track and its points to the object tree
|
||||
// (significant speed-up by explicitely adding only the last track point)
|
||||
if tracks.Count > 0 then
|
||||
begin
|
||||
T := TMapTrack(tracks[tracks.Count-1]);
|
||||
if T.Points.Count > 0 then
|
||||
GlobalDesignHook.PersistentAdded(TMapTrackPoint(T.Points[T.Points.Count-1]), false);
|
||||
end;
|
||||
// Add the last map point to the object tree.
|
||||
if pois.Count > 0 then
|
||||
begin
|
||||
P := TMapPoint(pois[pois.Count-1]);
|
||||
GlobalDesignHook.PersistentAdded(P, false);
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
pois.Free;
|
||||
tracks.Free;
|
||||
end;
|
||||
finally
|
||||
List.Free;
|
||||
end;
|
||||
|
@ -192,6 +192,8 @@ type
|
||||
function HitTest(constref Area: TRealArea): TMapObjectList; override;
|
||||
function AddPointOfInterest(APoint: TRealPoint; ACaption: String = ''): TMapPointOfInterest;
|
||||
procedure AssignFromGPSList(AList: TGPSObjectList);
|
||||
procedure AssignFromGPSList(AList: TGPSObjectList;
|
||||
AClear: Boolean; ATracks, APoints: TFPList);
|
||||
property ComboLayer: TGPSComboLayer read FComboLayer;
|
||||
published
|
||||
property MapProvider: String read GetMapProvider write SetMapProvider;
|
||||
@ -1953,11 +1955,19 @@ begin
|
||||
Result.Caption := ACaption;
|
||||
end;
|
||||
|
||||
procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList);
|
||||
{ Creates MapPoints and MapTracks from the objects in AList. When AClear is true,
|
||||
the internal collections are cleared first.
|
||||
The created MapPoints and MapTracks are stored in the specified
|
||||
APoints and ATracks lists - they are needed at designtime. }
|
||||
procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList; AClear: Boolean;
|
||||
ATracks, APoints: TFPList);
|
||||
|
||||
procedure AddPoint(APoint: TGPSPoint);
|
||||
var
|
||||
P: TMapPoint;
|
||||
begin
|
||||
with PointsOfInterest.Add as TMapPoint do
|
||||
P := PointsOfInterest.Add as TMapPoint;
|
||||
with P do
|
||||
begin
|
||||
Caption := APoint.Name;
|
||||
Longitude := APoint.Lon;
|
||||
@ -1965,14 +1975,18 @@ procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList);
|
||||
Elevation := APoint.Elevation;
|
||||
DateTime := APoint.DateTime;
|
||||
end;
|
||||
if Assigned(APoints) then
|
||||
APoints.Add(P);
|
||||
end;
|
||||
|
||||
procedure AddTrack(ATrack: TGPSTrack);
|
||||
var
|
||||
I: Integer;
|
||||
P: TGPSPoint;
|
||||
T: TMapTrack;
|
||||
begin
|
||||
with Tracks.Add as TMapTrack do
|
||||
T := Tracks.Add as TMapTrack;
|
||||
with T do
|
||||
begin
|
||||
Caption := ATrack.Name;
|
||||
for I := 0 to Pred(ATrack.Points.Count) do
|
||||
@ -1993,6 +2007,8 @@ procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList);
|
||||
LineColor := TTrackExtraData(ATrack.ExtraData).Color;
|
||||
end;
|
||||
end;
|
||||
if Assigned(ATracks) then
|
||||
ATracks.Add(T);
|
||||
end;
|
||||
|
||||
var
|
||||
@ -2000,8 +2016,13 @@ var
|
||||
begin
|
||||
if not Assigned(AList) then
|
||||
Exit;
|
||||
PointsOfInterest.Clear;
|
||||
Tracks.Clear;
|
||||
|
||||
if AClear then
|
||||
begin
|
||||
PointsOfInterest.Clear;
|
||||
Tracks.Clear;
|
||||
end;
|
||||
|
||||
for I := 0 to Pred(AList.Count) do
|
||||
if AList[I] is TGPSPoint then
|
||||
AddPoint(TGPSPoint(AList[I]))
|
||||
@ -2011,6 +2032,12 @@ begin
|
||||
{TODO};
|
||||
end;
|
||||
|
||||
procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList);
|
||||
begin
|
||||
AssignFromGPSList(AList, true, nil, nil);
|
||||
end;
|
||||
|
||||
|
||||
{ TMapLayers }
|
||||
|
||||
function TMapLayers.GetView: TMapView;
|
||||
|
Loading…
Reference in New Issue
Block a user