diff --git a/Src/CoordConvert/u_ProjectionTypeBase.pas b/Src/CoordConvert/u_ProjectionTypeBase.pas index 5d527a72c..6c5c34f70 100644 --- a/Src/CoordConvert/u_ProjectionTypeBase.pas +++ b/Src/CoordConvert/u_ProjectionTypeBase.pas @@ -47,7 +47,8 @@ type protected function Relative2LonLatInternal(const APoint: TDoublePoint): TDoublePoint; virtual; abstract; function LonLat2RelativeInternal(const APoint: TDoublePoint): TDoublePoint; virtual; abstract; - private + protected + { IProjectionType } function GetHash: THashValue; function GetDatum: IDatum; function GetProjectionEPSG: Integer; @@ -64,8 +65,8 @@ type procedure ValidateRelativePos(var APoint: TDoublePoint); procedure ValidateRelativeRect(var ARect: TDoubleRect); - procedure ValidateLonLatPos(var APoint: TDoublePoint); - procedure ValidateLonLatRect(var ARect: TDoubleRect); + procedure ValidateLonLatPos(var APoint: TDoublePoint); virtual; + procedure ValidateLonLatRect(var ARect: TDoubleRect); virtual; function CheckRelativePos(const APoint: TDoublePoint): boolean; function CheckRelativeRect(const ARect: TDoubleRect): boolean; diff --git a/Src/CoordConvert/u_ProjectionTypeGELonLat.pas b/Src/CoordConvert/u_ProjectionTypeGELonLat.pas index 9f3f373ba..e3136726d 100644 --- a/Src/CoordConvert/u_ProjectionTypeGELonLat.pas +++ b/Src/CoordConvert/u_ProjectionTypeGELonLat.pas @@ -24,9 +24,7 @@ unit u_ProjectionTypeGELonLat; interface uses - t_Hash, t_GeoTypes, - i_Datum, u_ProjectionTypeBase; type @@ -34,44 +32,60 @@ type protected function Relative2LonLatInternal(const APoint: TDoublePoint): TDoublePoint; override; function LonLat2RelativeInternal(const APoint: TDoublePoint): TDoublePoint; override; - public - constructor Create( - const AHash: THashValue; - const ADatum: IDatum; - const AProjEPSG: integer - ); + protected + procedure ValidateLonLatPos(var APoint: TDoublePoint); override; + procedure ValidateLonLatRect(var ARect: TDoubleRect); override; end; implementation -uses - Math; +const + CMaxLatitude = 85.0511287798066; { TProjectionTypeGELonLat } -constructor TProjectionTypeGELonLat.Create( - const AHash: THashValue; - const ADatum: IDatum; - const AProjEPSG: integer -); -begin - inherited Create(AHash, ADatum, AProjEPSG); -end; - function TProjectionTypeGELonLat.LonLat2RelativeInternal( const APoint: TDoublePoint ): TDoublePoint; begin - Result.x := (0.5 + APoint.x / 360); - Result.y := (0.5 - APoint.y / 360); + Result.X := (0.5 + APoint.X / 360); + Result.Y := (0.5 - APoint.Y / 360); end; function TProjectionTypeGELonLat.Relative2LonLatInternal( const APoint: TDoublePoint ): TDoublePoint; begin - Result.X := (APoint.x - 0.5) * 360; - Result.y := -(APoint.y - 0.5) * 360; + Result.X := (APoint.X - 0.5) * 360; + Result.Y := -(APoint.Y - 0.5) * 360; +end; + +procedure _ValidateLonLatPos(var APoint: TDoublePoint); inline; +begin + if APoint.X < -180 then begin + APoint.X := -180; + end else + if APoint.X > 180 then begin + APoint.X := 180; + end; + + if APoint.Y < -CMaxLatitude then begin + APoint.Y := -CMaxLatitude; + end else + if APoint.Y > CMaxLatitude then begin + APoint.Y := CMaxLatitude; + end; +end; + +procedure TProjectionTypeGELonLat.ValidateLonLatPos(var APoint: TDoublePoint); +begin + _ValidateLonLatPos(APoint); +end; + +procedure TProjectionTypeGELonLat.ValidateLonLatRect(var ARect: TDoubleRect); +begin + _ValidateLonLatPos(ARect.TopLeft); + _ValidateLonLatPos(ARect.BottomRight); end; end. diff --git a/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineHorizontal.pas b/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineHorizontal.pas index 3ba43ded4..50b9d5749 100644 --- a/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineHorizontal.pas +++ b/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineHorizontal.pas @@ -104,6 +104,18 @@ begin VValidLegendWidth := (Config.Width div 4) * 4; num := GetMetersPerLine(AVisualCoordConverter, VValidLegendWidth); + if num <= 0 then begin + DrawScaleLegend( + VColor, + VOutLineColor, + VColor, + VValidLegendWidth, + ' ', + ' ', + Layer.Bitmap + ); + Exit; + end; if Config.NumbersFormat = slnfNice then begin ModifyLenAndWidth(Num, VValidLegendWidth); @@ -244,7 +256,9 @@ begin VFinishPixel := DoublePoint(VStartPixel.X + 1, VStartPixel.Y); VProjection.ValidatePixelPosFloat(VFinishPixel, True); VStartLonLat := VProjection.PixelPosFloat2LonLat(VStartPixel); + VProjection.ProjectionType.ValidateLonLatPos(VStartLonLat); VFinishLonLat := VProjection.PixelPosFloat2LonLat(VFinishPixel); + VProjection.ProjectionType.ValidateLonLatPos(VFinishLonLat); Result := VProjection.ProjectionType.Datum.CalcDist(VStartLonLat, VFinishLonLat) * ALineWidth; end; diff --git a/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineVertical.pas b/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineVertical.pas index a2fbe0551..9167a8763 100644 --- a/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineVertical.pas +++ b/Src/MapLayers/WindowLayers/ScaleLine/u_WindowLayerScaleLineVertical.pas @@ -249,10 +249,12 @@ begin VCenterPixelXY := AVisualCoordConverter.GetCenterMapPixelFloat; VProjection.ValidatePixelPosFloatStrict(VCenterPixelXY, False); VStartLonLat := VProjection.PixelPosFloat2LonLat(VCenterPixelXY); + VProjection.ProjectionType.ValidateLonLatPos(VStartLonLat); VFinishPixelXY := DoublePoint(VCenterPixelXY.X, VCenterPixelXY.Y - ALineHeight / 2); if VProjection.CheckPixelPosFloatStrict(VFinishPixelXY) then begin VFinishLonLat := VProjection.PixelPosFloat2LonLat(VFinishPixelXY); + VProjection.ProjectionType.ValidateLonLatPos(VFinishLonLat); AHalfLen := VProjection.ProjectionType.Datum.CalcDist(VStartLonLat, VFinishLonLat); end else begin AHalfLen := -1; @@ -261,6 +263,7 @@ begin VFinishPixelXY := DoublePoint(VCenterPixelXY.X, VCenterPixelXY.Y - ALineHeight); if VProjection.CheckPixelPosFloatStrict(VFinishPixelXY) then begin VFinishLonLat := VProjection.PixelPosFloat2LonLat(VFinishPixelXY); + VProjection.ProjectionType.ValidateLonLatPos(VFinishLonLat); AFullLen := VProjection.ProjectionType.Datum.CalcDist(VStartLonLat, VFinishLonLat); end else begin AFullLen := -1; diff --git a/Src/MapLayers/WindowLayers/StatusBar/u_WindowLayerStatusBar.pas b/Src/MapLayers/WindowLayers/StatusBar/u_WindowLayerStatusBar.pas index ec9862f7c..0062bf674 100644 --- a/Src/MapLayers/WindowLayers/StatusBar/u_WindowLayerStatusBar.pas +++ b/Src/MapLayers/WindowLayers/StatusBar/u_WindowLayerStatusBar.pas @@ -489,6 +489,7 @@ begin VMapPoint := VVisualCoordConverter.LocalPixel2MapPixelFloat(VMousePos); VProjection.ValidatePixelPosFloatStrict(VMapPoint, True); VLonLat := VProjection.PixelPosFloat2LonLat(VMapPoint); + VProjection.ProjectionType.ValidateLonLatPos(VLonLat); I := Low(TStatusBarItemID); AItems[I].Visible := FConfig.ViewZoomInfo;