LazMapViewer: Fix TMapViewer.CyclicPointsOf crashing if called outside Paint method.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9506 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-11-27 15:19:31 +00:00
parent 17132ec44a
commit 03cf0e9c90

View File

@ -27,8 +27,9 @@ unit mvMapViewer;
interface interface
uses uses
Classes, SysUtils, Controls, GraphType, Graphics, FPImage, IntfGraphics, Classes, SysUtils, Types, fgl, FPImage,
Forms, ImgList, LCLVersion, fgl, Controls, GraphType, Graphics, IntfGraphics,
Forms, ImgList, LCLVersion,
mvTypes, mvGeoMath, mvGPSObj, mvDragObj, mvCache, mvExtraData, mvTypes, mvGeoMath, mvGPSObj, mvDragObj, mvCache, mvExtraData,
mvEngine, mvMapProvider, mvDownloadEngine, mvDrawingEngine; mvEngine, mvMapProvider, mvDownloadEngine, mvDrawingEngine;
@ -436,6 +437,7 @@ type
private private
FCacheLocation: TCacheLocation; FCacheLocation: TCacheLocation;
FCachePath, FCacheFullPath: String; FCachePath, FCacheFullPath: String;
FCanvasSize: TSize; // Needed for calculation of cyclic points
FCenter: TMapCenter; FCenter: TMapCenter;
FDownloadEngine: TMvCustomDownloadEngine; FDownloadEngine: TMvCustomDownloadEngine;
FBuiltinDownloadEngine: TMvCustomDownloadEngine; FBuiltinDownloadEngine: TMvCustomDownloadEngine;
@ -848,7 +850,7 @@ type
implementation implementation
uses uses
FileUtil, LazLoggerBase, Types, Math, FileUtil, LazLoggerBase, Math,
mvJobQueue, mvJobQueue,
mvDLEFPC, mvDLEFPC,
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
@ -2579,6 +2581,8 @@ begin
Engine.SetSize(ClientWidth, ClientHeight); Engine.SetSize(ClientWidth, ClientHeight);
Invalidate; Invalidate;
end; end;
if (FCanvasSize.CX = 0) and (FCanvasSize.CY = 0) then
FCanvasSize := Size(ClientWidth + 100, ClientHeight); // will be updated correctly in Paint
end; end;
procedure TMapView.Paint; procedure TMapView.Paint;
@ -2608,14 +2612,14 @@ const
W: Integer; W: Integer;
begin begin
Engine.Redraw; Engine.Redraw;
W := Canvas.Width; W := FCanvasSize.CX;
if Cyclic then if Cyclic then
W := Min(1 shl Zoom * TileSize.CX, W); W := Min(1 shl Zoom * TileSize.CX, W);
if Assigned(FBeforeDrawObjectsEvent) then if Assigned(FBeforeDrawObjectsEvent) then
FBeforeDrawObjectsEvent(Self); FBeforeDrawObjectsEvent(Self);
DrawObjects(Default(TTileId), 0, 0, W - 1, Canvas.Height); DrawObjects(Default(TTileId), 0, 0, W - 1, FCanvasSize.CY);
if Assigned(FAfterDrawObjectsEvent) then if Assigned(FAfterDrawObjectsEvent) then
FAfterDrawObjectsEvent(Self); FAfterDrawObjectsEvent(Self);
@ -2644,12 +2648,15 @@ const
begin begin
inherited Paint; inherited Paint;
if IsActive FCanvasSize := Size(Canvas.Width, Canvas.Height);
then if Engine.InDrag if IsActive then
then DragDraw begin
else FullRedraw if Engine.InDrag then
DragDraw
else else
InactiveDraw; FullRedraw;
end else
InactiveDraw;
end; end;
procedure TMapView.OnGPSItemsModified(Sender: TObject; objs: TGPSObjList; procedure TMapView.OnGPSItemsModified(Sender: TObject; objs: TGPSObjList;
@ -3272,7 +3279,7 @@ end;
function TMapView.CyclicPointsOf(APoint: TPoint): TPointArray; function TMapView.CyclicPointsOf(APoint: TPoint): TPointArray;
var var
I, R, L, WorldSize, CanvasWidth: LongInt; I, R, L, WorldSize: LongInt;
begin begin
Result := Default(TPointArray); Result := Default(TPointArray);
if not Cyclic then if not Cyclic then
@ -3283,13 +3290,12 @@ begin
else else
begin begin
WorldSize := mvGeoMath.ZoomFactor(Zoom) * TileSize.CX; WorldSize := mvGeoMath.ZoomFactor(Zoom) * TileSize.CX;
CanvasWidth := Canvas.Width; SetLength(Result, 1{APoint} + (1{Round} + FCanvasSize.CX div WorldSize));
SetLength(Result, 1{APoint} + (1{Round} + CanvasWidth div WorldSize));
Result[0] := APoint; Result[0] := APoint;
I := 1; R := APoint.X + WorldSize; L := APoint.X - WorldSize; I := 1; R := APoint.X + WorldSize; L := APoint.X - WorldSize;
while (R < CanvasWidth) or (L >= 0) do while (R < FCanvasSize.CX) or (L >= 0) do
begin begin
if R < CanvasWidth then if R < FCanvasSize.CX then
begin begin
Result[I].Y := APoint.Y; Result[I].Y := APoint.Y;
Result[I].X := R; Result[I].X := R;