Skip to content

Commit

Permalink
feat: add a lazmapviewer-specific way to save images
Browse files Browse the repository at this point in the history
  • Loading branch information
kfilippenok committed Dec 23, 2024
1 parent 9ee4866 commit e1b6966
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ Example:

****

### lazmapviewer

Save images in specific way for LazMapViewer:

```
/provider-name/zoom/x_y
```

****

### show-file-type

If you need the file extension in the name, use this option. The parameter with the file extension is not specified, since the image is always downloaded as a *PNG*.
Expand Down
10 changes: 10 additions & 0 deletions docs/USAGE_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ Example:

****

### lazmapviewer

Сохранение изображений с специфичным для LazMapViewer способом:

```
/provider-name/zoom/x_y
```

****

### show-file-type

Включение отображение расширения ```.png``` в названии файла. Расширение всегда *PNG*.
Expand Down
28 changes: 24 additions & 4 deletions src/TilesDownload/TilesDownload.Classes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ HTileHelper = record helper for RTile
procedure SetValues(x, y: Integer);
end;

TSaveMethod = (smFolders, smPattern);
TSaveMethod = (smFolders, smPattern, smLazmapviewer);
TFilterType = (ftNone, ftGrayscale);
TPatternItem = (piProviderName, piZoom, piX, piY);

Expand Down Expand Up @@ -120,6 +120,7 @@ CTilesDownloader = class(TFPCustomHTTPClient)
procedure SetPattern(APattern: String);
function GetCoordinate(Index: Integer): RCoordinate;
procedure SetCoordinate(Index: Integer; AValue: RCoordinate);
procedure SetSaveMethod(AValue: TSaveMethod);
procedure SetTileRes(AValue: Integer);
function GetTotalTilesCount: Longword;
function GetTotalTilesCountOnCoordinates: Longword;
Expand All @@ -133,6 +134,7 @@ CTilesDownloader = class(TFPCustomHTTPClient)
function CalcZoomTilesCount(ATile1, ATile2: RTile): Longword; overload;
function GetFileNameDir(const AZoom, AX, AY: Integer): String;
function GetFileNamePattern(const AZoom, AX, AY: Integer): String;
function GetFileNameLazmapviewer(const AZoom, AX, AY: Integer): String;
function GetFileName(const AZoom, AX, AY: Integer): String;
procedure ReceiveTile(var ATileImg: TBGRABitmap; const AProviderLink: String; const AZoom: Integer; const ATile: RTile);
procedure ResampleTile(var ATileImg: TBGRABitmap; const ATileRes: Integer);
Expand All @@ -148,7 +150,7 @@ CTilesDownloader = class(TFPCustomHTTPClient)
property OutPath : String read GetOutPath write SetOutPath ;
property TileRes : Integer read FTileRes write SetTileRes ;
property Pattern : String read FPattern write SetPattern ;
property SaveMethod : TSaveMethod read FSaveMethod write FSaveMethod default defSaveMethod;
property SaveMethod : TSaveMethod read FSaveMethod write SetSaveMethod default defSaveMethod;
property Filter : TFilterType read FFilter write SetFilter default defFilter;
property MinZoom : Integer read FMinZoom write FMinZoom default defMinZoom;
property MaxZoom : Integer read FMaxZoom write FMaxZoom default defMaxZoom;
Expand Down Expand Up @@ -400,6 +402,18 @@ procedure CTilesDownloader.SetCoordinate(Index: Integer; AValue: RCoordinate);
FCoordinates[Index] := AValue;
end;

procedure CTilesDownloader.SetSaveMethod(AValue: TSaveMethod);
begin
if FSaveMethod = AValue then Exit;

FSaveMethod := AValue;
case AValue of
smLazmapviewer: begin
FGetFileName := @GetFileNameLazmapviewer;
end;
end;
end;

constructor CTilesDownloader.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Expand Down Expand Up @@ -491,6 +505,12 @@ function CTilesDownloader.GetFileNamePattern(const AZoom, AX, AY: Integer
Result := Result + IfThen(ShowFileType, '.png');
end;

function CTilesDownloader.GetFileNameLazmapviewer(const AZoom, AX, AY: Integer
): String;
begin
Result := Format('%d%s%d_%d%s', [AZoom, PathDelim, AX, AY, IfThen(ShowFileType, '.png')]);
end;

function CTilesDownloader.GetFileName(const AZoom, AX, AY: Integer): String;
begin
Result := FGetFileName(AZoom, AX, AY);
Expand Down Expand Up @@ -641,7 +661,7 @@ procedure CTilesDownloader.Download;

for iz := MinZoom to MaxZoom do
begin
if SaveMethod = smFolders then
if SaveMethod in [smFolders, smLazmapviewer] then
if not DirectoryExists(Format('%s/%d', [OutPath, iz])) then
if not ForceDirectories(Format('%s/%d', [OutPath, iz])) then
raise Exception.Create('The necessary paths could not be created. Check the specified path');
Expand Down Expand Up @@ -713,7 +733,7 @@ procedure CTilesDownloader.DownloadFullMap;
LZoomCurrentCount := 0;
LZoomTotalCount := CalcZoomTilesCount(iz);

if SaveMethod = smFolders then
if SaveMethod in [smFolders, smLazmapviewer] then
if not DirectoryExists(Format('%s%s%d', [OutPath, PathDelim, iz])) then
ForceDirectories(Format('%s%s%d', [OutPath, PathDelim, iz]));

Expand Down
2 changes: 2 additions & 0 deletions src/TilesDownload/TilesDownload.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface
okProviderLink,
okOutput,
okPattern,
okLazmapviewer,
okMinZoom,
okMaxZoom,
okFirstCoordLat,
Expand Down Expand Up @@ -58,6 +59,7 @@ function getOptionName(Option: TOptionKind): String;
okProviderLink : Exit('provider-link');
okOutput : Exit('output');
okPattern : Exit('pattern');
okLazmapviewer : Exit('lazmapviewer');
okMinZoom : Exit('min-zoom');
okMaxZoom : Exit('max-zoom');
okFirstCoordLat : Exit('fcoord-lat');
Expand Down
9 changes: 7 additions & 2 deletions src/tilesdownloader.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ ATilesDownloader = class(TCustomApplication)
if not OptionParameter[okTileRes].IsEmpty then
TileRes := OptionParameter[okTileRes].ToInteger;

if not OptionParameter[okPattern].IsEmpty then
Pattern := OptionParameter[okPattern];
if okPattern in glOptions then
begin
if not OptionParameter[okPattern].IsEmpty then
Pattern := OptionParameter[okPattern];
end
else if (okLazmapviewer in glOptions) then
SaveMethod := smLazmapviewer;

ShowFileType := okShowFileType in glOptions;
SkipMissing := okSkipMissing in glOptions;
Expand Down

0 comments on commit e1b6966

Please sign in to comment.