MavViewer: Easier usage of GpsPoint and GpsTracks. Less hints and warnings. GpxReader LoadFromFile/Stream returns the ID of the items loaded.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8078 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
6312921fac
commit
b10c38f5d7
@ -66,7 +66,7 @@ uses
|
|||||||
|
|
||||||
function IsValidPNG(AStream: TStream): Boolean;
|
function IsValidPNG(AStream: TStream): Boolean;
|
||||||
var
|
var
|
||||||
s: string;
|
s: string = '';
|
||||||
y: Int64;
|
y: Int64;
|
||||||
begin
|
begin
|
||||||
if Assigned(AStream) then
|
if Assigned(AStream) then
|
||||||
@ -84,7 +84,7 @@ end;
|
|||||||
|
|
||||||
function IsValidJPEG(AStream: TStream): Boolean;
|
function IsValidJPEG(AStream: TStream): Boolean;
|
||||||
var
|
var
|
||||||
s: string;
|
s: string = '';
|
||||||
y: Int64;
|
y: Int64;
|
||||||
begin
|
begin
|
||||||
if Assigned(AStream) then
|
if Assigned(AStream) then
|
||||||
|
@ -68,8 +68,9 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LCLType,
|
LCLType, LCLIntf,
|
||||||
FPImgCanv, GraphType;
|
FPImgCanv, GraphType,
|
||||||
|
mvTypes;
|
||||||
|
|
||||||
function InRange(x, min, max: Integer): Boolean;
|
function InRange(x, min, max: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
@ -370,6 +371,7 @@ end;
|
|||||||
function TMvIntfGraphicsDrawingEngine.TextExtent(const AText: String): TSize;
|
function TMvIntfGraphicsDrawingEngine.TextExtent(const AText: String): TSize;
|
||||||
var
|
var
|
||||||
bmp: TBitmap;
|
bmp: TBitmap;
|
||||||
|
R: TRect;
|
||||||
begin
|
begin
|
||||||
bmp := TBitmap.Create;
|
bmp := TBitmap.Create;
|
||||||
try
|
try
|
||||||
@ -377,7 +379,9 @@ begin
|
|||||||
bmp.Canvas.Font.Name := FFontName;
|
bmp.Canvas.Font.Name := FFontName;
|
||||||
bmp.Canvas.Font.Size := FFontSize;
|
bmp.Canvas.Font.Size := FFontSize;
|
||||||
bmp.Canvas.Font.Style := FFontStyle;
|
bmp.Canvas.Font.Style := FFontStyle;
|
||||||
Result := bmp.Canvas.TextExtent(AText);
|
R := Rect(0, 0, DEFAULT_POI_TEXT_WIDTH, 0);
|
||||||
|
DrawText(bmp.Canvas.Handle, PChar(AText), Length(AText), R, DT_WORDBREAK + DT_CALCRECT);
|
||||||
|
Result := Size(R.Width, R.Height);
|
||||||
finally
|
finally
|
||||||
bmp.Free;
|
bmp.Free;
|
||||||
end;
|
end;
|
||||||
@ -394,6 +398,8 @@ var
|
|||||||
fc, tc: TFPColor;
|
fc, tc: TFPColor;
|
||||||
intens, intens0: Int64;
|
intens, intens0: Int64;
|
||||||
alpha: Double;
|
alpha: Double;
|
||||||
|
R: TRect;
|
||||||
|
txtFlags: Integer = DT_CENTER + DT_WORDBREAK;
|
||||||
begin
|
begin
|
||||||
if (FCanvas = nil) or (AText = '') then
|
if (FCanvas = nil) or (AText = '') then
|
||||||
exit;
|
exit;
|
||||||
@ -406,12 +412,13 @@ begin
|
|||||||
bmp.Canvas.Font.Size := FFontSize;
|
bmp.Canvas.Font.Size := FFontSize;
|
||||||
bmp.Canvas.Font.Style := FFontStyle;
|
bmp.Canvas.Font.Style := FFontStyle;
|
||||||
bmp.Canvas.Font.Color := FFontColor;
|
bmp.Canvas.Font.Color := FFontColor;
|
||||||
ex := bmp.Canvas.TextExtent(AText);
|
ex := TextExtent(AText);
|
||||||
|
R := Rect(0, 0, ex.CX, ex.CY);
|
||||||
bmp.SetSize(ex.CX, ex.CY);
|
bmp.SetSize(ex.CX, ex.CY);
|
||||||
if GetBrushStyle <> bsClear then begin
|
if GetBrushStyle <> bsClear then begin
|
||||||
bmp.Canvas.Brush.Color := GetBrushColor;
|
bmp.Canvas.Brush.Color := GetBrushColor;
|
||||||
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
|
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
|
||||||
bmp.Canvas.TextOut(0, 0, AText);
|
DrawText(bmp.Canvas.Handle, PChar(AText), Length(AText), R, txtFlags);
|
||||||
DrawBitmap(X, Y, bmp, false);
|
DrawBitmap(X, Y, bmp, false);
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
@ -419,8 +426,9 @@ begin
|
|||||||
bmp.Canvas.Brush.Color := clBlack
|
bmp.Canvas.Brush.Color := clBlack
|
||||||
else
|
else
|
||||||
bmp.Canvas.Brush.Color := clWhite;
|
bmp.Canvas.Brush.Color := clWhite;
|
||||||
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
|
bmp.Canvas.FillRect(R); //0, 0, bmp.Width, bmp.Height);
|
||||||
bmp.Canvas.TextOut(0, 0, AText);
|
DrawText(bmp.Canvas.Handle, PChar(AText), Length(AText), R, txtFlags);
|
||||||
|
// bmp.Canvas.TextOut(0, 0, AText);
|
||||||
|
|
||||||
img := bmp.CreateIntfImage;
|
img := bmp.CreateIntfImage;
|
||||||
try
|
try
|
||||||
|
@ -39,6 +39,7 @@ type
|
|||||||
procedure SetExtraData(AValue: TObject);
|
procedure SetExtraData(AValue: TObject);
|
||||||
public
|
public
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure Assign(AObj: TGPSObj); virtual;
|
||||||
procedure GetArea(out Area: TRealArea); virtual; abstract;
|
procedure GetArea(out Area: TRealArea); virtual; abstract;
|
||||||
property Name: String read FName write FName;
|
property Name: String read FName write FName;
|
||||||
property ExtraData: TObject read FExtraData write SetExtraData;
|
property ExtraData: TObject read FExtraData write SetExtraData;
|
||||||
@ -63,6 +64,7 @@ type
|
|||||||
class function CreateFrom(aPt: TRealPoint; AElevation: Double = NO_ELE;
|
class function CreateFrom(aPt: TRealPoint; AElevation: Double = NO_ELE;
|
||||||
ADateTime: TDateTime = NO_DATE): TGPSPoint;
|
ADateTime: TDateTime = NO_DATE): TGPSPoint;
|
||||||
|
|
||||||
|
procedure Assign(AObj: TGPSObj); override;
|
||||||
procedure GetArea(out Area: TRealArea);override;
|
procedure GetArea(out Area: TRealArea);override;
|
||||||
function HasElevation: boolean;
|
function HasElevation: boolean;
|
||||||
function HasDateTime: Boolean;
|
function HasDateTime: Boolean;
|
||||||
@ -244,6 +246,11 @@ end;
|
|||||||
|
|
||||||
{ TGPSObj }
|
{ TGPSObj }
|
||||||
|
|
||||||
|
procedure TGPSObj.Assign(AObj: TGPSObj);
|
||||||
|
begin
|
||||||
|
FName := AObj.Name;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TGPSObj.SetExtraData(AValue: TObject);
|
procedure TGPSObj.SetExtraData(AValue: TObject);
|
||||||
begin
|
begin
|
||||||
if FExtraData=AValue then Exit;
|
if FExtraData=AValue then Exit;
|
||||||
@ -367,6 +374,7 @@ procedure TGPSObjectList.IdsToObj(const Ids: TIdArray; out objs: TGPSObjArray;
|
|||||||
var
|
var
|
||||||
i,nb : integer;
|
i,nb : integer;
|
||||||
begin
|
begin
|
||||||
|
objs := nil;
|
||||||
SetLength(objs, Length(Ids));
|
SetLength(objs, Length(Ids));
|
||||||
nb := 0;
|
nb := 0;
|
||||||
Lock;
|
Lock;
|
||||||
@ -607,8 +615,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if Items[i].ExtraData.InheritsFrom(TDrawingExtraData) then
|
if Items[i].ExtraData.InheritsFrom(TDrawingExtraData) then
|
||||||
begin
|
begin
|
||||||
Extr := TDrawingExtraData(Items[i]);
|
Extr := TDrawingExtraData(Items[i].ExtraData);
|
||||||
// !!! wp: There is a warning that TGPSObj and TDrawingExtraData are not related !!!
|
|
||||||
if ToDelete(Extr.Id) then
|
if ToDelete(Extr.Id) then
|
||||||
_Delete(i, DelLst);
|
_Delete(i, DelLst);
|
||||||
// !!! wp: DelLst is a local var and was created by _Delete but is
|
// !!! wp: DelLst is a local var and was created by _Delete but is
|
||||||
@ -695,6 +702,17 @@ end;
|
|||||||
|
|
||||||
{ TGPSPoint }
|
{ TGPSPoint }
|
||||||
|
|
||||||
|
procedure TGPSPoint.Assign(AObj: TGpsObj);
|
||||||
|
begin
|
||||||
|
if (AObj is TGPSPoint) then
|
||||||
|
begin
|
||||||
|
inherited Assign(AObj);
|
||||||
|
FRealPt := TGPSPoint(AObj).RealPoint;
|
||||||
|
FElevation := TGPSPoint(AObj).Elevation;
|
||||||
|
FDateTime := TGPSPoint(AObj).DateTime;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TGPSPoint.GetLat: Double;
|
function TGPSPoint.GetLat: Double;
|
||||||
begin
|
begin
|
||||||
result := FRealPt.Lat;
|
result := FRealPt.Lat;
|
||||||
|
@ -33,8 +33,8 @@ 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; out ABounds: TRealArea);
|
function LoadFromFile(AFileName: String; AList: TGpsObjectList; out ABounds: TRealArea): Integer;
|
||||||
procedure LoadFromStream(AStream: TStream; AList: TGpsObjectList; out ABounds: TRealArea);
|
function LoadFromStream(AStream: TStream; AList: TGpsObjectList; out ABounds: TRealArea): Integer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -150,21 +150,25 @@ end;
|
|||||||
|
|
||||||
{ TGpxReader }
|
{ TGpxReader }
|
||||||
|
|
||||||
procedure TGpxReader.LoadFromFile(AFileName: String; AList: TGpsObjectList;
|
{ Loads the specified gpx file and stores the tracks, points etc. in the provided
|
||||||
out ABounds: TRealArea);
|
list. All items share the same mapviewer ID which is selected randomly and
|
||||||
|
return as function result. ABounds is the geo rectangle enclosing the items. }
|
||||||
|
function TGpxReader.LoadFromFile(AFileName: String; AList: TGpsObjectList;
|
||||||
|
out ABounds: TRealArea): Integer;
|
||||||
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, ABounds);
|
Result := LoadFromStream(stream, AList, ABounds);
|
||||||
finally
|
finally
|
||||||
stream.Free;
|
stream.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGpxReader.LoadFromStream(AStream: TStream; AList: TGpsObjectList;
|
{ See LoadFromFile. }
|
||||||
out ABounds: TRealArea);
|
function TGpxReader.LoadFromStream(AStream: TStream; AList: TGpsObjectList;
|
||||||
|
out ABounds: TRealArea): Integer;
|
||||||
var
|
var
|
||||||
doc: TXMLDocument = nil;
|
doc: TXMLDocument = nil;
|
||||||
begin
|
begin
|
||||||
@ -180,6 +184,7 @@ begin
|
|||||||
ABounds.TopLeft.Lat := FMaxLat;
|
ABounds.TopLeft.Lat := FMaxLat;
|
||||||
ABounds.BottomRight.Lon := FMaxLon;
|
ABounds.BottomRight.Lon := FMaxLon;
|
||||||
ABounds.BottomRight.Lat := FMinLat;
|
ABounds.BottomRight.Lat := FMinLat;
|
||||||
|
Result := ID;
|
||||||
finally
|
finally
|
||||||
doc.Free;
|
doc.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -485,6 +485,7 @@ function TJobQueue.pFindJobByName(const aName: string;
|
|||||||
var
|
var
|
||||||
iRes, i: integer;
|
iRes, i: integer;
|
||||||
begin
|
begin
|
||||||
|
Result := nil;
|
||||||
SetLength(Result, Jobs.Count);
|
SetLength(Result, Jobs.Count);
|
||||||
iRes := 0;
|
iRes := 0;
|
||||||
for i := 0 to pred(Jobs.Count) do
|
for i := 0 to pred(Jobs.Count) do
|
||||||
@ -621,7 +622,7 @@ function TJobQueue.CancelAllJob(ByLauncher: TObject): TJobArray;
|
|||||||
var
|
var
|
||||||
i, iJob: integer;
|
i, iJob: integer;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 0);
|
Result := nil;
|
||||||
if FUseThreads then
|
if FUseThreads then
|
||||||
begin
|
begin
|
||||||
EnterCriticalSection;
|
EnterCriticalSection;
|
||||||
@ -758,7 +759,7 @@ end;
|
|||||||
|
|
||||||
procedure TJob.Cancel;
|
procedure TJob.Cancel;
|
||||||
var
|
var
|
||||||
lst: Array of TRestartTask;
|
lst: Array of TRestartTask = nil;
|
||||||
i, idx: integer;
|
i, idx: integer;
|
||||||
begin
|
begin
|
||||||
Queue.EnterCriticalSection;
|
Queue.EnterCriticalSection;
|
||||||
|
@ -15,7 +15,7 @@ unit mvMapProvider;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, laz2_xmlwrite, laz2_dom;
|
Classes, SysUtils, laz2_dom;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ uses
|
|||||||
const
|
const
|
||||||
TILE_SIZE = 256;
|
TILE_SIZE = 256;
|
||||||
PALETTE_PAGE = 'Misc';
|
PALETTE_PAGE = 'Misc';
|
||||||
|
DEFAULT_POI_TEXT_WIDTH = 300;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
{ TArea }
|
{ TArea }
|
||||||
|
Loading…
Reference in New Issue
Block a user