Nearest traficar inforations.
This commit is contained in:
@@ -109,13 +109,10 @@ class Main extends Controller
|
|||||||
// Header("Content-type: image/png");
|
// Header("Content-type: image/png");
|
||||||
imagepng($output, $fileName, 9); //to print to screen
|
imagepng($output, $fileName, 9); //to print to screen
|
||||||
|
|
||||||
|
|
||||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
|
||||||
$printer = new Printer($connector);
|
|
||||||
$img = EscposImage::load($fileName, false);
|
$img = EscposImage::load($fileName, false);
|
||||||
$printer->bitImage($img);
|
$this->paper->getPrinter()->bitImage($img);
|
||||||
|
|
||||||
$printer->feed(4);
|
$this->paper->getPrinter()->feed(4);
|
||||||
|
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
@@ -152,13 +149,15 @@ class Main extends Controller
|
|||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printNote($noteId){
|
public function printNote($noteId)
|
||||||
|
{
|
||||||
$note = DB::table('note')->where('id', $noteId)->first();
|
$note = DB::table('note')->where('id', $noteId)->first();
|
||||||
$this->paper->sendPrint($note->topic, $note->text, $note->icon);
|
$this->paper->sendPrint($note->topic, $note->text, $note->icon);
|
||||||
return $note;
|
return $note;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function noteLast(){
|
public function noteLast()
|
||||||
|
{
|
||||||
$note = DB::table('note')->orderBy('id', 'desc')->first();
|
$note = DB::table('note')->orderBy('id', 'desc')->first();
|
||||||
$this->printNote($note->id);
|
$this->printNote($note->id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,27 @@ class HtmlToPos
|
|||||||
return $posText;
|
return $posText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
public function convert($html = '')
|
public function convert($html = '')
|
||||||
{
|
{
|
||||||
$posText = $this->handleNewLine($html);
|
$posText = $this->handleNewLine($html);
|
||||||
@@ -80,7 +101,10 @@ class HtmlToPos
|
|||||||
$posText = $this->pickRandomElement($posText);
|
$posText = $this->pickRandomElement($posText);
|
||||||
$posText = $this->randomNumber($posText);
|
$posText = $this->randomNumber($posText);
|
||||||
$posText = $this->vocabularyWord($posText);
|
$posText = $this->vocabularyWord($posText);
|
||||||
|
$posText = $this->traficar($posText);
|
||||||
|
|
||||||
|
// print_r($posText);
|
||||||
|
// die();
|
||||||
return $posText;
|
return $posText;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,16 @@ class Paper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getConnector()
|
||||||
|
{
|
||||||
|
return $this->connector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrinter()
|
||||||
|
{
|
||||||
|
return $this->printer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function sendHeaderPrint($title)
|
public function sendHeaderPrint($title)
|
||||||
{
|
{
|
||||||
@@ -42,11 +52,15 @@ class Paper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendImagePrint($image, $imageLocal = true)
|
public function sendImagePrint($image, $imageLocal = true, $icon = true)
|
||||||
{
|
{
|
||||||
if ($image) {
|
if ($image) {
|
||||||
if ($imageLocal) {
|
if ($imageLocal) {
|
||||||
|
if ($icon) {
|
||||||
$img = EscposImage::load($this->imageDirectory . basename($image) . '.png');
|
$img = EscposImage::load($this->imageDirectory . basename($image) . '.png');
|
||||||
|
} else {
|
||||||
|
$img = EscposImage::load($image);
|
||||||
|
}
|
||||||
} else { //image not local so then remote image
|
} else { //image not local so then remote image
|
||||||
$extension = strtolower(pathinfo($image, PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($image, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
@@ -67,7 +81,13 @@ class Paper
|
|||||||
$this->sendImagePrint($image, $imageLocal);
|
$this->sendImagePrint($image, $imageLocal);
|
||||||
$this->sendHeaderPrint($title);
|
$this->sendHeaderPrint($title);
|
||||||
$htmlToPos = new HtmlToPos();
|
$htmlToPos = new HtmlToPos();
|
||||||
|
$convertedData = $htmlToPos->convert($text);
|
||||||
|
if (is_array($convertedData)) {
|
||||||
|
$this->printer->text($convertedData['text']);
|
||||||
|
} else {
|
||||||
$this->printer->text($htmlToPos->convert($text));
|
$this->printer->text($htmlToPos->convert($text));
|
||||||
|
|
||||||
|
}
|
||||||
$this->printer->feed(3);
|
$this->printer->feed(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
60
app/Paper/Traficar.php
Normal file
60
app/Paper/Traficar.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: k
|
||||||
|
* Date: 30.06.2018
|
||||||
|
* Time: 18:29
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Paper;
|
||||||
|
|
||||||
|
|
||||||
|
class Traficar
|
||||||
|
{
|
||||||
|
|
||||||
|
private $homeCoords = ['lat' => 54.417475, 'lng' => 18.481913];
|
||||||
|
private $staticMapsKey = 'AIzaSyBPb9wXT2BcK8EH_3FFWVc2MLuDprj7YXw';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $lat1
|
||||||
|
* @param $lon1
|
||||||
|
* @param $lat2
|
||||||
|
* @param $lon2
|
||||||
|
* @return float zwracana jest odległość w kilometrach
|
||||||
|
*/
|
||||||
|
private function distance($lat1, $lon1, $lat2, $lon2)
|
||||||
|
{
|
||||||
|
|
||||||
|
$theta = $lon1 - $lon2;
|
||||||
|
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
|
||||||
|
$dist = acos($dist);
|
||||||
|
$dist = rad2deg($dist);
|
||||||
|
$miles = $dist * 60 * 1.1515;
|
||||||
|
return ($miles * 1.609344);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function nearestCar()
|
||||||
|
{
|
||||||
|
$trafcarData = json_decode(file_get_contents('https://api.traficar.pl/eaw-rest-api/car?shapeId=5'), 1);
|
||||||
|
$closestCar = [];
|
||||||
|
$closestDistance = 1000;
|
||||||
|
foreach ($trafcarData['cars'] as $car) {
|
||||||
|
|
||||||
|
$distance = $this->distance($this->homeCoords['lat'], $this->homeCoords['lng'], $car['latitude'], $car['longitude']);
|
||||||
|
if ($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];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user