Skip to content

Commit

Permalink
Merge pull request #9 from davetha/master
Browse files Browse the repository at this point in the history
Add support for curl options and fail curl on error in the TileLayer.
  • Loading branch information
DantSu authored Nov 9, 2022
2 parents 5808877 + e037af6 commit 54a8b91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"require": {
"php": ">=7.0",
"dantsu/php-image-editor": "^1.2"
"dantsu/php-image-editor": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 16 additions & 2 deletions src/TileLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,31 @@ public static function defaultTileLayer(): TileLayer
*/
protected $opacity = 1;

/**
* @array $curlOptions Array of curl options
*/
protected $curlOptions = [];

/**
* @bool $failCurlOnError If true, curl will throw an exception on error.
*/
protected $failCurlOnError = false;

/**
* TileLayer constructor
* @param string $url tile server url with placeholders (`x`, `y`, `z`, `r`, `s`)
* @param string $attributionText tile server attribution text
* @param string $subdomains tile server subdomains
* @param array $curlOptions Array of curl options
* @param bool $failCurlOnError If true, curl will throw an exception on error.
*/
public function __construct(string $url, string $attributionText, string $subdomains = 'abc')
public function __construct(string $url, string $attributionText, string $subdomains = 'abc', array $curlOptions = [], bool $failCurlOnError = false)
{
$this->url = $url;
$this->attributionText = $attributionText;
$this->subdomains = \str_split($subdomains);
$this->curlOptions = $curlOptions;
$this->failCurlOnError = $failCurlOnError;
}

/**
Expand Down Expand Up @@ -115,7 +129,7 @@ public function getTile(float $x, float $y, int $z): Image
return Image::newCanvas(256, 256);
}

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

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

0 comments on commit 54a8b91

Please sign in to comment.