LazMapViewer: Restrict LatLonToDMS property editor allow only latitudes between +/-90° and longitudes between +/-180°
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9617 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
20a2365fca
commit
2a8df5456c
@ -1828,6 +1828,8 @@ end;
|
|||||||
procedure TMapCenter.SetLongitude(AValue: Double);
|
procedure TMapCenter.SetLongitude(AValue: Double);
|
||||||
begin
|
begin
|
||||||
if FLongitude = AValue then Exit;
|
if FLongitude = AValue then Exit;
|
||||||
|
if (AValue <-180) or (AValue > 180) then
|
||||||
|
raise EMapViewerLatLonException.Create('Longitudes allowed only between +/-180°');
|
||||||
FLongitude := AValue;
|
FLongitude := AValue;
|
||||||
SetViewCenter;
|
SetViewCenter;
|
||||||
end;
|
end;
|
||||||
@ -1835,6 +1837,8 @@ end;
|
|||||||
procedure TMapCenter.SetLatitude(AValue: Double);
|
procedure TMapCenter.SetLatitude(AValue: Double);
|
||||||
begin
|
begin
|
||||||
if FLatitude = AValue then Exit;
|
if FLatitude = AValue then Exit;
|
||||||
|
if (AValue < -90) or (AValue > 90) then
|
||||||
|
raise EMapViewerLatLonException.Create('Latitudes allowed only between +/-90°.');
|
||||||
FLatitude := AValue;
|
FLatitude := AValue;
|
||||||
SetViewCenter;
|
SetViewCenter;
|
||||||
end;
|
end;
|
||||||
|
@ -95,9 +95,29 @@ type
|
|||||||
TLatLonDMSPropertyEditor = class(TFloatPropertyEditor)
|
TLatLonDMSPropertyEditor = class(TFloatPropertyEditor)
|
||||||
private
|
private
|
||||||
function UseDMS: Boolean;
|
function UseDMS: Boolean;
|
||||||
|
protected
|
||||||
|
procedure EnsureRange(var AValue: Double); virtual;
|
||||||
|
procedure GetRange(out AMin, AMax: Double); virtual; abstract;
|
||||||
|
public
|
||||||
|
procedure SetValue(const NewValue: AnsiString); override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLatDMSPropertyEditor }
|
||||||
|
|
||||||
|
TLatDMSPropertyEditor = class(TLatLonDMSPropertyEditor)
|
||||||
|
protected
|
||||||
|
procedure GetRange(out AMin, AMax: Double); override;
|
||||||
|
public
|
||||||
|
function GetValue: string; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLonDMSPropertyEditor }
|
||||||
|
|
||||||
|
TLonDMSPropertyEditor = class(TLatLonDMSPropertyEditor)
|
||||||
|
protected
|
||||||
|
procedure GetRange(out AMin, AMax: Double); override;
|
||||||
public
|
public
|
||||||
function GetValue: string; override;
|
function GetValue: string; override;
|
||||||
procedure SetValue(const NewValue: AnsiString); override;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -289,6 +309,34 @@ end;
|
|||||||
|
|
||||||
{ TLatLonDMSPropertyEditor }
|
{ TLatLonDMSPropertyEditor }
|
||||||
|
|
||||||
|
procedure TLatLonDMSPropertyEditor.EnsureRange(var AValue: Double);
|
||||||
|
var
|
||||||
|
min, max: Double;
|
||||||
|
begin
|
||||||
|
GetRange(min, max);
|
||||||
|
if AValue < min then
|
||||||
|
AValue := min
|
||||||
|
else if AValue > max then
|
||||||
|
AValue := max;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLatLonDMSPropertyEditor.SetValue(const NewValue: AnsiString);
|
||||||
|
var
|
||||||
|
Deg: Double;
|
||||||
|
FS: TFormatSettings;
|
||||||
|
begin
|
||||||
|
if not (UseDMS and TryStrDMSToDeg(NewValue, Deg)) then
|
||||||
|
begin
|
||||||
|
FS := DefaultFormatSettings;
|
||||||
|
FS.DecimalSeparator := '.'; //after all, this is Pascal, so we expect a period
|
||||||
|
if not TryStrToFloat(NewValue, Deg, FS) then
|
||||||
|
//if this failed, assume the user entered DS from his current locale
|
||||||
|
Deg := StrToFloat(NewValue, DefaultFormatSettings);
|
||||||
|
end;
|
||||||
|
EnsureRange(Deg);
|
||||||
|
SetFloatValue(Deg);
|
||||||
|
end;
|
||||||
|
|
||||||
function TLatLonDMSPropertyEditor.UseDMS: Boolean;
|
function TLatLonDMSPropertyEditor.UseDMS: Boolean;
|
||||||
var
|
var
|
||||||
Inst: TPersistent;
|
Inst: TPersistent;
|
||||||
@ -298,22 +346,37 @@ begin
|
|||||||
or (Inst is TMapCenter) and TMapCenter(Inst).LatLonInDMS;
|
or (Inst is TMapCenter) and TMapCenter(Inst).LatLonInDMS;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLatLonDMSPropertyEditor.GetValue: string;
|
|
||||||
|
{ TLatDMSPropertyEditor }
|
||||||
|
|
||||||
|
procedure TLatDMSPropertyEditor.GetRange(out AMin, AMax: Double);
|
||||||
begin
|
begin
|
||||||
if not UseDMS
|
AMin := -90.0;
|
||||||
then Result := inherited GetValue
|
AMax := +90.0;
|
||||||
else if StartsText('Lat', GetName)
|
|
||||||
then Result := LatToStr(GetFloatValue, True)
|
|
||||||
else Result := LonToStr(GetFloatValue, True);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLatLonDMSPropertyEditor.SetValue(const NewValue: AnsiString);
|
function TLatDMSPropertyEditor.GetValue: string;
|
||||||
var
|
|
||||||
Deg: Double;
|
|
||||||
begin
|
begin
|
||||||
if UseDMS and TryStrDMSToDeg(NewValue, Deg)
|
if not UseDMS then
|
||||||
then SetFloatValue(Deg)
|
Result := inherited GetValue
|
||||||
else inherited SetValue(NewValue);
|
else
|
||||||
|
Result := LatToStr(GetFloatValue, True);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLonDMSPropertyEditor }
|
||||||
|
|
||||||
|
procedure TLonDMSPropertyEditor.GetRange(out AMin, AMax: Double);
|
||||||
|
begin
|
||||||
|
AMin := -180.0;
|
||||||
|
AMax := +180.0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLonDMSPropertyEditor.GetValue: string;
|
||||||
|
begin
|
||||||
|
if not UseDMS then
|
||||||
|
Result := inherited GetValue
|
||||||
|
else
|
||||||
|
Result := LonToStr(GetFloatValue, True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPointDateTimePropertyEditor }
|
{ TPointDateTimePropertyEditor }
|
||||||
|
@ -47,13 +47,13 @@ begin
|
|||||||
TMapPoint, 'Elevation', TPointElevationPropertyEditor);
|
TMapPoint, 'Elevation', TPointElevationPropertyEditor);
|
||||||
|
|
||||||
RegisterPropertyEditor(TypeInfo(Double),
|
RegisterPropertyEditor(TypeInfo(Double),
|
||||||
TMapPoint,'Latitude', TLatLonDMSPropertyEditor);
|
TMapPoint,'Latitude', TLatDMSPropertyEditor);
|
||||||
RegisterPropertyEditor(TypeInfo(Double),
|
RegisterPropertyEditor(TypeInfo(Double),
|
||||||
TMapPoint,'Longitude', TLatLonDMSPropertyEditor);
|
TMapPoint,'Longitude', TLonDMSPropertyEditor);
|
||||||
RegisterPropertyEditor(TypeInfo(Double),
|
RegisterPropertyEditor(TypeInfo(Double),
|
||||||
TMapCenter,'Latitude', TLatLonDMSPropertyEditor);
|
TMapCenter,'Latitude', TLatDMSPropertyEditor);
|
||||||
RegisterPropertyEditor(TypeInfo(Double),
|
RegisterPropertyEditor(TypeInfo(Double),
|
||||||
TMapCenter,'Longitude', TLatLonDMSPropertyEditor);
|
TMapCenter,'Longitude', TLonDMSPropertyEditor);
|
||||||
|
|
||||||
RegisterComponentEditor(TMvPluginManager, TMvPluginManagerComponentEditor);
|
RegisterComponentEditor(TMvPluginManager, TMvPluginManagerComponentEditor);
|
||||||
RegisterPropertyEditor(TypeInfo(TMvPluginList),
|
RegisterPropertyEditor(TypeInfo(TMvPluginList),
|
||||||
|
@ -26,6 +26,7 @@ var
|
|||||||
|
|
||||||
Type
|
Type
|
||||||
EMapViewerException = class(Exception);
|
EMapViewerException = class(Exception);
|
||||||
|
EMapViewerLatLonException = class(EMapViewerException);
|
||||||
|
|
||||||
{ TArea }
|
{ TArea }
|
||||||
TArea = record
|
TArea = record
|
||||||
|
Loading…
Reference in New Issue
Block a user