Skip to content

Commit 18193b0

Browse files
committed
Add support for curl options and fail curl on error in the TileLayer construct and getTile function.
1 parent 5808877 commit 18193b0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/TileLayer.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,31 @@ public static function defaultTileLayer(): TileLayer
4444
*/
4545
protected $opacity = 1;
4646

47+
/**
48+
* @array $curlOptions Array of curl options
49+
*/
50+
protected $curlOptions = [];
51+
52+
/**
53+
* @bool $failCurlOnError If true, curl will throw an exception on error.
54+
*/
55+
protected $failCurlOnError = false;
56+
4757
/**
4858
* TileLayer constructor
4959
* @param string $url tile server url with placeholders (`x`, `y`, `z`, `r`, `s`)
5060
* @param string $attributionText tile server attribution text
5161
* @param string $subdomains tile server subdomains
62+
* @param array $curlOptions Array of curl options
63+
* @param bool $failCurlOnError If true, curl will throw an exception on error.
5264
*/
53-
public function __construct(string $url, string $attributionText, string $subdomains = 'abc')
65+
public function __construct(string $url, string $attributionText, string $subdomains = 'abc', array $curlOptions = [], bool $failCurlOnError = false)
5466
{
5567
$this->url = $url;
5668
$this->attributionText = $attributionText;
5769
$this->subdomains = \str_split($subdomains);
70+
$this->curlOptions = $curlOptions;
71+
$this->failCurlOnError = $failCurlOnError;
5872
}
5973

6074
/**
@@ -115,7 +129,7 @@ public function getTile(float $x, float $y, int $z): Image
115129
return Image::newCanvas(256, 256);
116130
}
117131

118-
$tile = Image::fromCurl($this->getTileUrl($x, $y, $z));
132+
$tile = Image::fromCurl($this->getTileUrl($x, $y, $z),$this->curlOptions, $this->failCurlOnError);
119133

120134
if($this->opacity > 0 && $this->opacity < 1) {
121135
$tile->setOpacity($this->opacity);

0 commit comments

Comments
 (0)