Fixed printing informations about nearest traficar car. Increased size of printed image from 300 to 370px.

This commit is contained in:
kplaczek
2018-08-12 12:21:16 +02:00
parent 7a5e7a5d9d
commit 23220819d5
5 changed files with 31 additions and 29 deletions

View File

@@ -46,10 +46,8 @@ class Keyboard extends Controller
case 'last':
$main = new Main();
$main->noteLast();
break;
case $keyboardAction[1] > 0:
echo 'test';
$main = new Main();
$main->printNote((int)$keyboardAction[1]);
break;

View File

@@ -52,7 +52,7 @@ class Main extends Controller
$image = $image->greyscale()
->resize(300, null, function ($constraint) {
->resize(370, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});

View File

@@ -79,23 +79,12 @@ class HtmlToPos
public function traficar($posText)
{
$data = $posText;
if (strstr($posText, '[traficar]')) {
$data = [];
$traficar = new Traficar();
$nearest = $traficar->nearestCar();
$data['text'] = "Najbliższy traficar:\n" .
'Model: ' . $nearest['car']['model'] . "\n" .
'Numer boczny: ' . $nearest['car']['orderNumber'] . "\n" .
'Rejestracja: ' . $nearest['car']['regNumber'] . "\n" .
'Lokalizacja: ' . $nearest['car']['location'] . "\n" .
'Odległość: ' . $nearest['distance'] . "km\n";
// $data['image'] = $nearest['imageName'];
// $data['image'] = 'https://staticmapmaker.com/img/cartodb_placeholder.png';
$nearest = $traficar->nearestCarText();
$posText = str_replace('[traficar]', $nearest, $posText);
}
return $data;
return $posText;
}

View File

@@ -86,7 +86,6 @@ class Paper
$this->printer->text($convertedData['text']);
} else {
$this->printer->text($htmlToPos->convert($text));
}
$this->printer->feed(3);
}

View File

@@ -13,7 +13,9 @@ class Traficar
{
private $homeCoords = ['lat' => 54.417475, 'lng' => 18.481913];
private $staticMapsKey = 'AIzaSyBPb9wXT2BcK8EH_3FFWVc2MLuDprj7YXw';
//dystans w kilometrach w którym auta brane są pod uwagę
const CLOSEST_DISTANCE = 2;
/**
* @param $lat1
@@ -34,7 +36,29 @@ class Traficar
}
public function nearestCar()
/**
* pobiera informacje o najbliższym trafficarze względem punktu podanego jako domowy i zwraca Sformatowane
* informacje na jego temat lub jesli nie ma auta to podaje informację że nie ma dostępnego.
*
* @return string
*/
public function nearestCarText()
{
$info = $this->nearestCarInfo();
$formatedInfo = 'Brak aut w promieniu ' . self::CLOSEST_DISTANCE . 'km od domu.';
if ($info['car'] != []) {
$formatedInfo = "Najbliższy traficar:\n" .
'Model: ' . $info['car']['model'] . "\n" .
'Numer boczny: ' . $info['car']['orderNumber'] . "\n" .
'Rejestracja: ' . $info['car']['regNumber'] . "\n" .
'Lokalizacja: ' . $info['car']['location'] . "\n" .
'Odległość: ' . $info['distance'] . "km\n";
}
return $formatedInfo;
}
public function nearestCarInfo()
{
$trafcarData = json_decode(file_get_contents('https://api.traficar.pl/eaw-rest-api/car?shapeId=5'), 1);
$closestCar = [];
@@ -42,19 +66,11 @@ class Traficar
foreach ($trafcarData['cars'] as $car) {
$distance = $this->distance($this->homeCoords['lat'], $this->homeCoords['lng'], $car['latitude'], $car['longitude']);
if ($distance < $closestDistance) {
if ($distance < self::CLOSEST_DISTANCE && $distance < $closestDistance) {
$closestDistance = $distance;
$closestCar = $car;
}
}
// $imgNoKey = "https://maps.googleapis.com/maps/api/staticmap?center=" . $latHome . "," . $lngHome . "&size=300x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0x000000%7C" . $closestCar['latitude'] . "," . $closestCar['longitude'];
// $img = "https://maps.googleapis.com/maps/api/staticmap?center=" . $this->homeCoords['lat'] . "," . $this->homeCoords['lng'] . "&size=300x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0x000000%7C" . $closestCar['latitude'] . "," . $closestCar['longitude'] . '&key=' . $this->staticMapsKey;
// $tmpFile = storage_path() . '/traficar_map.png';
// file_put_contents($tmpFile, file_get_contents($img));
return ['car' => $closestCar, 'distance' => round($closestDistance, 2),];
// 'imageName' => $tmpFile];
}
}