More work on the pirep/acars maps

This commit is contained in:
Nabeel Shahzad
2017-12-28 14:35:28 -06:00
parent ee328dabc6
commit 9d92d8af55
7 changed files with 40 additions and 50 deletions
+2 -2
View File
@@ -73,7 +73,7 @@ class AcarsReplay extends Command
$flight_number = substr($flight->callsign, 3); $flight_number = substr($flight->callsign, 3);
$response = $this->httpClient->post('/api/pirep/prefile', [ $response = $this->httpClient->post('/api/pireps/prefile', [
'json' => [ 'json' => [
'airline_id' => 1, 'airline_id' => 1,
'flight_number' => $flight_number, 'flight_number' => $flight_number,
@@ -97,7 +97,7 @@ class AcarsReplay extends Command
*/ */
protected function filePirep($pirep_id) protected function filePirep($pirep_id)
{ {
$response = $this->httpClient->post('/api/pirep/'.$pirep_id.'/file', [ $response = $this->httpClient->post('/api/pireps/'.$pirep_id.'/file', [
'json'=> [] 'json'=> []
]); ]);
+8 -21
View File
@@ -151,16 +151,19 @@ class PirepController extends AppBaseController
} }
/** /**
* Get all of the ACARS updates for a PIREP * Return the GeoJSON for the ACARS line
* @param $id * @param $id
* @return AcarsResource * @param Request $request
* @return \Illuminate\Contracts\Routing\ResponseFactory
*/ */
public function acars_get($id) public function acars_get($id, Request $request)
{ {
$pirep = $this->pirepRepo->find($id); $pirep = $this->pirepRepo->find($id);
$geodata = $this->geoSvc->getFeatureFromAcars($pirep);
$updates = $this->acarsRepo->forPirep($id); return response(\json_encode($geodata), 200, [
return new AcarsResource($updates); 'Content-Type' => 'application/json',
]);
} }
/** /**
@@ -187,20 +190,4 @@ class PirepController extends AppBaseController
AcarsResource::withoutWrapping(); AcarsResource::withoutWrapping();
return new AcarsResource($update); return new AcarsResource($update);
} }
/**
* Return the GeoJSON for the ACARS line
* @param $id
* @param Request $request
* @return \Illuminate\Contracts\Routing\ResponseFactory
*/
public function geojson($id, Request $request)
{
$pirep = $this->pirepRepo->find($id);
$geodata = $this->geoSvc->getFeatureFromAcars($pirep);
return response(\json_encode($geodata), 200, [
'Content-Type' => 'application/json',
]);
}
} }
+1 -1
View File
@@ -94,7 +94,7 @@ class Pirep extends BaseModel
public function acars() public function acars()
{ {
return $this->hasMany('App\Models\Acars', 'pirep_id') return $this->hasMany('App\Models\Acars', 'pirep_id')
->orderBy('created_at', 'desc'); ->orderBy('created_at', 'asc');
} }
public function aircraft() public function aircraft()
+15 -16
View File
@@ -5,14 +5,15 @@
*/ */
Route::group([], function() Route::group([], function()
{ {
Route::match(['get'], 'acars', 'AcarsController@index'); Route::get('acars', 'AcarsController@index');
Route::match(['get'], 'flights/search', 'FlightController@search'); Route::get('flights/search', 'FlightController@search');
Route::match(['get'], 'flights/{id}', 'FlightController@get'); Route::get('flights/{id}', 'FlightController@get');
Route::match(['post'], 'pirep/{id}/geojson', 'PirepController@file'); Route::get('pireps/{id}/acars', 'PirepController@acars_get');
Route::get('pireps/{id}/geojson', 'PirepController@acars_get');
Route::match(['get'], 'status', 'BaseController@status'); Route::get('status', 'BaseController@status');
}); });
/** /**
@@ -20,19 +21,17 @@ Route::group([], function()
*/ */
Route::group(['middleware' => ['api.auth']], function () Route::group(['middleware' => ['api.auth']], function ()
{ {
Route::match(['get'], 'airports/{id}', 'AirportController@get'); Route::get('airports/{id}', 'AirportController@get');
Route::match(['get'], 'airports/{id}/lookup', 'AirportController@lookup'); Route::get('airports/{id}/lookup', 'AirportController@lookup');
Route::match(['get'], 'pirep/{id}', 'PirepController@get'); Route::get('pireps/{id}', 'PirepController@get');
Route::match(['post'], 'pirep/prefile', 'PirepController@prefile'); Route::post('pireps/prefile', 'PirepController@prefile');
Route::match(['post'], 'pirep/{id}/file', 'PirepController@file'); Route::post('pireps/{id}/file', 'PirepController@file');
Route::match(['get'], 'pirep/{id}/acars', 'PirepController@acars_get'); Route::post('pireps/{id}/acars', 'PirepController@acars_store');
Route::match(['post'], 'pirep/{id}/acars', 'PirepController@acars_store');
# This is the info of the user whose token is in use # This is the info of the user whose token is in use
Route::match(['get'], 'user', 'UserController@index'); Route::get('user', 'UserController@index');
#Route::match(['get'], 'user/bids', 'UserController@index'); Route::get('users/{id}', 'UserController@get');
Route::match(['get'], 'users/{id}', 'UserController@get'); Route::get('users/{id}/bids', 'UserController@bids');
Route::match(['get'], 'users/{id}/bids', 'UserController@bids');
}); });
+12 -10
View File
@@ -168,34 +168,36 @@ class GeoService extends BaseService
/** /**
* Read an array/relationship of ACARS model points * Read an array/relationship of ACARS model points
* @param Pirep $pirep * @param Pirep $pirep
* @return FeatureCollection * @return array
*/ */
public function getFeatureFromAcars(Pirep $pirep) public function getFeatureFromAcars(Pirep $pirep)
{ {
$route_line = []; $route_line = [];
$route_points = []; $route_points = [];
$route_line[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]; $route_line[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat];
/** /**
* @var $point \App\Models\Acars * @var $point \App\Models\Acars
*/ */
foreach ($pirep->acars as $point) $counter = 1;
{ foreach ($pirep->acars as $point) {
$route_line[] = [$point->lon, $point->lat]; $route_line[] = [$point->lon, $point->lat];
$route_points[] = new Feature( $route_points[] = new Feature(
new Point([$point->lon, $point->lat]), [ new Point([$point->lon, $point->lat]), [
'pirep_id' => $pirep->id, 'name' => $point->altitude,
'name' => $point->altitude, 'popup' => $counter . '<br />GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
'popup' => 'GS: ' . $point->gs . '<br />Alt: ' . $point->altitude, ]);
]);
}
$counter += 1;
}
# Arrival # Arrival
$route_line[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat]; $route_line[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
$route_line = new Feature(new LineString($route_line)); $route_line = new Feature(new LineString($route_line));
return new FeatureCollection([$route_line, $route_points]); return [
'line' => new FeatureCollection([$route_line]),
'points' => new FeatureCollection($route_points)
];
} }
/** /**
+1
View File
@@ -218,6 +218,7 @@ const phpvms = (function() {
opts = _.defaults(opts, { opts = _.defaults(opts, {
update_uri: '/api/acars', update_uri: '/api/acars',
pirep_uri: '/api/pireps/{id}/acars',
positions: null, positions: null,
render_elem: 'map', render_elem: 'map',
aircraft_icon: '/assets/img/acars/aircraft.png', aircraft_icon: '/assets/img/acars/aircraft.png',
@@ -13,6 +13,7 @@
<script type="text/javascript"> <script type="text/javascript">
phpvms.render_live_map({ phpvms.render_live_map({
'update_uri': '{!! url('/api/acars') !!}', 'update_uri': '{!! url('/api/acars') !!}',
'pirep_uri': '{!! url('/api/pireps/{id}/acars') !!}',
'aircraft_icon': '{!! public_asset('/assets/img/acars/aircraft.png') !!}', 'aircraft_icon': '{!! public_asset('/assets/img/acars/aircraft.png') !!}',
}); });
</script> </script>