Convert live acars map into a widget

This commit is contained in:
Nabeel Shahzad
2018-01-09 12:48:24 -06:00
parent 458ee93974
commit 26d3a7f4d6
6 changed files with 74 additions and 41 deletions

View File

@@ -2,7 +2,6 @@
namespace App\Http\Controllers\Frontend;
use App\Models\Pirep;
use App\Repositories\AcarsRepository;
use App\Services\GeoService;
use Illuminate\Http\Request;

32
app/Widgets/LiveMap.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Widgets;
use App\Repositories\AcarsRepository;
use App\Services\GeoService;
class LiveMap extends BaseWidget
{
protected $config = [
'height' => '800px',
'width' => '100%',
];
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function run()
{
$geoSvc = app(GeoService::class);
$acarsRepo = app(AcarsRepository::class);
$pireps = $acarsRepo->getPositions();
$positions = $geoSvc->getFeatureForLiveFlights($pireps);
return $this->view('widgets.live_map', [
'config' => $this->config,
'pireps' => $pireps,
'positions' => $positions,
]);
}
}

View File

@@ -2,8 +2,6 @@
@section('title', 'live map')
@section('content')
@include('layouts.default.acars.map')
<div class="clearfix" style="padding-top: 25px"></div>
@include('layouts.default.acars.table')
{{ Widget::liveMap() }}
@endsection

View File

@@ -1,20 +0,0 @@
<div class="row">
<div class="col-md-12">
<h3 class="description">flight map</h3>
</div>
<div class="col-12">
<div class="box-body">
<div id="map" style="width: 100%; height: 800px"></div>
</div>
</div>
</div>
@section('scripts')
<script type="text/javascript">
phpvms.render_live_map({
'update_uri': '{!! url('/api/acars') !!}',
'pirep_uri': '{!! url('/api/pireps/{id}/acars/geojson') !!}',
'aircraft_icon': '{!! public_asset('/assets/img/acars/aircraft.png') !!}',
});
</script>
@endsection

View File

@@ -1,17 +0,0 @@
<div id="flights_table" class="row">
<div class="col-md-12">
<h3 class="description">flights</h3>
<table class="table">
@foreach($pireps as $pirep)
<tr>
<td>{!! $pirep->ident !!}</td>
<td>{!! $pirep->dpt_airport_id !!}</td>
<td>{!! $pirep->arr_airport_id !!}</td>
<td>
{!! PirepStatus::label($pirep->status); !!}
</td>
</tr>
@endforeach
</table>
</div>
</div>

View File

@@ -0,0 +1,41 @@
<div class="row">
<div class="col-md-12">
<h3 class="description">flight map</h3>
<div class="box-body">
<div id="map" style="width: {!! $config['width'] !!}; height: {!! $config['height'] !!}"></div>
</div>
</div>
</div>
<div class="clearfix" style="padding-top: 25px"></div>
<div id="flights_table" class="row">
<div class="col-md-12">
<h3 class="description">flights</h3>
@if(!filled($pireps))
<div class="text-center">There are no flights</div>
@endif
<table class="table">
@foreach($pireps as $pirep)
<tr>
<td>{!! $pirep->ident !!}</td>
<td>{!! $pirep->dpt_airport_id !!}</td>
<td>{!! $pirep->arr_airport_id !!}</td>
<td>
{!! PirepStatus::label($pirep->status); !!}
</td>
</tr>
@endforeach
</table>
</div>
</div>
@section('scripts')
<script type="text/javascript">
phpvms.render_live_map({
'update_uri': '{!! url('/api/acars') !!}',
'pirep_uri': '{!! url('/api/pireps/{id}/acars/geojson') !!}',
'aircraft_icon': '{!! public_asset('/assets/img/acars/aircraft.png') !!}',
});
</script>
@endsection