You've already forked lazarus-ccr
LazMapViewer: Add distance measurement between user-provided points (https://forum.lazarus.freepascal.org/index.php/topic,12674.msg319269.html, patch by sstvmaster).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6879 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -34,7 +34,7 @@
|
|||||||
<PackageName Value="LCL"/>
|
<PackageName Value="LCL"/>
|
||||||
</Item2>
|
</Item2>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="3">
|
<Units Count="4">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="MapViewer_Demo.lpr"/>
|
<Filename Value="MapViewer_Demo.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
@ -54,6 +54,10 @@
|
|||||||
<HasResources Value="True"/>
|
<HasResources Value="True"/>
|
||||||
<ResourceBaseClass Value="Form"/>
|
<ResourceBaseClass Value="Form"/>
|
||||||
</Unit2>
|
</Unit2>
|
||||||
|
<Unit3>
|
||||||
|
<Filename Value="globals.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit3>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -5,7 +5,7 @@ program MapViewer_Demo;
|
|||||||
uses
|
uses
|
||||||
{$IFDEF UNIX}cthreads,{$ENDIF}
|
{$IFDEF UNIX}cthreads,{$ENDIF}
|
||||||
Interfaces, // this includes the LCL widgetset
|
Interfaces, // this includes the LCL widgetset
|
||||||
Forms, Main, gpslistform
|
Forms, Main, gpslistform, globals
|
||||||
{ you can add units after this };
|
{ you can add units after this };
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
19
components/lazmapviewer/example/globals.pas
Normal file
19
components/lazmapviewer/example/globals.pas
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
unit globals;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, mvEngine;
|
||||||
|
|
||||||
|
const
|
||||||
|
DistanceUnit_Names: array[TDistanceUnits] of string = ('m', 'km', 'miles');
|
||||||
|
|
||||||
|
var
|
||||||
|
DistanceUnit: TDistanceUnits = duKilometers;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -2,20 +2,21 @@ object GPSListViewer: TGPSListViewer
|
|||||||
Left = 282
|
Left = 282
|
||||||
Height = 352
|
Height = 352
|
||||||
Top = 135
|
Top = 135
|
||||||
Width = 483
|
Width = 557
|
||||||
Caption = 'GPS points'
|
Caption = 'GPS points'
|
||||||
ClientHeight = 352
|
ClientHeight = 352
|
||||||
ClientWidth = 483
|
ClientWidth = 557
|
||||||
LCLVersion = '2.1.0.0'
|
LCLVersion = '2.1.0.0'
|
||||||
object ListView: TListView
|
object ListView: TListView
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 308
|
Height = 308
|
||||||
Top = 6
|
Top = 6
|
||||||
Width = 471
|
Width = 545
|
||||||
Align = alClient
|
Align = alClient
|
||||||
BorderSpacing.Left = 6
|
BorderSpacing.Left = 6
|
||||||
BorderSpacing.Top = 6
|
BorderSpacing.Top = 6
|
||||||
BorderSpacing.Right = 6
|
BorderSpacing.Right = 6
|
||||||
|
Checkboxes = True
|
||||||
Columns = <
|
Columns = <
|
||||||
item
|
item
|
||||||
Caption = 'ID'
|
Caption = 'ID'
|
||||||
@ -41,12 +42,12 @@ object GPSListViewer: TGPSListViewer
|
|||||||
Left = 0
|
Left = 0
|
||||||
Height = 38
|
Height = 38
|
||||||
Top = 314
|
Top = 314
|
||||||
Width = 483
|
Width = 557
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
AutoSize = True
|
AutoSize = True
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 38
|
ClientHeight = 38
|
||||||
ClientWidth = 483
|
ClientWidth = 557
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
object BtnDeletePoint: TBitBtn
|
object BtnDeletePoint: TBitBtn
|
||||||
AnchorSideLeft.Control = BtnGoToPoint
|
AnchorSideLeft.Control = BtnGoToPoint
|
||||||
@ -151,7 +152,7 @@ object GPSListViewer: TGPSListViewer
|
|||||||
AnchorSideTop.Control = Panel1
|
AnchorSideTop.Control = Panel1
|
||||||
AnchorSideRight.Control = Panel1
|
AnchorSideRight.Control = Panel1
|
||||||
AnchorSideRight.Side = asrBottom
|
AnchorSideRight.Side = asrBottom
|
||||||
Left = 402
|
Left = 476
|
||||||
Height = 26
|
Height = 26
|
||||||
Top = 6
|
Top = 6
|
||||||
Width = 75
|
Width = 75
|
||||||
@ -198,5 +199,19 @@ object GPSListViewer: TGPSListViewer
|
|||||||
OnClick = BtnCloseClick
|
OnClick = BtnCloseClick
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
end
|
end
|
||||||
|
object BtnCalcDistance: TButton
|
||||||
|
AnchorSideLeft.Control = BtnDeletePoint
|
||||||
|
AnchorSideLeft.Side = asrBottom
|
||||||
|
AnchorSideTop.Control = Panel1
|
||||||
|
Left = 234
|
||||||
|
Height = 25
|
||||||
|
Top = 6
|
||||||
|
Width = 203
|
||||||
|
AutoSize = True
|
||||||
|
BorderSpacing.Around = 6
|
||||||
|
Caption = 'Calc distance between two points'
|
||||||
|
OnClick = BtnCalcDistanceClick
|
||||||
|
TabOrder = 3
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, ComCtrls,
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, ComCtrls,
|
||||||
ExtCtrls, Buttons, mvGpsObj, mvMapViewer;
|
ExtCtrls, Buttons, StdCtrls, mvGpsObj, mvMapViewer;
|
||||||
|
|
||||||
const
|
const
|
||||||
// IDs of GPS items
|
// IDs of GPS items
|
||||||
@ -20,8 +20,10 @@ type
|
|||||||
BtnDeletePoint: TBitBtn;
|
BtnDeletePoint: TBitBtn;
|
||||||
BtnGoToPoint: TBitBtn;
|
BtnGoToPoint: TBitBtn;
|
||||||
BtnClose: TBitBtn;
|
BtnClose: TBitBtn;
|
||||||
|
BtnCalcDistance: TButton;
|
||||||
ListView: TListView;
|
ListView: TListView;
|
||||||
Panel1: TPanel;
|
Panel1: TPanel;
|
||||||
|
procedure BtnCalcDistanceClick(Sender: TObject);
|
||||||
procedure BtnCloseClick(Sender: TObject);
|
procedure BtnCloseClick(Sender: TObject);
|
||||||
procedure BtnDeletePointClick(Sender: TObject);
|
procedure BtnDeletePointClick(Sender: TObject);
|
||||||
procedure BtnGoToPointClick(Sender: TObject);
|
procedure BtnGoToPointClick(Sender: TObject);
|
||||||
@ -46,7 +48,8 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
mvTypes, mvEngine;
|
mvTypes, mvEngine,
|
||||||
|
globals;
|
||||||
|
|
||||||
destructor TGPSListViewer.Destroy;
|
destructor TGPSListViewer.Destroy;
|
||||||
begin
|
begin
|
||||||
@ -92,6 +95,57 @@ begin
|
|||||||
Close;
|
Close;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TGPSListViewer.BtnCalcDistanceClick(Sender: TObject);
|
||||||
|
type
|
||||||
|
TCoorRec = record
|
||||||
|
Lon: Double;
|
||||||
|
Lat: Double;
|
||||||
|
Name: String;
|
||||||
|
end;
|
||||||
|
var
|
||||||
|
i, iChecked: Integer;
|
||||||
|
gpsObj: TGpsObj;
|
||||||
|
gpsPt: TGpsPoint;
|
||||||
|
TCoorArr: array[0..1] of TCoorRec;
|
||||||
|
begin
|
||||||
|
// count checked items
|
||||||
|
iChecked := 0;
|
||||||
|
for i:=0 to ListView.Items.Count - 1 do begin
|
||||||
|
if ListView.Items.Item[i].Checked then Inc(iChecked);
|
||||||
|
end;
|
||||||
|
//
|
||||||
|
if iChecked <> 2 then begin
|
||||||
|
ShowMessage('Please select 2 items to calculate the distance.');
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
iChecked := 0;
|
||||||
|
for i:=0 to ListView.Items.Count - 1 do begin
|
||||||
|
if ListView.Items.Item[i].Checked then begin
|
||||||
|
gpsObj := FList.Items[i];
|
||||||
|
if gpsObj is TGpsPoint then begin
|
||||||
|
gpsPt := TGpsPoint(gpsObj);
|
||||||
|
TCoorArr[iChecked].Lat := gpsPt.Lat;
|
||||||
|
TCoorArr[iChecked].Lon := gpsPt.Lon;
|
||||||
|
TCoorArr[iChecked].Name:= gpsPt.Name;
|
||||||
|
Inc(iChecked);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
// show distance between selected items
|
||||||
|
ShowMessage('Distance between ' + TCoorArr[0].Name + ' and ' + TCoorArr[1].Name + ' is: ' +
|
||||||
|
Format('%.2n %s.', [
|
||||||
|
CalcGeoDistance(
|
||||||
|
TCoorArr[0].Lat,
|
||||||
|
TCoorArr[0].Lon,
|
||||||
|
TCoorArr[1].Lat,
|
||||||
|
TCoorArr[1].Lon,
|
||||||
|
DistanceUnit
|
||||||
|
),
|
||||||
|
DistanceUnit_Names[DistanceUnit]
|
||||||
|
]));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TGPSListViewer.BtnDeletePointClick(Sender: TObject);
|
procedure TGPSListViewer.BtnDeletePointClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
gpsObj: TGpsObj;
|
gpsObj: TGpsObj;
|
||||||
|
@ -99,7 +99,7 @@ implementation
|
|||||||
uses
|
uses
|
||||||
LCLType, IniFiles, Math, FPCanvas, FPImage, IntfGraphics,
|
LCLType, IniFiles, Math, FPCanvas, FPImage, IntfGraphics,
|
||||||
mvEngine, mvExtraData,
|
mvEngine, mvExtraData,
|
||||||
gpslistform;
|
globals, gpslistform;
|
||||||
|
|
||||||
type
|
type
|
||||||
TLocationParam = class
|
TLocationParam = class
|
||||||
@ -241,6 +241,7 @@ end;
|
|||||||
|
|
||||||
procedure TMainForm.CbDistanceUnitsChange(Sender: TObject);
|
procedure TMainForm.CbDistanceUnitsChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
DistanceUnit := TDistanceUnits(CbDistanceUnits.ItemIndex);
|
||||||
UpdateViewPortSize;
|
UpdateViewPortSize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -414,6 +415,7 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
s: String;
|
s: String;
|
||||||
pt: TRealPoint;
|
pt: TRealPoint;
|
||||||
|
du: TDistanceUnits;
|
||||||
begin
|
begin
|
||||||
ini := TMemIniFile.Create(CalcIniName);
|
ini := TMemIniFile.Create(CalcIniName);
|
||||||
try
|
try
|
||||||
@ -435,6 +437,16 @@ begin
|
|||||||
pt.Lat := StrToFloatDef(ini.ReadString('MapView', 'Center.Latitude', ''), 0.0, PointFormatSettings);
|
pt.Lat := StrToFloatDef(ini.ReadString('MapView', 'Center.Latitude', ''), 0.0, PointFormatSettings);
|
||||||
MapView.Center := pt;
|
MapView.Center := pt;
|
||||||
|
|
||||||
|
s := ini.ReadString('MapView', 'DistanceUnits', '');
|
||||||
|
if s <> '' then begin
|
||||||
|
for du in TDistanceUnits do
|
||||||
|
if DistanceUnit_Names[du] = s then begin
|
||||||
|
DistanceUnit := du;
|
||||||
|
CbDistanceUnits.ItemIndex := ord(du);
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
List := TStringList.Create;
|
List := TStringList.Create;
|
||||||
try
|
try
|
||||||
ini.ReadSection('Locations', List);
|
ini.ReadSection('Locations', List);
|
||||||
@ -518,9 +530,9 @@ begin
|
|||||||
MapView.GetVisibleArea.TopLeft.Lon,
|
MapView.GetVisibleArea.TopLeft.Lon,
|
||||||
MapView.GetVisibleArea.TopLeft.Lat,
|
MapView.GetVisibleArea.TopLeft.Lat,
|
||||||
MapView.GetVisibleArea.BottomRight.Lon,
|
MapView.GetVisibleArea.BottomRight.Lon,
|
||||||
TDistanceUnits(cbDistanceUnits.ItemIndex)
|
DistanceUnit
|
||||||
),
|
),
|
||||||
cbDistanceUnits.Items[cbDistanceUnits.ItemIndex]
|
DistanceUnit_Names[DistanceUnit]
|
||||||
]);
|
]);
|
||||||
InfoViewportHeight.Caption := Format('%.2n %s', [
|
InfoViewportHeight.Caption := Format('%.2n %s', [
|
||||||
CalcGeoDistance(
|
CalcGeoDistance(
|
||||||
@ -528,9 +540,9 @@ begin
|
|||||||
MapView.GetVisibleArea.TopLeft.Lon,
|
MapView.GetVisibleArea.TopLeft.Lon,
|
||||||
MapView.GetVisibleArea.BottomRight.Lat,
|
MapView.GetVisibleArea.BottomRight.Lat,
|
||||||
MapView.GetVisibleArea.TopLeft.Lon,
|
MapView.GetVisibleArea.TopLeft.Lon,
|
||||||
TDistanceUnits(cbDistanceUnits.ItemIndex)
|
DistanceUnit
|
||||||
),
|
),
|
||||||
cbDistanceUnits.Items[cbDistanceUnits.ItemIndex]
|
DistanceUnit_Names[DistanceUnit]
|
||||||
]);
|
]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -552,6 +564,8 @@ begin
|
|||||||
ini.WriteString('MapView', 'Center.Longitude', FloatToStr(MapView.Center.Lon, PointFormatSettings));
|
ini.WriteString('MapView', 'Center.Longitude', FloatToStr(MapView.Center.Lon, PointFormatSettings));
|
||||||
ini.WriteString('MapView', 'Center.Latitude', FloatToStr(MapView.Center.Lat, PointFormatSettings));
|
ini.WriteString('MapView', 'Center.Latitude', FloatToStr(MapView.Center.Lat, PointFormatSettings));
|
||||||
|
|
||||||
|
ini.WriteString('MapView', 'DistanceUnits', DistanceUnit_Names[DistanceUnit]);
|
||||||
|
|
||||||
ini.EraseSection('Locations');
|
ini.EraseSection('Locations');
|
||||||
for i := 0 to CbLocations.Items.Count-1 do
|
for i := 0 to CbLocations.Items.Count-1 do
|
||||||
ini.WriteString('Locations', 'Item'+IntToStr(i), CbLocations.Items[i]);
|
ini.WriteString('Locations', 'Item'+IntToStr(i), CbLocations.Items[i]);
|
||||||
|
Reference in New Issue
Block a user