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"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Units Count="4">
|
||||
<Unit0>
|
||||
<Filename Value="MapViewer_Demo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
@ -54,6 +54,10 @@
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="globals.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit3>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
@ -5,7 +5,7 @@ program MapViewer_Demo;
|
||||
uses
|
||||
{$IFDEF UNIX}cthreads,{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, Main, gpslistform
|
||||
Forms, Main, gpslistform, globals
|
||||
{ you can add units after this };
|
||||
|
||||
{$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
|
||||
Height = 352
|
||||
Top = 135
|
||||
Width = 483
|
||||
Width = 557
|
||||
Caption = 'GPS points'
|
||||
ClientHeight = 352
|
||||
ClientWidth = 483
|
||||
ClientWidth = 557
|
||||
LCLVersion = '2.1.0.0'
|
||||
object ListView: TListView
|
||||
Left = 6
|
||||
Height = 308
|
||||
Top = 6
|
||||
Width = 471
|
||||
Width = 545
|
||||
Align = alClient
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 6
|
||||
Checkboxes = True
|
||||
Columns = <
|
||||
item
|
||||
Caption = 'ID'
|
||||
@ -41,12 +42,12 @@ object GPSListViewer: TGPSListViewer
|
||||
Left = 0
|
||||
Height = 38
|
||||
Top = 314
|
||||
Width = 483
|
||||
Width = 557
|
||||
Align = alBottom
|
||||
AutoSize = True
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 38
|
||||
ClientWidth = 483
|
||||
ClientWidth = 557
|
||||
TabOrder = 1
|
||||
object BtnDeletePoint: TBitBtn
|
||||
AnchorSideLeft.Control = BtnGoToPoint
|
||||
@ -151,7 +152,7 @@ object GPSListViewer: TGPSListViewer
|
||||
AnchorSideTop.Control = Panel1
|
||||
AnchorSideRight.Control = Panel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 402
|
||||
Left = 476
|
||||
Height = 26
|
||||
Top = 6
|
||||
Width = 75
|
||||
@ -198,5 +199,19 @@ object GPSListViewer: TGPSListViewer
|
||||
OnClick = BtnCloseClick
|
||||
TabOrder = 2
|
||||
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
|
||||
|
@ -6,7 +6,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, ComCtrls,
|
||||
ExtCtrls, Buttons, mvGpsObj, mvMapViewer;
|
||||
ExtCtrls, Buttons, StdCtrls, mvGpsObj, mvMapViewer;
|
||||
|
||||
const
|
||||
// IDs of GPS items
|
||||
@ -20,8 +20,10 @@ type
|
||||
BtnDeletePoint: TBitBtn;
|
||||
BtnGoToPoint: TBitBtn;
|
||||
BtnClose: TBitBtn;
|
||||
BtnCalcDistance: TButton;
|
||||
ListView: TListView;
|
||||
Panel1: TPanel;
|
||||
procedure BtnCalcDistanceClick(Sender: TObject);
|
||||
procedure BtnCloseClick(Sender: TObject);
|
||||
procedure BtnDeletePointClick(Sender: TObject);
|
||||
procedure BtnGoToPointClick(Sender: TObject);
|
||||
@ -46,7 +48,8 @@ implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
mvTypes, mvEngine;
|
||||
mvTypes, mvEngine,
|
||||
globals;
|
||||
|
||||
destructor TGPSListViewer.Destroy;
|
||||
begin
|
||||
@ -92,6 +95,57 @@ begin
|
||||
Close;
|
||||
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);
|
||||
var
|
||||
gpsObj: TGpsObj;
|
||||
|
@ -99,7 +99,7 @@ implementation
|
||||
uses
|
||||
LCLType, IniFiles, Math, FPCanvas, FPImage, IntfGraphics,
|
||||
mvEngine, mvExtraData,
|
||||
gpslistform;
|
||||
globals, gpslistform;
|
||||
|
||||
type
|
||||
TLocationParam = class
|
||||
@ -241,6 +241,7 @@ end;
|
||||
|
||||
procedure TMainForm.CbDistanceUnitsChange(Sender: TObject);
|
||||
begin
|
||||
DistanceUnit := TDistanceUnits(CbDistanceUnits.ItemIndex);
|
||||
UpdateViewPortSize;
|
||||
end;
|
||||
|
||||
@ -414,6 +415,7 @@ var
|
||||
i: Integer;
|
||||
s: String;
|
||||
pt: TRealPoint;
|
||||
du: TDistanceUnits;
|
||||
begin
|
||||
ini := TMemIniFile.Create(CalcIniName);
|
||||
try
|
||||
@ -435,6 +437,16 @@ begin
|
||||
pt.Lat := StrToFloatDef(ini.ReadString('MapView', 'Center.Latitude', ''), 0.0, PointFormatSettings);
|
||||
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;
|
||||
try
|
||||
ini.ReadSection('Locations', List);
|
||||
@ -518,9 +530,9 @@ begin
|
||||
MapView.GetVisibleArea.TopLeft.Lon,
|
||||
MapView.GetVisibleArea.TopLeft.Lat,
|
||||
MapView.GetVisibleArea.BottomRight.Lon,
|
||||
TDistanceUnits(cbDistanceUnits.ItemIndex)
|
||||
DistanceUnit
|
||||
),
|
||||
cbDistanceUnits.Items[cbDistanceUnits.ItemIndex]
|
||||
DistanceUnit_Names[DistanceUnit]
|
||||
]);
|
||||
InfoViewportHeight.Caption := Format('%.2n %s', [
|
||||
CalcGeoDistance(
|
||||
@ -528,9 +540,9 @@ begin
|
||||
MapView.GetVisibleArea.TopLeft.Lon,
|
||||
MapView.GetVisibleArea.BottomRight.Lat,
|
||||
MapView.GetVisibleArea.TopLeft.Lon,
|
||||
TDistanceUnits(cbDistanceUnits.ItemIndex)
|
||||
DistanceUnit
|
||||
),
|
||||
cbDistanceUnits.Items[cbDistanceUnits.ItemIndex]
|
||||
DistanceUnit_Names[DistanceUnit]
|
||||
]);
|
||||
end;
|
||||
|
||||
@ -552,6 +564,8 @@ begin
|
||||
ini.WriteString('MapView', 'Center.Longitude', FloatToStr(MapView.Center.Lon, PointFormatSettings));
|
||||
ini.WriteString('MapView', 'Center.Latitude', FloatToStr(MapView.Center.Lat, PointFormatSettings));
|
||||
|
||||
ini.WriteString('MapView', 'DistanceUnits', DistanceUnit_Names[DistanceUnit]);
|
||||
|
||||
ini.EraseSection('Locations');
|
||||
for i := 0 to CbLocations.Items.Count-1 do
|
||||
ini.WriteString('Locations', 'Item'+IntToStr(i), CbLocations.Items[i]);
|
||||
|
Reference in New Issue
Block a user