-
Notifications
You must be signed in to change notification settings - Fork 0
/
WMTSTileDownloader.php
65 lines (57 loc) · 1.85 KB
/
WMTSTileDownloader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace WMTSTileDownloader;
use App\Models\MobileProvidersList;
use App\Models\ProviderTiles;
use WMTSTileDownloader\Downloader\DownloaderInterface;
use WMTSTileDownloader\Exceptions\InvalidZoomLevelException;
use WMTSTileDownloader\Helpers\MercatorInterface;
use WMTSTileDownloader\Types\LatLng;
use WMTSTileDownloader\Types\ZoomLevel;
readonly class WMTSTileDownloader
{
public function __construct(private MercatorInterface $mercator, private DownloaderInterface $downloader)
{
}
/**
* @param LatLng $northWest
* @param LatLng $southEast
* @param ZoomLevel $zoomLevel
* @return true
* @throws InvalidZoomLevelException
*/
public function generateFromLatLongs(LatLng $northWest, LatLng $southEast, ZoomLevel $zoomLevel): true
{
$tile1 = $this->mercator->tileAtLatLng($northWest, $zoomLevel->getLevel());
$tile2 = $this->mercator->tileAtLatLng($southEast, $zoomLevel->getLevel());
$xTile1 = $tile1->getX();
$xTile2 = $tile2->getX();
$yTile1 = $tile1->getY();
$yTile2 = $tile2->getY();
$this->generate(xTile1: $xTile1,xTile2: $xTile2,yTile1: $yTile1,yTile2: $yTile2,zoomLevel: $zoomLevel->getLevel());
return true;
}
/**
* @param int $xTile1
* @param int $xTile2
* @param int $yTile1
* @param int $yTile2
* @param int $zoomLevel
* @return void
*/
private function generate(
int $xTile1,
int $xTile2,
int $yTile1,
int $yTile2,
int $zoomLevel
): void {
$i = 0;
for ($xTile = $xTile1; $xTile <= $xTile2 + 1; $xTile++) {
for ($yTile = $yTile1; $yTile <= $yTile2 + 1; $yTile++) {
$i++;
$this->downloader->download(x: $xTile,y: $yTile, z: $zoomLevel,counter: $i);
}
}
}
}