Extract static methods.
This commit is contained in:
parent
5a7bdc21b1
commit
11e15874df
@ -135,20 +135,11 @@ class Printer
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lonToTile($long, $zoom)
|
|
||||||
{
|
|
||||||
return (($long + 180) / 360) * pow(2, $zoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function latToTile($lat, $zoom)
|
|
||||||
{
|
|
||||||
return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * pi() / 180)) / pi()) / 2 * pow(2, $zoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initCoords()
|
public function initCoords()
|
||||||
{
|
{
|
||||||
$this->centerX = $this->lonToTile($this->lon, $this->zoom);
|
$this->centerX = Util::lonToTile($this->lon, $this->zoom);
|
||||||
$this->centerY = $this->latToTile($this->lat, $this->zoom);
|
$this->centerY = Util::latToTile($this->lat, $this->zoom);
|
||||||
|
|
||||||
$this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
|
$this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
|
||||||
$this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
|
$this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
|
||||||
}
|
}
|
||||||
@ -236,8 +227,8 @@ class Printer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calc position
|
// calc position
|
||||||
$destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom)));
|
$destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($markerLon, $this->zoom)));
|
||||||
$destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom)));
|
$destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($markerLat, $this->zoom)));
|
||||||
|
|
||||||
// copy shadow on basemap
|
// copy shadow on basemap
|
||||||
if ($markerShadow && $markerShadowImg) {
|
if ($markerShadow && $markerShadowImg) {
|
||||||
@ -282,14 +273,14 @@ class Printer
|
|||||||
$sourceLongitude = array_shift($polylineList);
|
$sourceLongitude = array_shift($polylineList);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sourceX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($sourceLongitude, $this->zoom)));
|
$sourceX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($sourceLongitude, $this->zoom)));
|
||||||
$sourceY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($sourceLatitude, $this->zoom)));
|
$sourceY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($sourceLatitude, $this->zoom)));
|
||||||
|
|
||||||
$destinationLatitude = array_shift($polylineList);
|
$destinationLatitude = array_shift($polylineList);
|
||||||
$destinationLongitude = array_shift($polylineList);
|
$destinationLongitude = array_shift($polylineList);
|
||||||
|
|
||||||
$destinationX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($destinationLongitude, $this->zoom)));
|
$destinationX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($destinationLongitude, $this->zoom)));
|
||||||
$destinationY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($destinationLatitude, $this->zoom)));
|
$destinationY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($destinationLatitude, $this->zoom)));
|
||||||
|
|
||||||
imageline($this->image , $sourceX, $sourceY , $destinationX, $destinationY, $color);
|
imageline($this->image , $sourceX, $sourceY , $destinationX, $destinationY, $color);
|
||||||
|
|
||||||
|
16
src/Util.php
Normal file
16
src/Util.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace StaticMapLite;
|
||||||
|
|
||||||
|
class Util
|
||||||
|
{
|
||||||
|
public static function lonToTile(float $longitude, int $zoom): float
|
||||||
|
{
|
||||||
|
return (($longitude + 180) / 360) * pow(2, $zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function latToTile(float $latitude, int $zoom): float
|
||||||
|
{
|
||||||
|
return (1 - log(tan($latitude * pi() / 180) + 1 / cos($latitude * pi() / 180)) / pi()) / 2 * pow(2, $zoom);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user