PHP code example of nikop / wmts-tile-downloader

1. Go to this page and download the library: Download nikop/wmts-tile-downloader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nikop / wmts-tile-downloader example snippets


int $x, int $y, int $z, int $counter

use WMTSTileDownloader\Downloader\BasicDownloader;
use WMTSTileDownloader\Helpers\Mercator;
use WMTSTileDownloader\Types\LatLng;
use WMTSTileDownloader\Types\ZoomLevel;
use WMTSTileDownloader\WMTSTileDownloader;

g(49.610709938074, 1.93359375);
$downloader->generateFromLatLongs(northWest: $nw, southEast: $se, zoomLevel: new ZoomLevel(9));



declare(strict_types=1);

namespace WMTSTileDownloader\Downloader;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

final readonly class BasicDownloader implements DownloaderInterface
{

    public function __construct(private string $saveTo)
    {
    }

    /**
     * @throws GuzzleException
     */
    public function download(int $x, int $y, int $z, int $counter): bool
    {
        $url = 'https://tile.openstreetmap.org/'.$z.'/'.$x.'/'.$y.'.png';
        $this->downloadFile($url,$z.'_'.$x.'_'.$y,'.png');
        return true;
    }

    /**
     * @throws GuzzleException
     */
    public function downloadFile(string $url, string $name, string $extensions): void
    {
        $path = rtrim($this->saveTo,'/').'/' . $name . $extensions;
        $client = new Client();
        $client->get($url, ['sink' => $path]);
    }
}