LazMapViewer: Rehaul of TMapItem/TMapCollection, TMapTrack, TMapTrackPoint, TMapTrackPoints. TTrackSegmentExtraData added.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9289 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alpine-a110 2024-03-28 13:45:53 +00:00
parent b651135f37
commit 6a13ae7fb3
6 changed files with 541 additions and 202 deletions

View File

@ -39,9 +39,29 @@ type
property Width: Double read FWidth write SetWidth; // Line width in mm
end;
{ TTrackSegmentExtraData }
TTrackSegmentExtraData = class(TObject)
public
type TSegmentMark = (smNone, smStart, smMid, smEnd);
private
FMark: TSegmentMark;
public
constructor Create(AMark: TSegmentMark);
property Mark: TSegmentMark read FMark write FMark;
end;
implementation
{ TTrackSegmentExtraData }
constructor TTrackSegmentExtraData.Create(AMark: TSegmentMark);
begin
inherited Create;
FMark := AMark;
end;
{ TDrawingExtraData }
constructor TDrawingExtraData.Create(aId: integer);

View File

@ -27,6 +27,30 @@ type
TGPSObj = class;
TGPSObjClass = class of TGPSObj;
TGPSObjList_ = specialize TFPGObjectList<TGPSObj>;
{ TGPSObjList }
TGPSObjList = class(TGPSObjList_)
private
FRef: TObject;
public
destructor Destroy; override;
end;
{ TGPSObjEnumerator }
TGPSObjEnumerator = class
private
function GetCurrent: TGPSObj; virtual; abstract;
public
function GetEnumerator: TGPSObjEnumerator;
function MoveNext: Boolean; virtual; abstract;
property Current: TGPSObj read GetCurrent;
end;
{ TGPSObjDrawEvent }
TGPSObjDrawEvent = procedure(Sender: TObject; AGPSObj: TGPSObj;
AArea: TRealArea) of object;
@ -42,6 +66,7 @@ type
FVisible: Boolean;
FZOrder: Integer;
function GetBoundingBox: TRealArea;
function GetAllObjs: TGPSObjEnumerator; virtual;
procedure SetExtraData(AValue: TObject);
public
constructor Create;
@ -55,6 +80,7 @@ type
property BoundingBox: TRealArea read GetBoundingBox;
property ZOrder: Integer read FZOrder;
property Visible: Boolean read FVisible write FVisible;
property AllObjs: TGPSObjEnumerator read GetAllObjs;
property OnDrawObj: TGPSObjDrawEvent read FOnDrawObj write FOnDrawObj;
end;
@ -112,6 +138,7 @@ type
TGPSPolyLine = class(TGPSObj)
private
FPoints: TGPSPointList;
function GetAllObjs: TGPSObjEnumerator; override;
public
constructor Create;
destructor Destroy; override;
@ -154,17 +181,6 @@ type
property LineWidth: Double read FLineWidth write FLineWidth;
end;
TGPSObjList_ = specialize TFPGObjectList<TGPSObj>;
{ TGPSObjList }
TGPSObjList = class(TGPSObjList_)
private
FRef: TObject;
public
destructor Destroy; override;
end;
{ TGPSObjectList }
TModifiedEvent = procedure (Sender: TObject; objs: TGPSObjList;
@ -180,6 +196,7 @@ type
FItems: TGPSObjList;
function GetCount: integer;
function GetItem(AIndex: Integer): TGpsObj;
function GetAllObjs: TGPSObjEnumerator; override;
protected
procedure _Delete(Idx: Integer; var DelLst: TGPSObjList);
procedure FreePending;
@ -232,6 +249,24 @@ implementation
uses
mvExtraData, mvMapViewer, Math;
type
{ TGPSObjEnumeratorFrom }
generic TGPSObjEnumeratorFrom<T: Class> = class(TGPSObjEnumerator)
private
type
TItemClass = T;
TOwnerListClass = specialize TFPGObjectList<T>;
private
FList: TOwnerListClass;
FCurrent: TItemClass;
FIndex: Integer;
function GetCurrent: TGPSObj; override;
public
constructor Create(AList: TOwnerListClass);
function MoveNext: Boolean; override;
end;
function GoingEast(Lon1, Lon2: Double): Boolean;
begin
// Assume the shortest path (<180 deg)
@ -277,6 +312,34 @@ begin
end;
end;
{ TGPSObjEnumeratorFrom }
function TGPSObjEnumeratorFrom.GetCurrent: TGPSObj;
begin
Result := FCurrent;
end;
constructor TGPSObjEnumeratorFrom.Create(AList: TOwnerListClass);
begin
FList := AList;
FIndex := -1;
end;
function TGPSObjEnumeratorFrom.MoveNext: Boolean;
begin
Inc(FIndex);
Result := FIndex < FList.Count;
if Result then
FCurrent := FList[FIndex];
end;
{ TGPSObjEnumerator }
function TGPSObjEnumerator.GetEnumerator: TGPSObjEnumerator;
begin
Result := Self;
end;
{ TGPSArea }
constructor TGPSArea.Create;
@ -294,6 +357,11 @@ end;
{ TGPSPolyLine }
function TGPSPolyLine.GetAllObjs: TGPSObjEnumerator;
begin
Result := specialize TGPSObjEnumeratorFrom<TGPSPoint>.Create(FPoints);
end;
constructor TGPSPolyLine.Create;
begin
inherited;
@ -366,6 +434,11 @@ begin
Result := A;
end;
function TGPSObj.GetAllObjs: TGPSObjEnumerator;
begin
Result := Nil;
end;
destructor TGPSObj.Destroy;
begin
FreeAndNil(FExtraData);
@ -486,6 +559,11 @@ begin
SetLength(objs, nb);
end;
function TGPSObjectList.GetAllObjs: TGPSObjEnumerator;
begin
Result := specialize TGPSObjEnumeratorFrom<TGPSObj>.Create(FItems);
end;
procedure TGPSObjectList.GetArea(out Area: TRealArea);
var
i: integer;

View File

@ -518,18 +518,20 @@ end;
procedure TGpxReader.ReadTrackSegment(ANode: TDOMNode; ATrack: TGpsTrack);
var
gpsPt: TGpsPoint;
gpsPt: TGpsPoint = Nil;
nodeName: String;
begin
while ANode <> nil do begin
nodeName := ANode.NodeName;
if nodeName = 'trkpt' then begin
gpsPt := ReadPoint(ANode);
if gpsPt <> nil then
if gpsPt <> Nil then
ATrack.Points.Add(gpsPt);
end;
ANode := ANode.NextSibling;
end;
if Assigned(gpsPt) then // Mark the last point of the segment
gpsPt.ExtraData := TTrackSegmentExtraData.Create(smEnd);
end;
procedure TGpxReader.ReadWayPoints(ANode: TDOMNode; AList: TGpsObjectList);

View File

@ -48,6 +48,9 @@ const
type
TMapView = class;
TMapPoint = class;
TMapLayer = class;
TMapLayers = class;
TPointOfInterest = class;
TPointsOfInterest = class;
TMapTrack = class;
@ -58,17 +61,37 @@ type
TPointOfInterestDrawEvent = procedure(Sender: TObject;
ADrawer: TMvCustomDrawingEngine; APoint: TPointOfInterest) of object;
TMapTrackDrawEvent = procedure(Sender: TObject;
ADrawer: TMvCustomDrawingEngine; ATrack: TMapTrack) of object;
{ TMapCollectionBase }
TMapCollectionBase = class(TOwnedCollection)
protected
function GetView: TMapView; virtual;
function GetLayer: TMapLayer; virtual;
procedure FixOrder(APrevIndex, AIndex: Integer); virtual;
procedure Update(Item: TCollectionItem); override;
public
property View: TMapView read GetView;
property Layer: TMapLayer read GetLayer;
end;
{ TMapCollection }
generic TMapCollection<T, OT: class> = class(TOwnedCollection)
generic TMapCollection<T, OT: class> = class(TMapCollectionBase)
private
FMCOwner: OT;
function GetItems(Index: Integer): T;
procedure SetItems(Index: Integer; AValue: T);
type
TItemClass = T;
TOwnerClass = OT;
private
FMCOwner: TOwnerClass;
function GetItems(Index: Integer): TItemClass;
procedure SetItems(Index: Integer; AValue: TItemClass);
public
constructor Create(AOwner: OT);
property MCOwner: OT read FMCOwner;
property Items[Index: Integer]: T read GetItems write SetItems; default;
property MCOwner: TOwnerClass read FMCOwner;
property Items[Index: Integer]: TItemClass read GetItems write SetItems; default;
end;
{ TMapItem }
@ -78,11 +101,19 @@ type
FCaption: TCaption;
FTag: PtrInt;
FVisible: Boolean;
function GetGPSObj: TGPSObj; virtual; abstract;
function GetView: TMapView; virtual;
function GetLayer: TMapLayer; virtual;
procedure SetCaption(AValue: TCaption);
procedure SetVisible(AValue: Boolean);
protected
function GetDisplayName: string; override;
procedure ItemChanged; virtual; abstract;
procedure SetIndex(Value: Integer); override;
public
property View: TMapView read GetView;
property Layer: TMapLayer read GetLayer;
PROPERTY GPSObj: TGPSObj read GetGPSObj;
published
property Caption: TCaption read FCaption write SetCaption;
property Visible: Boolean read FVisible write SetVisible default True;
@ -92,7 +123,7 @@ type
{ TMapLayer }
TMapLayer = class(TMapItem)
private
strict private
FComboLayer: TGPSComboLayer;
FDrawMode: TItemDrawMode;
FUseThreads: Boolean;
@ -100,8 +131,11 @@ type
FOpacity: Single;
FPointsOfInterest: TPointsOfInterest;
FTracks: TMapTracks;
private
function GetGPSObj: TGPSObj; override;
function GetView: TMapView; override;
function GetLayer: TMapLayer; override;
function GetMapProvider: String;
function GetMapView: TMapView;
function GetPointsOfInterest: TPointsOfInterest;
function GetTracks: TMapTracks;
function GetUseThreads: Boolean;
@ -112,13 +146,11 @@ type
procedure SetTracks(AValue: TMapTracks);
procedure SetUseThreads(AValue: Boolean);
protected
procedure SetIndex(Value: Integer); override;
procedure ItemChanged; override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
procedure AssignFromGPSList(AList: TGPSObjectList);
property MapView: TMapView read GetMapView;
property ComboLayer: TGPSComboLayer read FComboLayer;
published
property MapProvider: String read GetMapProvider write SetMapProvider;
@ -132,9 +164,8 @@ type
{ TMapLayers }
TMapLayers = class(specialize TMapCollection<TMapLayer, TMapView>)
protected
procedure Update(Item: TCollectionItem); override;
procedure FixOrder(APrevIndex, AIndex: Integer);
function GetView: TMapView; override;
function GetLayer: TMapLayer; override;
end;
{ TMapCenter }
@ -158,43 +189,71 @@ type
property Latitude: Double read FLatitude write SetLatitude;
end;
{ TPointOfInterest }
{ TMapPoint }
TPointOfInterest = class(TMapItem)
TMapPoint = class(TMapItem)
private
FDateTime: TDateTime;
FElevation: Double;
FImageIndex: TImageIndex;
FLatitude: Double;
FLongitude: Double;
FOnDrawPoint: TPointOfInterestDrawEvent;
FPoint: TGPSPointOfInterest;
FPoint: TGPSPoint;
function GetLatLonInDMS: Boolean;
function GetLayer: TMapLayer;
function GetMapView: TMapView;
function IsDateTimeStored: Boolean;
function IsElevationStored: Boolean;
procedure SetDateTime(AValue: TDateTime);
procedure SetElevation(AValue: Double);
procedure SetImageIndex(AValue: TImageIndex);
procedure SetLatitude(AValue: Double);
procedure SetLongitude(AValue: Double);
procedure SetOnDrawPoint(AValue: TPointOfInterestDrawEvent);
function GetGPSObj: TGPSObj; override;
protected
procedure SetIndex(Value: Integer); override;
procedure ItemChanged; override;
procedure DrawPoint(Sender: TObject; AGPSObj: TGPSObj; AArea: TRealArea);
function CreatePoint: TGPSPoint; virtual;
procedure DestroyPoint; virtual;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
property MapView: TMapView read GetMapView;
property Layer: TMapLayer read GetLayer;
property LatLonInDMS: Boolean read GetLatLonInDMS;
published
property Longitude: Double read FLongitude write SetLongitude;
property Latitude: Double read FLatitude write SetLatitude;
property Elevation: Double read FElevation write SetElevation stored IsElevationStored;
property DateTime: TDateTime read FDateTime write SetDateTime stored IsDateTimeStored;
end;
{ TMapTrackPoint }
TMapTrackPoint = class(TMapPoint)
protected
function GPSTrack: TGPSTrack;
function CreatePoint: TGPSPoint; override;
procedure DestroyPoint; override;
end;
{ TMapTrackPoints }
TMapTrackPoints = class(specialize TMapCollection<TMapTrackPoint, TMapTrack>)
protected
function GetLayer: TMapLayer; override;
procedure FixOrder(APrevIndex, AIndex: Integer); override;
end;
{ TPointOfInterest }
TPointOfInterest = class(TMapPoint)
private
FImageIndex: TImageIndex;
FOnDrawPoint: TPointOfInterestDrawEvent;
procedure SetImageIndex(AValue: TImageIndex);
procedure SetOnDrawPoint(AValue: TPointOfInterestDrawEvent);
protected
procedure DrawPoint(Sender: TObject; AGPSObj: TGPSObj; AArea: TRealArea);
procedure ItemChanged; override;
function CreatePoint: TGPSPoint; override;
procedure DestroyPoint; override;
public
constructor Create(ACollection: TCollection); override;
published
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
property OnDrawPoint: TPointOfInterestDrawEvent read FOnDrawPoint write SetOnDrawPoint;
end;
@ -203,8 +262,7 @@ type
TPointsOfInterest = class(specialize TMapCollection<TPointOfInterest, TMapLayer>)
protected
procedure Update(Item: TCollectionItem); override;
procedure FixOrder(APrevIndex, AIndex: Integer);
function GetLayer: TMapLayer; override;
end;
{ TMapPolygon }
@ -216,39 +274,40 @@ type
property Points: TGPSPointList read FPoints;
end;
TMapTrackSegment = class(TMapPolygon)
end;
TMapTrackSegments = class(specialize TMapCollection<TMapTrackSegment, TMapTrack>)
end;
{ TMapTrack }
TMapTrack = class(TMapItem)
private
FLineColor: TColor;
FLineWidth: Double;
FSegments: TMapTrackSegments;
FPoints: TMapTrackPoints;
FTrack: TGPSTrack;
FOnDrawTrack: TMapTrackDrawEvent;
function GetGPSObj: TGPSObj; override;
function GetPoints: TMapTrackPoints;
procedure SetOnDrawTrack(AValue: TMapTrackDrawEvent);
procedure SetPoints(AValue: TMapTrackPoints);
protected
procedure DrawTrack(Sender: TObject; AGPSObj: TGPSObj; AArea: TRealArea);
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
procedure ItemChanged; override;
published
property Segments: TMapTrackSegments read FSegments write FSegments;
//property DateTime: TDateTime read GetDateTime write FDateTime;
property LineColor: TColor read FLineColor write FLineColor;
property LineColor: TColor read FLineColor write FLineColor default clDefault;
property LineWidth: Double read FLineWidth write FLineWidth;
property Points: TMapTrackPoints read GetPoints write SetPoints;
property OnDrawTrack: TMapTrackDrawEvent read FOnDrawTrack write SetOnDrawTrack;
end;
{ TMapTracks }
TMapTracks = class(specialize TMapCollection<TMapTrack, TMapLayer>)
protected
procedure Update(Item: TCollectionItem); override;
function GetLayer: TMapLayer; override;
end;
{ TMapView }
TMapView = class(TCustomControl)
@ -514,7 +573,7 @@ type
implementation
uses
GraphMath, FileUtil, Types, Math,
GraphMath, FileUtil, LazLoggerBase, Types, Math,
mvJobQueue, mvExtraData, mvDLEFpc,
{$IFDEF MSWINDOWS}
mvDLEWin,
@ -555,31 +614,187 @@ type
destructor Destroy; override;
end;
{ TMapTrackPoint }
function TMapTrackPoint.CreatePoint: TGPSPoint;
var
Trk: TGPSTrack;
begin
Result := inherited CreatePoint;
Trk := GPSTrack;
if Assigned(Trk)
then Trk.Points.Add(Result);
end;
procedure TMapTrackPoint.DestroyPoint;
var
Trk: TGPSTrack;
begin
Trk := GPSTrack;
if Assigned(Trk) and Assigned(FPoint)
then Trk.Points.Remove(FPoint);
//FPoint.Free;
end;
function TMapTrackPoint.GPSTrack: TGPSTrack;
begin
Result := Nil;
if Assigned(Collection) and (Collection is TMapTrackPoints) then
with (Collection as TMapTrackPoints) do
if Assigned(MCOwner) and (MCOwner is TMapTrack) then
Result := (MCOwner as TMapTrack).FTrack;
end;
{ TMapCollectionBase }
function TMapCollectionBase.GetView: TMapView;
begin
if Assigned(Layer)
then Result := Layer.View
else Result := Nil;
end;
function TMapCollectionBase.GetLayer: TMapLayer;
begin
Result := Nil;
end;
procedure TMapCollectionBase.FixOrder(APrevIndex, AIndex: Integer);
var
I, T, B: Integer;
begin
T := Min(APrevIndex, AIndex);
B := Max(APrevIndex, AIndex);
if APrevIndex < 0 then
begin
T := AIndex;
B := Pred(Count);
end;
for I := T to B do
Layer.ComboLayer.ChangeZOrder(TMapItem(Items[I]).GPSObj, I);
end;
procedure TMapCollectionBase.Update(Item: TCollectionItem);
begin
inherited Update(Item);
if Assigned(View) then
View.Invalidate;
end;
{ TMapTrackPoints }
function TMapTrackPoints.GetLayer: TMapLayer;
begin
Result := MCOwner.Layer;
end;
procedure TMapTrackPoints.FixOrder(APrevIndex, AIndex: Integer);
var
I, T, B: Integer;
Trk: TGPSTrack;
O: TGPSPoint;
begin
if Assigned(MCOwner) and (MCOwner is TMapTrack)
then Trk := (MCOwner as TMapTrack).FTrack
else Exit;
T := Min(APrevIndex, AIndex);
B := Max(APrevIndex, AIndex);
if APrevIndex < 0 then
begin
T := AIndex;
B := Pred(Count);
end;
for I := T to B do
begin
O := TGPSPoint(TMapItem(Items[I]).GPSObj);
if Trk.Points.Extract(O) <> Nil then
Trk.Points.Insert(I, O);
end;
end;
{ TMapTrack }
procedure TMapTrack.SetOnDrawTrack(AValue: TMapTrackDrawEvent);
begin
if CompareMem(@FOnDrawTrack, @AValue, SizeOf(TMethod)) then
Exit;
FOnDrawTrack := AValue;
if Assigned(FOnDrawTrack)
then FTrack.OnDrawObj := @DrawTrack
else FTrack.OnDrawObj := Nil;
ItemChanged;
end;
function TMapTrack.GetGPSObj: TGPSObj;
begin
Result := FTrack;
end;
function TMapTrack.GetPoints: TMapTrackPoints;
begin
Result := FPoints;
end;
procedure TMapTrack.SetPoints(AValue: TMapTrackPoints);
begin
FPoints.Assign(AValue);
end;
procedure TMapTrack.DrawTrack(Sender: TObject; AGPSObj: TGPSObj;
AArea: TRealArea);
begin
if Assigned(FOnDrawTrack) then
FOnDrawTrack(Sender, (Collection as TMapTracks).GetView.DrawingEngine, Self);
end;
constructor TMapTrack.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FSegments := TMapTrackSegments.Create(Self);
FLineColor := clDefault;
FLineWidth := -1;
FVisible := True;
FPoints := TMapTrackPoints.Create(Self);
FTrack := TGPSTrack.Create;
Layer.ComboLayer.Add(FTrack, Pred(_TILELAYERS_ID_), Self.Index + 1);
end;
destructor TMapTrack.Destroy;
begin
FSegments.Free;
FPoints.Free;
if Assigned(FTrack) then
Layer.ComboLayer.Delete(FTrack);
inherited Destroy;
end;
procedure TMapTrack.ItemChanged;
begin
FTrack.LineColor := LineColor;
FTrack.LineWidth := LineWidth;
FTrack.Visible := Visible;
Changed(False);
end;
{ TMapTracks }
procedure TMapTracks.Update(Item: TCollectionItem);
function TMapTracks.GetLayer: TMapLayer;
begin
inherited Update(Item);
if Assigned(MCOwner.MapView) then
MCOwner.MapView.Invalidate;
Result := MCOwner;
end;
{ TMapItem }
function TMapItem.GetView: TMapView;
begin
Result := Layer.View;
end;
function TMapItem.GetLayer: TMapLayer;
begin
if Assigned(Collection)
then Result := (Collection as TMapCollectionBase).Layer
else Result := Nil;
end;
procedure TMapItem.SetCaption(AValue: TCaption);
begin
if FCaption=AValue then Exit;
@ -603,21 +818,31 @@ begin
then Result := Result + ' (Invisible)';
end;
{ TMapCollection }
function TMapCollection.GetItems(Index: Integer): T;
procedure TMapItem.SetIndex(Value: Integer);
var
PrevIndex: Integer;
begin
Result := T(inherited GetItem(Index));
PrevIndex := Index;
inherited SetIndex(Value);
if (PrevIndex <> Index) and Assigned(Collection) then
TMapCollectionBase(Collection).FixOrder(PrevIndex, Index);
end;
procedure TMapCollection.SetItems(Index: Integer; AValue: T);
{ TMapCollection }
function TMapCollection.GetItems(Index: Integer): TItemClass;
begin
Result := TItemClass(inherited GetItem(Index));
end;
procedure TMapCollection.SetItems(Index: Integer; AValue: TItemClass);
begin
(GetItems(Index) as TPersistent).Assign(AValue);
end;
constructor TMapCollection.Create(AOwner: OT);
begin
inherited Create(AOwner, T);
inherited Create(AOwner, TItemClass);
FMCOwner := AOwner;
end;
@ -662,94 +887,107 @@ end;
{ TPointsOfInterest }
procedure TPointsOfInterest.Update(Item: TCollectionItem);
function TPointsOfInterest.GetLayer: TMapLayer;
begin
inherited Update(Item);
if Assigned(MCOwner.MapView) then
MCOwner.MapView.Invalidate;
Result := MCOwner;
end;
procedure TPointsOfInterest.FixOrder(APrevIndex, AIndex: Integer);
var
I, T, B: Integer;
begin
T := Min(APrevIndex, AIndex);
B := Max(APrevIndex, AIndex);
if APrevIndex < 0 then
begin
T := AIndex;
B := Pred(Count);
end;
for I := T to B do
MCOwner.FComboLayer.ChangeZOrder(Items[I].FPoint, I);
end;
{ TMapPoint }
{ TPointOfInterest }
function TPointOfInterest.GetMapView: TMapView;
begin
if Collection is TPointsOfInterest
then Result := (Collection as TPointsOfInterest).MCOwner.MapView
else Result := Nil;
end;
function TPointOfInterest.IsDateTimeStored: Boolean;
function TMapPoint.IsDateTimeStored: Boolean;
begin
Result := not (FDateTime = NO_DATE);
end;
function TPointOfInterest.IsElevationStored: Boolean;
function TMapPoint.IsElevationStored: Boolean;
begin
Result := not (FElevation = NO_ELE);
end;
procedure TPointOfInterest.SetDateTime(AValue: TDateTime);
procedure TMapPoint.SetDateTime(AValue: TDateTime);
begin
if FDateTime=AValue then Exit;
FDateTime:=AValue;
ItemChanged;
end;
procedure TPointOfInterest.SetElevation(AValue: Double);
procedure TMapPoint.SetElevation(AValue: Double);
begin
if FElevation=AValue then Exit;
FElevation:=AValue;
ItemChanged;
end;
function TPointOfInterest.GetLayer: TMapLayer;
function TMapPoint.GetLatLonInDMS: Boolean;
begin
if Collection is TPointsOfInterest
then Result := (Collection as TPointsOfInterest).MCOwner
else Result := Nil;
Result := Assigned(View) and (mvoLatLonInDMS in View.Options);
end;
function TPointOfInterest.GetLatLonInDMS: Boolean;
begin
Result := Assigned(MapView) and (mvoLatLonInDMS in MapView.Options);
end;
procedure TPointOfInterest.SetImageIndex(AValue: TImageIndex);
begin
if FImageIndex = AValue then Exit;
FImageIndex := AValue;
ItemChanged;
end;
procedure TPointOfInterest.SetLatitude(AValue: Double);
procedure TMapPoint.SetLatitude(AValue: Double);
begin
if FLatitude = AValue then Exit;
FLatitude := AValue;
ItemChanged;
end;
procedure TPointOfInterest.SetLongitude(AValue: Double);
procedure TMapPoint.SetLongitude(AValue: Double);
begin
if FLongitude = AValue then Exit;
FLongitude := AValue;
ItemChanged;
end;
function TMapPoint.GetGPSObj: TGPSObj;
begin
Result := FPoint;
end;
procedure TMapPoint.ItemChanged;
begin
FPoint.Lon := Longitude;
FPoint.Lat := Latitude;
FPoint.Name := Caption;
FPoint.Visible := Visible;
FPoint.Elevation := Elevation;
FPoint.DateTime := DateTime;
Changed(False);
end;
function TMapPoint.CreatePoint: TGPSPoint;
begin
Result := TGPSPoint.Create(FLongitude, FLatitude);
end;
procedure TMapPoint.DestroyPoint;
begin
end;
constructor TMapPoint.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FLongitude := View.Center.Lon;
FLatitude := View.Center.Lat;
FVisible := True;
FElevation := NO_ELE;
FDateTime := NO_DATE;
FPoint := CreatePoint;
end;
destructor TMapPoint.Destroy;
begin
DestroyPoint;
inherited Destroy;
end;
{ TPointOfInterest }
procedure TPointOfInterest.SetImageIndex(AValue: TImageIndex);
begin
if FImageIndex = AValue then Exit;
FImageIndex := AValue;
ItemChanged;
end;
procedure TPointOfInterest.SetOnDrawPoint(AValue: TPointOfInterestDrawEvent);
begin
if CompareMem(@FOnDrawPoint, @AValue, SizeOf(TMethod)) then
@ -761,53 +999,35 @@ begin
ItemChanged;
end;
procedure TPointOfInterest.SetIndex(Value: Integer);
var
PrevIndex: Integer;
begin
PrevIndex := Index;
inherited SetIndex(Value);
if (PrevIndex <> Index) and Assigned(Collection) then
TPointsOfInterest(Collection).FixOrder(PrevIndex, Self.Index);
end;
procedure TPointOfInterest.ItemChanged;
begin
FPoint.Lon := Longitude;
FPoint.Lat := Latitude;
FPoint.Name := Caption;
FPoint.ImageIndex := ImageIndex;
FPoint.Visible := Visible;
FPoint.Elevation := Elevation;
FPoint.DateTime := DateTime;
Changed(False);
end;
procedure TPointOfInterest.DrawPoint(Sender: TObject; AGPSObj: TGPSObj;
AArea: TRealArea);
begin
if Assigned(FOnDrawPoint) then
FOnDrawPoint(Sender, MapView.DrawingEngine, Self);
FOnDrawPoint(Sender, View.DrawingEngine, Self);
end;
procedure TPointOfInterest.ItemChanged;
begin
TGPSPointOfInterest(FPoint).ImageIndex := FImageIndex;
inherited ItemChanged;
end;
function TPointOfInterest.CreatePoint: TGPSPoint;
begin
Result := TGPSPointOfInterest.Create(FLongitude, FLatitude);
Layer.ComboLayer.Add(Result, Pred(_TILELAYERS_ID_), Self.Index + 1);
end;
procedure TPointOfInterest.DestroyPoint;
begin
if Assigned(FPoint) then
Layer.ComboLayer.Delete(FPoint);
end;
constructor TPointOfInterest.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FImageIndex := -1;
FLongitude := MapView.Center.Lon;
FLatitude := MapView.Center.Lat;
FVisible := True;
FElevation := NO_ELE;
FDateTime := NO_DATE;
FPoint := TGPSPointOfInterest.Create(FLongitude, FLatitude);
Layer.FComboLayer.Add(FPoint, Pred(_TILELAYERS_ID_), Self.Index + 1);
end;
destructor TPointOfInterest.Destroy;
begin
if Assigned(FPoint) then
Layer.FComboLayer.Delete(FPoint);
inherited Destroy;
end;
{ TMapCenter }
@ -851,12 +1071,12 @@ end;
{ TMapLayer }
function TMapLayer.GetMapView: TMapView;
begin
if Collection is TMapLayers
then Result := (Collection as TMapLayers).MCOwner //MapView
else Result := Nil;
end;
//function TMapLayer.GetMapView: TMapView;
//begin
// if Collection is TMapLayers
// then Result := (Collection as TMapLayers).MCOwner //MapView
// else Result := Nil;
//end;
function TMapLayer.GetPointsOfInterest: TPointsOfInterest;
begin
@ -868,9 +1088,26 @@ begin
Result := FTracks;
end;
function TMapLayer.GetGPSObj: TGPSObj;
begin
Result := FComboLayer;
end;
function TMapLayer.GetView: TMapView;
begin
if (Collection is TMapLayers)
then Result := (Collection as TMapLayers).View
else Result := Nil;
end;
function TMapLayer.GetLayer: TMapLayer;
begin
Result := Self;
end;
function TMapLayer.GetMapProvider: String;
begin
Result := FComboLayer.TileLayer.MapProvider
Result := ComboLayer.TileLayer.MapProvider
end;
function TMapLayer.GetUseThreads: Boolean;
@ -893,12 +1130,12 @@ begin
if FMapProvider = AValue then
Exit;
// Check compat. of provider projection type against the base provider.
if Assigned(MapView) then
if Assigned(View) then
begin
P := MapView.Engine.MapProviderByName(AValue);
if Assigned(P) and (MapView.Engine.MapProjectionType <> P.ProjectionType) then
P := View.Engine.MapProviderByName(AValue);
if Assigned(P) and (View.Engine.MapProjectionType <> P.ProjectionType) then
begin
WriteStr(LPS, MapView.Engine.MapProjectionType);
WriteStr(LPS, View.Engine.MapProjectionType);
WriteStr(MPS, P.ProjectionType);
raise EArgumentException.CreateFmt(
'%s has different projection type (%s) from the base map (%s).',
@ -936,16 +1173,6 @@ begin
ItemChanged;
end;
procedure TMapLayer.SetIndex(Value: Integer);
var
PrevIndex: Integer;
begin
PrevIndex := Index;
inherited SetIndex(Value);
if (PrevIndex <> Index) and Assigned(Collection) then
TMapLayers(Collection).FixOrder(PrevIndex, Index);
end;
procedure TMapLayer.ItemChanged;
begin
if Assigned(FComboLayer) then
@ -968,10 +1195,12 @@ begin
FVisible := True;
FTag := 0;
DebugLn('TMapLayer.Create 1');
FPointsOfInterest := TPointsOfInterest.Create(Self);
FTracks := TMapTracks.Create(Self);
FComboLayer := TGPSComboLayer.Create;
MapView.GPSItems.Add(FComboLayer, _TILELAYERS_ID_, Self.Index - LAYERS_ZOFFS);
View.GPSItems.Add(FComboLayer, _TILELAYERS_ID_, Self.Index - LAYERS_ZOFFS);
DebugLn('TMapLayer.Create X');
end;
destructor TMapLayer.Destroy;
@ -979,7 +1208,7 @@ begin
FPointsOfInterest.Free;
FTracks.Free;
if Assigned(FComboLayer) then
MapView.GPSItems.Delete(FComboLayer);
View.GPSItems.Delete(FComboLayer);
inherited Destroy;
end;
@ -987,7 +1216,7 @@ procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList);
procedure AddPoint(APoint: TGPSPoint);
begin
with PointsOfInterest.Add as TPointOfInterest do
with PointsOfInterest.Add as TMapPoint do
begin
Caption := APoint.Name;
Longitude := APoint.Lon;
@ -997,41 +1226,49 @@ procedure TMapLayer.AssignFromGPSList(AList: TGPSObjectList);
end;
end;
procedure AddTrack(ATrack: TGPSTrack);
var
I: Integer;
P: TGPSPoint;
begin
with Tracks.Add as TMapTrack do
for I := 0 to Pred(ATrack.Points.Count) do
with Points.Add as TMapTrackPoint do
begin
P := ATrack.Points[I];
Caption := P.Name;
Longitude := P.Lon;
Latitude := P.Lat;
Elevation := P.Elevation;
DateTime := P.DateTime;
end;
end;
var
I: Integer;
begin
if not Assigned(AList) then
Exit;
PointsOfInterest.Clear;
PointsOfInterest.Clear;
for I := 0 to Pred(AList.Count) do
if AList[I] is TGPSPoint then
AddPoint(TGPSPoint(AList[I]))
else if AList[I] is TGPSTrack then
AddTrack(TGPSTrack(AList[I]))
else
{TODO};
end;
{ TMapLayers }
procedure TMapLayers.Update(Item: TCollectionItem);
function TMapLayers.GetView: TMapView;
begin
inherited Update(Item);
if Assigned(MCOwner) then
MCOwner.Invalidate;
Result := MCOwner;
end;
procedure TMapLayers.FixOrder(APrevIndex, AIndex: Integer);
var
I, T, B: Integer;
function TMapLayers.GetLayer: TMapLayer;
begin
T := Min(APrevIndex, AIndex);
B := Max(APrevIndex, AIndex);
if APrevIndex < 0 then
begin
T := AIndex;
B := Pred(Count);
end;
for I := T to B do
MCOwner.GPSItems.ChangeZOrder(Items[I].FComboLayer, I + LAYERS_ZOFFS);
Result := Nil;
end;
{ TDrawObjJob }
@ -2341,7 +2578,7 @@ var
I: Integer;
begin
for I := 0 to Pred(FLayers.Count) do
FLayers[I].FComboLayer.TileLayer.ParentViewChanged;
FLayers[I].ComboLayer.TileLayer.ParentViewChanged;
end;
procedure TMapView.ChangeCachePath(AOldLoc: TCacheLocation; ANewPath: String);

View File

@ -128,7 +128,7 @@ var
Inst: TPersistent;
begin
Inst := GetComponent(0);
Result := (Inst is TPointOfInterest) and TPointOfInterest(Inst).LatLonInDMS
Result := (Inst is TMapPoint) and TMapPoint(Inst).LatLonInDMS
or (Inst is TMapCenter) and TMapCenter(Inst).LatLonInDMS;
end;
@ -176,7 +176,7 @@ begin
P := GetComponent(0);
if (P is TPointOfInterest) then
begin
Result := TPointOfInterest(P).MapView.POIImages;
Result := TPointOfInterest(P).View.POIImages;
end;
end;
@ -203,7 +203,7 @@ begin
MV := TMapView(Inst)
else if Inst is TMapLayer then
begin
MV := TMapLayer(Inst).MapView;
MV := TMapLayer(Inst).View;
Filter := True;
PT := MV.Engine.MapProjectionType;
end
@ -248,14 +248,14 @@ begin
RegisterPropertyEditor(TypeInfo(TImageIndex),
TPointOfInterest, 'ImageIndex', TPointOfInterestImageIndexPropertyEditor);
RegisterPropertyEditor(TypeInfo(TDateTime),
TPointOfInterest, 'DateTime', TPointDateTimePropertyEditor);
TMapPoint, 'DateTime', TPointDateTimePropertyEditor);
RegisterPropertyEditor(TypeInfo(Double),
TPointOfInterest, 'Elevation', TPointElevationPropertyEditor);
TMapPoint, 'Elevation', TPointElevationPropertyEditor);
RegisterPropertyEditor(TypeInfo(Double),
TPointOfInterest,'Latitude',TLatLonDMSPropertyEditor);
TMapPoint,'Latitude',TLatLonDMSPropertyEditor);
RegisterPropertyEditor(TypeInfo(Double),
TPointOfInterest,'Longitude',TLatLonDMSPropertyEditor);
TMapPoint,'Longitude',TLatLonDMSPropertyEditor);
RegisterPropertyEditor(TypeInfo(Double),
TMapCenter,'Latitude',TLatLonDMSPropertyEditor);
RegisterPropertyEditor(TypeInfo(Double),

View File

@ -44,6 +44,8 @@ Type
property LatRad: Extended read GetLatRad write SetLatRad;
end;
TRealPointArray = array of TRealPoint;
{ TRealArea }
TRealArea = Record
public