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);
|
||||
begin
|
||||
if FLongitude = AValue then Exit;
|
||||
if (AValue <-180) or (AValue > 180) then
|
||||
raise EMapViewerLatLonException.Create('Longitudes allowed only between +/-180°');
|
||||
FLongitude := AValue;
|
||||
SetViewCenter;
|
||||
end;
|
||||
@ -1835,6 +1837,8 @@ end;
|
||||
procedure TMapCenter.SetLatitude(AValue: Double);
|
||||
begin
|
||||
if FLatitude = AValue then Exit;
|
||||
if (AValue < -90) or (AValue > 90) then
|
||||
raise EMapViewerLatLonException.Create('Latitudes allowed only between +/-90°.');
|
||||
FLatitude := AValue;
|
||||
SetViewCenter;
|
||||
end;
|
||||
|
@ -95,9 +95,29 @@ type
|
||||
TLatLonDMSPropertyEditor = class(TFloatPropertyEditor)
|
||||
private
|
||||
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
|
||||
function GetValue: string; override;
|
||||
procedure SetValue(const NewValue: AnsiString); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -289,6 +309,34 @@ end;
|
||||
|
||||
{ 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;
|
||||
var
|
||||
Inst: TPersistent;
|
||||
@ -298,22 +346,37 @@ begin
|
||||
or (Inst is TMapCenter) and TMapCenter(Inst).LatLonInDMS;
|
||||
end;
|
||||
|
||||
function TLatLonDMSPropertyEditor.GetValue: string;
|
||||
|
||||
{ TLatDMSPropertyEditor }
|
||||
|
||||
procedure TLatDMSPropertyEditor.GetRange(out AMin, AMax: Double);
|
||||
begin
|
||||
if not UseDMS
|
||||
then Result := inherited GetValue
|
||||
else if StartsText('Lat', GetName)
|
||||
then Result := LatToStr(GetFloatValue, True)
|
||||
else Result := LonToStr(GetFloatValue, True);
|
||||
AMin := -90.0;
|
||||
AMax := +90.0;
|
||||
end;
|
||||
|
||||
procedure TLatLonDMSPropertyEditor.SetValue(const NewValue: AnsiString);
|
||||
var
|
||||
Deg: Double;
|
||||
function TLatDMSPropertyEditor.GetValue: string;
|
||||
begin
|
||||
if UseDMS and TryStrDMSToDeg(NewValue, Deg)
|
||||
then SetFloatValue(Deg)
|
||||
else inherited SetValue(NewValue);
|
||||
if not UseDMS then
|
||||
Result := inherited GetValue
|
||||
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;
|
||||
|
||||
{ TPointDateTimePropertyEditor }
|
||||
|
@ -47,13 +47,13 @@ begin
|
||||
TMapPoint, 'Elevation', TPointElevationPropertyEditor);
|
||||
|
||||
RegisterPropertyEditor(TypeInfo(Double),
|
||||
TMapPoint,'Latitude', TLatLonDMSPropertyEditor);
|
||||
TMapPoint,'Latitude', TLatDMSPropertyEditor);
|
||||
RegisterPropertyEditor(TypeInfo(Double),
|
||||
TMapPoint,'Longitude', TLatLonDMSPropertyEditor);
|
||||
TMapPoint,'Longitude', TLonDMSPropertyEditor);
|
||||
RegisterPropertyEditor(TypeInfo(Double),
|
||||
TMapCenter,'Latitude', TLatLonDMSPropertyEditor);
|
||||
TMapCenter,'Latitude', TLatDMSPropertyEditor);
|
||||
RegisterPropertyEditor(TypeInfo(Double),
|
||||
TMapCenter,'Longitude', TLatLonDMSPropertyEditor);
|
||||
TMapCenter,'Longitude', TLonDMSPropertyEditor);
|
||||
|
||||
RegisterComponentEditor(TMvPluginManager, TMvPluginManagerComponentEditor);
|
||||
RegisterPropertyEditor(TypeInfo(TMvPluginList),
|
||||
|
@ -26,6 +26,7 @@ var
|
||||
|
||||
Type
|
||||
EMapViewerException = class(Exception);
|
||||
EMapViewerLatLonException = class(EMapViewerException);
|
||||
|
||||
{ TArea }
|
||||
TArea = record
|
||||
|
Loading…
Reference in New Issue
Block a user