phpvms/app/Widgets/LiveMap.php

45 lines
1.1 KiB
PHP
Raw Normal View History

2018-01-10 02:48:24 +08:00
<?php
namespace App\Widgets;
use App\Contracts\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
*/
class LiveMap extends Widget
2018-01-10 02:48:24 +08:00
{
protected $config = [
'height' => '800px',
'width' => '100%',
'table' => true,
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);
$pireps = $acarsRepo->getPositions(setting('acars.live_time', 0));
2018-01-10 02:48:24 +08:00
$positions = $geoSvc->getFeatureForLiveFlights($pireps);
$center_coords = setting('acars.center_coords', '0,0');
2018-08-27 00:40:04 +08:00
$center_coords = array_map(function ($c) {
return (float) trim($c);
}, explode(',', $center_coords));
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
]);
}
}