lazmapviewer: Use E/W and N/S suffixes to GPS coordinates.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6868 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2019-04-25 19:42:50 +00:00
parent fb276886e4
commit efd629624c
5 changed files with 64 additions and 28 deletions

View File

@ -46,7 +46,7 @@ implementation
{$R *.lfm}
uses
mvTypes;
mvTypes, mvEngine;
destructor TGPSListViewer.Destroy;
begin
@ -55,8 +55,6 @@ begin
end;
procedure TGPSListViewer.Populate;
const
GPS_FORMAT = '0.00000°';
var
i: Integer;
item: TListItem;
@ -80,8 +78,8 @@ begin
// item.Caption := IntToStr(gpsObj.ID);
if gpsObj is TGpsPoint then begin
item.SubItems.Add(gpsObj.Name);
item.Subitems.Add(FormatFloat(GPS_FORMAT, TGpsPoint(gpsObj).Lat));
item.Subitems.Add(FormatFloat(GPS_FORMAT, TGpsPoint(gpsObj).Lon));
item.Subitems.Add(LatToStr(TGpsPoint(gpsObj).Lat, true));
item.Subitems.Add(LonToStr(TGpsPoint(gpsObj).Lon, true));
end;
end;
finally

View File

@ -625,6 +625,7 @@ object MainForm: TMainForm
OnZoomChange = MapViewZoomChange
OnChange = MapViewChange
OnDrawGpsPoint = MapViewDrawGpsPoint
OnMouseLeave = MapViewMouseLeave
OnMouseMove = MapViewMouseMove
OnMouseUp = MapViewMouseUp
end

View File

