LazMapViewer: Reactivate commit #8789 (panning across dateline).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8805 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-04-25 11:30:49 +00:00
parent 4ca84b72c3
commit f704502528

View File

@ -724,18 +724,26 @@ end;
function TMapViewerEngine.MapPixelsToDegrees(const AWin: TMapWindow; function TMapViewerEngine.MapPixelsToDegrees(const AWin: TMapWindow;
APoint: TPoint): TRealPoint; APoint: TPoint): TRealPoint;
var var
iMapWidth: Int64; mapWidth: Int64;
mPoint : TPoint; mPoint : TPoint;
begin begin
iMapWidth := round(ZoomFactor(AWin.Zoom)) * TILE_SIZE; mapWidth := round(ZoomFactor(AWin.Zoom)) * TILE_SIZE;
mPoint.X := EnsureRange(APoint.X - AWin.X, 0, iMapWidth); mPoint.Y := EnsureRange(APoint.Y - AWin.Y, 0, mapWidth);
mPoint.Y := EnsureRange(APoint.Y - AWin.Y, 0, iMapWidth); mPoint.X := EnsureRange(APoint.X - AWin.X, 0, mapWidth);
if FCyclic then
begin
while mPoint.X < 0 do
mPoint.X := mPoint.X + mapWidth;
while mPoint.X >= mapWidth do
mPoint.X := mPoint.X - mapWidth;
mPoint.Y := EnsureRange(APoint.Y - AWin.Y, 0, mapWidth);
end;
case aWin.MapProvider.ProjectionType of case aWin.MapProvider.ProjectionType of
ptEPSG3857: Result := PixelsToDegreesEPSG3857(mPoint, AWin.Zoom); ptEPSG3857: Result := PixelsToDegreesEPSG3857(mPoint, AWin.Zoom);
ptEPSG3395: Result := PixelsToDegreesEPSG3395(mPoint, AWin.Zoom); ptEPSG3395: Result := PixelsToDegreesEPSG3395(mPoint, AWin.Zoom);
else Result := PixelsToDegreesEPSG3857(mPoint, AWin.Zoom); else Result := PixelsToDegreesEPSG3857(mPoint, AWin.Zoom);
end; end;
end; end;
@ -1004,31 +1012,39 @@ begin
Redraw(MapWin); Redraw(MapWin);
end; end;
procedure TMapViewerEngine.Redraw(const aWin: TmapWindow); procedure TMapViewerEngine.Redraw(const AWin: TmapWindow);
var var
TilesVis: TArea; TilesVis: TArea;
x, y : Integer; //int64; x, y : Integer; //int64;
Tiles: TTileIdArray = nil; Tiles: TTileIdArray = nil;
iTile: Integer; iTile: Integer;
numTiles: Integer;
begin begin
if not(Active) then if not(Active) then
Exit; Exit;
Queue.CancelAllJob(self); Queue.CancelAllJob(self);
TilesVis := CalculateVisibleTiles(aWin); TilesVis := CalculateVisibleTiles(AWin);
SetLength(Tiles, (TilesVis.Bottom - TilesVis.Top + 1) * (TilesVis.Right - TilesVis.Left + 1)); SetLength(Tiles, (TilesVis.Bottom - TilesVis.Top + 1) * (TilesVis.Right - TilesVis.Left + 1));
iTile := Low(Tiles); iTile := Low(Tiles);
numTiles := 1 shl AWin.Zoom;
for y := TilesVis.Top to TilesVis.Bottom do for y := TilesVis.Top to TilesVis.Bottom do
for X := TilesVis.Left to TilesVis.Right do for X := TilesVis.Left to TilesVis.Right do
begin begin
Tiles[iTile].X := X; if FCyclic then
begin
Tiles[iTile].X := X mod numTiles;
if Tiles[iTile].X < 0 then
Tiles[iTile].X := Tiles[iTile].X + numTiles;
end else
Tiles[iTile].X := X;
Tiles[iTile].Y := Y; Tiles[iTile].Y := Y;
Tiles[iTile].Z := aWin.Zoom; Tiles[iTile].Z := AWin.Zoom;
if IsValidTile(aWin, Tiles[iTile]) then if IsValidTile(AWin, Tiles[iTile]) then
iTile += 1; inc(iTile);
end; end;
SetLength(Tiles, iTile); SetLength(Tiles, iTile);
if Length(Tiles) > 0 then if Length(Tiles) > 0 then
Queue.AddJob(TLaunchDownloadJob.Create(self, Tiles, aWin), self); Queue.AddJob(TLaunchDownloadJob.Create(self, Tiles, AWin), self);
end; end;
@ -1264,15 +1280,40 @@ var
EnvTile: TEnvTile; EnvTile: TEnvTile;
img: TLazIntfImage; img: TLazIntfImage;
X, Y: integer; X, Y: integer;
worldWidth : Integer;
numTiles : Integer;
baseX : Integer;
begin begin
EnvTile := TEnvTile(Data); EnvTile := TEnvTile(Data);
try try
if IsCurrentWin(EnvTile.Win)then if IsCurrentWin(EnvTile.Win)then
begin begin
Cache.GetFromCache(EnvTile.Win.MapProvider, EnvTile.Tile, img); Cache.GetFromCache(EnvTile.Win.MapProvider, EnvTile.Tile, img);
X := EnvTile.Win.X + EnvTile.Tile.X * TILE_SIZE; // begin of X
Y := EnvTile.Win.Y + EnvTile.Tile.Y * TILE_SIZE; // begin of Y Y := EnvTile.Win.Y + EnvTile.Tile.Y * TILE_SIZE; // begin of Y
DrawTile(EnvTile.Tile, X, Y, img); if Cyclic then
begin
baseX := EnvTile.Win.X + EnvTile.Tile.X * TILE_SIZE; // begin of X
numTiles := 1 shl EnvTile.Win.Zoom;
worldWidth := numTiles * TILE_SIZE;
// From the center to the left (western) hemisphere
X := baseX;
while (X+TILE_SIZE >= 0) do
begin
DrawTile(EnvTile.Tile, X, Y, img);
X := X - worldWidth;
end;
// From the center to the right (eastern) hemisphere
X := baseX + worldWidth;
while ((X-TILE_SIZE) <= EnvTile.Win.Width) do
begin
DrawTile(EnvTile.Tile, X, Y, img);
X := X + worldWidth;
end;
end else
begin
X := EnvTile.Win.X + EnvTile.Tile.X * TILE_SIZE; // begin of X
DrawTile(EnvTile.Tile, X, Y, img);
end;
end; end;
finally finally
FreeAndNil(EnvTile); FreeAndNil(EnvTile);