diff --git a/src/Element/Marker.php b/src/Element/Marker.php new file mode 100644 index 0000000..9211d4d --- /dev/null +++ b/src/Element/Marker.php @@ -0,0 +1,32 @@ +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; + } +} diff --git a/src/Printer.php b/src/Printer.php index 3378007..09f23ca 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -2,6 +2,7 @@ namespace StaticMapLite; +use StaticMapLite\Element\Marker; use StaticMapLite\TileResolver\CachedTileResolver; use StaticMapLite\TileResolver\TileResolver; @@ -82,11 +83,9 @@ class Printer $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]; - - array_push($this->markers, $marker); + $this->markers[] = $marker; return $this; } @@ -186,21 +185,15 @@ class Printer public function placeMarkers() { - // loop thru marker array foreach ($this->markers as $marker) { - // set some local variables - $markerLat = $marker['lat']; - $markerLon = $marker['lon']; - $markerType = $marker['type']; - // clear variables from previous loops $markerFilename = ''; $markerShadow = ''; $matches = false; // check for marker type, get settings from markerPrototypes - if ($markerType) { + if ($marker->getMarkerType()) { 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']; if ($markerPrototype['offsetImage']) { list($markerImageOffsetX, $markerImageOffsetY) = explode(",", $markerPrototype['offsetImage']); @@ -235,8 +228,8 @@ class Printer } // calc position - $destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($markerLon, $this->zoom))); - $destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($markerLat, $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($marker->getLatitude(), $this->zoom))); // copy shadow on basemap if ($markerShadow && $markerShadowImg) { diff --git a/web/staticmap.php b/web/staticmap.php index 68adfd8..45bb12b 100644 --- a/web/staticmap.php +++ b/web/staticmap.php @@ -27,6 +27,7 @@ require_once '../vendor/autoload.php'; +use StaticMapLite\Element\Marker; use StaticMapLite\Printer; $printer = new Printer(); @@ -49,7 +50,9 @@ if ($markers) { foreach ($markerList as $marker) { list($markerLatitude, $markerLongitude, $markerType) = explode(',', $marker); - $printer->addMarker($markerType, $markerLatitude, $markerLongitude); + $marker = new Marker($markerType, $markerLatitude, $markerLongitude); + + $printer->addMarker($marker); } }