Turn marker into object.
This commit is contained in:
parent
ecf28c9888
commit
93daa80771
32
src/Element/Marker.php
Normal file
32
src/Element/Marker.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace StaticMapLite\Element;
|
||||||
|
|
||||||
|
class Marker
|
||||||
|
{
|
||||||
|
protected $latitude;
|
||||||
|
protected $longitude;
|
||||||
|
protected $markerType;
|
||||||
|
|
||||||
|
public function __construct(string $markerType, float $latitude, float $longitude)
|
||||||
|
{
|
||||||
|
$this->markerType = $markerType;
|
||||||
|
$this->latitude = $latitude;
|
||||||
|
$this->longitude = $longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMarkerType(): string
|
||||||
|
{
|
||||||
|
return $this->markerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLatitude(): float
|
||||||
|
{
|
||||||
|
return $this->latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLongitude(): float
|
||||||
|
{
|
||||||
|
return $this->longitude;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace StaticMapLite;
|
namespace StaticMapLite;
|
||||||
|
|
||||||
|
use StaticMapLite\Element\Marker;
|
||||||
use StaticMapLite\TileResolver\CachedTileResolver;
|
use StaticMapLite\TileResolver\CachedTileResolver;
|
||||||
use StaticMapLite\TileResolver\TileResolver;
|
use StaticMapLite\TileResolver\TileResolver;
|
||||||
|
|
||||||
@ -82,11 +83,9 @@ class Printer
|
|||||||
$this->tileResolver = new CachedTileResolver();
|
$this->tileResolver = new CachedTileResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMarker(string $markerType, float $latitude, float $longitude): Printer
|
public function addMarker(Marker $marker): Printer
|
||||||
{
|
{
|
||||||
$marker = ['lat' => $latitude, 'lon' => $longitude, 'type' => $markerType];
|
$this->markers[] = $marker;
|
||||||
|
|
||||||
array_push($this->markers, $marker);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -186,21 +185,15 @@ class Printer
|
|||||||
|
|
||||||
public function placeMarkers()
|
public function placeMarkers()
|
||||||
{
|
{
|
||||||
// loop thru marker array
|
|
||||||
foreach ($this->markers as $marker) {
|
foreach ($this->markers as $marker) {
|
||||||
// set some local variables
|
|
||||||
$markerLat = $marker['lat'];
|
|
||||||
$markerLon = $marker['lon'];
|
|
||||||
$markerType = $marker['type'];
|
|
||||||
// clear variables from previous loops
|
|
||||||
$markerFilename = '';
|
$markerFilename = '';
|
||||||
$markerShadow = '';
|
$markerShadow = '';
|
||||||
$matches = false;
|
$matches = false;
|
||||||
|
|
||||||
// check for marker type, get settings from markerPrototypes
|
// check for marker type, get settings from markerPrototypes
|
||||||
if ($markerType) {
|
if ($marker->getMarkerType()) {
|
||||||
foreach ($this->markerPrototypes as $markerPrototype) {
|
foreach ($this->markerPrototypes as $markerPrototype) {
|
||||||
if (preg_match($markerPrototype['regex'], $markerType, $matches)) {
|
if (preg_match($markerPrototype['regex'], $marker->getMarkerType(), $matches)) {
|
||||||
$markerFilename = $matches[0] . $markerPrototype['extension'];
|
$markerFilename = $matches[0] . $markerPrototype['extension'];
|
||||||
if ($markerPrototype['offsetImage']) {
|
if ($markerPrototype['offsetImage']) {
|
||||||
list($markerImageOffsetX, $markerImageOffsetY) = explode(",", $markerPrototype['offsetImage']);
|
list($markerImageOffsetX, $markerImageOffsetY) = explode(",", $markerPrototype['offsetImage']);
|
||||||
@ -235,8 +228,8 @@ class Printer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calc position
|
// calc position
|
||||||
$destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($markerLon, $this->zoom)));
|
$destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($marker->getLongitude(), $this->zoom)));
|
||||||
$destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($markerLat, $this->zoom)));
|
$destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($marker->getLatitude(), $this->zoom)));
|
||||||
|
|
||||||
// copy shadow on basemap
|
// copy shadow on basemap
|
||||||
if ($markerShadow && $markerShadowImg) {
|
if ($markerShadow && $markerShadowImg) {
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
require_once '../vendor/autoload.php';
|
require_once '../vendor/autoload.php';
|
||||||
|
|
||||||
|
use StaticMapLite\Element\Marker;
|
||||||
use StaticMapLite\Printer;
|
use StaticMapLite\Printer;
|
||||||
|
|
||||||
$printer = new Printer();
|
$printer = new Printer();
|
||||||
@ -49,7 +50,9 @@ if ($markers) {
|
|||||||
foreach ($markerList as $marker) {
|
foreach ($markerList as $marker) {
|
||||||
list($markerLatitude, $markerLongitude, $markerType) = explode(',', $marker);
|
list($markerLatitude, $markerLongitude, $markerType) = explode(',', $marker);
|
||||||
|
|
||||||
$printer->addMarker($markerType, $markerLatitude, $markerLongitude);
|
$marker = new Marker($markerType, $markerLatitude, $markerLongitude);
|
||||||
|
|
||||||
|
$printer->addMarker($marker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user