2018-01-10 02:48:24 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Widgets;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Widget;
|
2018-01-10 02:48:24 +08:00
|
|
|
use App\Repositories\AcarsRepository;
|
|
|
|
use App\Services\GeoService;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* Show the live map in a view
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class LiveMap extends Widget
|
2018-01-10 02:48:24 +08:00
|
|
|
{
|
|
|
|
protected $config = [
|
|
|
|
'height' => '800px',
|
2018-03-20 09:50:40 +08:00
|
|
|
'width' => '100%',
|
2018-01-10 02:48:24 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$geoSvc = app(GeoService::class);
|
|
|
|
$acarsRepo = app(AcarsRepository::class);
|
|
|
|
|
2018-05-16 23:54:01 +08:00
|
|
|
$pireps = $acarsRepo->getPositions(setting('acars.live_time', 0));
|
2018-01-10 02:48:24 +08:00
|
|
|
$positions = $geoSvc->getFeatureForLiveFlights($pireps);
|
|
|
|
|
2018-05-16 23:54:01 +08:00
|
|
|
$center_coords = setting('acars.center_coords', '0,0');
|
2018-08-27 00:40:04 +08:00
|
|
|
$center_coords = array_map(function ($c) {
|
2018-05-16 23:54:01 +08:00
|
|
|
return (float) trim($c);
|
|
|
|
}, explode(',', $center_coords));
|
|
|
|
|
2018-03-12 07:00:42 +08:00
|
|
|
return view('widgets.live_map', [
|
2018-08-27 00:40:04 +08:00
|
|
|
'config' => $this->config,
|
|
|
|
'pireps' => $pireps,
|
|
|
|
'positions' => $positions,
|
|
|
|
'center' => $center_coords,
|
|
|
|
'zoom' => setting('acars.default_zoom', 5),
|
2018-01-10 02:48:24 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|