@ -67,8 +67,8 @@ type
const ALoc: TRealPoint);
procedure MapViewChange(Sender: TObject);
procedure MapViewDrawGpsPoint(Sender, ACanvas: TObject; APoint: TGpsPoint);
procedure MapViewMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure MapViewMouseLeave(Sender: TObject);
procedure MapViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure MapViewMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MapViewZoomChange(Sender: TObject);
@ -78,6 +78,7 @@ type
private
procedure ClearFoundLocations;
procedure UpdateCoords(X, Y: Integer);
procedure UpdateDropdownWidth(ACombobox: TCombobox);
procedure UpdateLocationHistory(ALocation: String);
procedure UpdateViewportSize;
@ -110,10 +111,12 @@ const
MAX_LOCATIONS_HISTORY = 50;
HOMEDIR = '';
MAP_PROVIDER_FILENAME = 'map-providers.xml';
USE_DMS = true;
var
PointFormatSettings: TFormatsettings;
function CalcIniName: String;
begin
Result := ChangeFileExt(Application.ExeName, '.ini');
@ -339,32 +342,22 @@ begin
end;
end;
procedure TMainForm.MapViewMouseLeave(Sender: TObject);
begin
UpdateCoords(MaxInt, MaxInt);
end;
procedure TMainForm.MapViewMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
const
DELTA = 3;
var
rPt: TRealPoint;
rArea: TRealArea;
gpsList: TGpsObjList;
L: TStrings;
i: Integer;
begin
rPt := MapView.Center;
InfoCenterLongitude.Caption := Format('%.6f° = %s', [rPt.Lon, GPSToDMS(rPt.Lon)]);
InfoCenterLatitude.Caption := Format('%.6f° = %s', [rPt.Lat, GPSToDMS(rPt.Lat)]);
{
InfoCenterLongitude.Caption := Format('%.6f°', [rPt.Lon]);
InfoCenterLatitude.Caption := Format('%.6f°', [rPt.Lat]);
}
rPt := MapView.ScreenToLonLat(Point(X, Y));
InfoPositionLongitude.Caption := Format('%.6f° = %s', [rPt.Lon, GPSToDMS(rPt.Lon)]);
InfoPositionLatitude.Caption := Format('%.6f° = %s', [rPt.Lat, GPSToDMS(rPt.Lat)]);
{
InfoPositionLongitude.Caption := Format('%.6f°', [rPt.Lon]);
InfoPositionLatitude.Caption := Format('%.6f°', [rPt.Lat]);
}
UpdateCoords(X, Y);
rArea.TopLeft := MapView.ScreenToLonLat(Point(X-DELTA, Y-DELTA));
rArea.BottomRight := MapView.ScreenToLonLat(Point(X+DELTA, Y+DELTA));
@ -376,11 +369,9 @@ begin
for i:=0 to gpsList.Count-1 do
if gpsList[i] is TGpsPoint then
with TGpsPoint(gpsList[i]) do
L.Add(Format('%s' + Lineending + ' (lat=%.6f°=%s, lon=%.6f°=%s°)', [
Name, Lat, GPSToDMS(Lat), Lon, GPSToDMS(Lon)
L.Add(Format('%s (%s / %s)', [
Name, LatToStr(Lat, USE_DMS), LonToStr(Lon, USE_DMS)
]));
//L.Add(Format('%s' + Lineending + ' (lat=%.6f°, lon=%.6f°)', [Name, Lat, Lon]));
GPSPointInfo.Caption := L.Text;
finally
L.Free;
@ -461,6 +452,24 @@ begin
end;
end;
procedure TMainForm.UpdateCoords(X, Y: Integer);
var
rPt: TRealPoint;
begin
rPt := MapView.Center;
InfoCenterLongitude.Caption := LonToStr(rPt.Lon, USE_DMS);
InfoCenterLatitude.Caption := LatToStr(rPt.Lat, USE_DMS);
if (X <> MaxInt) and (Y <> MaxInt) then begin
rPt := MapView.ScreenToLonLat(Point(X, Y));
InfoPositionLongitude.Caption := LonToStr(rPt.Lon, USE_DMS);
InfoPositionLatitude.Caption := LatToStr(rPt.Lat, USE_DMS);
end else begin
InfoPositionLongitude.Caption := '-';
InfoPositionLatitude.Caption := '-';
end;
end;
procedure TMainForm.UpdateDropdownWidth(ACombobox: TCombobox);
var
cnv: TControlCanvas;

View File

@ -73,7 +73,7 @@ begin
{$IF FPC_FullVersion >= 30000}
http.AllowRedirect := true;
{$IFEND}
http.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
http.AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
{$IF FPC_FullVersion >= 30101}
if UseProxy then begin
http.Proxy.Host := FProxyHost;

View File

@ -168,6 +168,9 @@ function CalcGeoDistance(Lat1, Lon1, Lat2, Lon2: double;
function GPSToDMS(Angle: Double): string;
function LatToStr(ALatitude: Double; DMS: Boolean): String;
function LonToStr(ALongitude: Double; DMS: Boolean): String;
procedure SplitGps(AValue: Double; out ADegs, AMins, ASecs: Double);
@ -1123,6 +1126,31 @@ begin
Result := Format('%.0f° %.0f'' %.1f"', [deg, min, sec]);
end;
function LatToStr(ALatitude: Double; DMS: Boolean): String;
begin
if DMS then
Result := GPSToDMS(abs(ALatitude))
else
Result := Format('%.6f°',[abs(ALatitude)]);
if ALatitude > 0 then
Result := Result + ' N'
else
if ALatitude < 0 then
Result := Result + 'E';
end;
function LonToStr(ALongitude: Double; DMS: Boolean): String;
begin
if DMS then
Result := GPSToDMS(abs(ALongitude))
else
Result := Format('%.6f°', [abs(ALongitude)]);
if ALongitude > 0 then
Result := Result + ' E'
else if ALongitude < 0 then
Result := Result + ' W';
end;
{ Returns the direct distance (air-line) between two geo coordinates
If latitude NOT between -90°..+90° and longitude NOT between -180°..+180°
the function returns -1.