Output PIREP map with just the dep/arr airports for now
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Frontend;
|
||||
use App\Facades\Utils;
|
||||
use App\Models\Enums\PirepSource;
|
||||
use App\Repositories\Criteria\WhereCriteria;
|
||||
use App\Services\GeoService;
|
||||
use App\Services\PIREPService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -27,6 +28,7 @@ class PirepController extends Controller
|
||||
$pirepRepo,
|
||||
$airportRepo,
|
||||
$pirepFieldRepo,
|
||||
$geoSvc,
|
||||
$pirepSvc;
|
||||
|
||||
public function __construct(
|
||||
@@ -35,6 +37,7 @@ class PirepController extends Controller
|
||||
AircraftRepository $aircraftRepo,
|
||||
AirportRepository $airportRepo,
|
||||
PirepFieldRepository $pirepFieldRepo,
|
||||
GeoService $geoSvc,
|
||||
PIREPService $pirepSvc
|
||||
) {
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
@@ -42,6 +45,8 @@ class PirepController extends Controller
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
$this->airportRepo = $airportRepo;
|
||||
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||
|
||||
$this->geoSvc = $geoSvc;
|
||||
$this->pirepSvc = $pirepSvc;
|
||||
}
|
||||
|
||||
@@ -110,8 +115,16 @@ class PirepController extends Controller
|
||||
{
|
||||
#$pirep = Pirep::where('id', $id);
|
||||
$pirep = $this->pirepRepo->find($id);
|
||||
if (empty($pirep)) {
|
||||
Flash::error('Pirep not found');
|
||||
return redirect(route('frontend.pirep.index'));
|
||||
}
|
||||
|
||||
$coords = $this->geoSvc->getRouteCoordsGeoJSON($pirep);
|
||||
|
||||
return $this->view('pireps.show', [
|
||||
'pirep' => $pirep,
|
||||
'coords' => $coords,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class Airport extends Model
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*
|
||||
@@ -42,7 +43,8 @@ class Airport extends Model
|
||||
/**
|
||||
* Some fancy callbacks
|
||||
*/
|
||||
protected static function boot() {
|
||||
protected static function boot()
|
||||
{
|
||||
|
||||
parent::boot();
|
||||
|
||||
@@ -54,4 +56,14 @@ class Airport extends Model
|
||||
$model->id = $model->icao;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return full name like:
|
||||
* KJFK - John F Kennedy
|
||||
* @return string
|
||||
*/
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
return $this->icao . ' - ' . $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,11 @@ class Pirep extends Model
|
||||
return $this->user();
|
||||
}
|
||||
|
||||
public function route()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\User', 'user_id');
|
||||
|
||||
72
app/Services/GeoService.php
Normal file
72
app/Services/GeoService.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
//use \League\Geotools\Geotools;
|
||||
use \GeoJson\Geometry\LineString;
|
||||
use \GeoJson\Feature\Feature;
|
||||
use \GeoJson\Feature\FeatureCollection;
|
||||
|
||||
use \League\Geotools\Geotools;
|
||||
use \League\Geotools\Coordinate\Coordinate;
|
||||
|
||||
class GeoService extends BaseService
|
||||
{
|
||||
/**
|
||||
* Return all of the coordinates, start to finish
|
||||
* Returned in the GeoJSON format
|
||||
* https://tools.ietf.org/html/rfc7946
|
||||
*
|
||||
* TODO: Save this data:
|
||||
* Once a PIREP is accepted, save this returned structure as a
|
||||
* JSON-encoded string into the raw_data field of the PIREP row
|
||||
*
|
||||
* @param \App\Models\Pirep|\App\Models\Flight $model
|
||||
* @return array
|
||||
*/
|
||||
public function getRouteCoordsGeoJSON($model): array
|
||||
{
|
||||
# NOTE!! GeoJSON takes coords in [lon, lat] format!!
|
||||
$line = new LineString([
|
||||
[$model->dpt_airport->lon, $model->dpt_airport->lat],
|
||||
[$model->arr_airport->lon, $model->arr_airport->lat],
|
||||
]);
|
||||
|
||||
// TODO: Add markers for the start/end airports
|
||||
// TODO: Read from the ACARS data table
|
||||
|
||||
$feature = new Feature($line, [], 1);
|
||||
$features = new FeatureCollection([$feature]);
|
||||
|
||||
return [
|
||||
'features' => $features,
|
||||
//'center' => $center,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the center point between two sets of coordinates
|
||||
* @param $latA
|
||||
* @param $lonA
|
||||
* @param $latB
|
||||
* @param $lonB
|
||||
* @return array
|
||||
* @throws \League\Geotools\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function getCenter($latA, $lonA, $latB, $lonB)
|
||||
{
|
||||
$geotools = new Geotools();
|
||||
$coordA = new Coordinate([$latA, $lonA]);
|
||||
$coordB = new Coordinate([$latB, $lonB]);
|
||||
|
||||
$vertex = $geotools->vertex()->setFrom($coordA)->setTo($coordB);
|
||||
$middlePoint = $vertex->middle();
|
||||
|
||||
$center = [
|
||||
$middlePoint->getLatitude(),
|
||||
$middlePoint->getLongitude()
|
||||
];
|
||||
|
||||
return $center;
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class PIREPService extends BaseService
|
||||
/**
|
||||
* @param Pirep $pirep
|
||||
*/
|
||||
public function setPilotState(Pirep &$pirep)
|
||||
public function setPilotState(Pirep $pirep)
|
||||
{
|
||||
$pilot = $pirep->pilot;
|
||||
$pilot->refresh();
|
||||
|
||||
Reference in New Issue
Block a user