Cleanup some of the geojson code
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Collection;
|
|||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
use App\Facades\Utils;
|
use App\Facades\Utils;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
class AcarsReplay extends Command
|
class AcarsReplay extends Command
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,13 @@ class AcarsReplay extends Command
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*protected function getArguments()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['--files', InputOption::VALUE_OPTIONAL]
|
||||||
|
];
|
||||||
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a request to start a PIREP
|
* Make a request to start a PIREP
|
||||||
* @param \stdClass $flight
|
* @param \stdClass $flight
|
||||||
@@ -107,13 +115,13 @@ class AcarsReplay extends Command
|
|||||||
$uri = '/api/pirep/' . $pirep_id . '/acars';
|
$uri = '/api/pirep/' . $pirep_id . '/acars';
|
||||||
|
|
||||||
$upd = [
|
$upd = [
|
||||||
'log' => '',
|
'log' => '',
|
||||||
'lat' => $data->latitude,
|
'lat' => $data->latitude,
|
||||||
'lon' => $data->longitude,
|
'lon' => $data->longitude,
|
||||||
'heading' => $data->heading,
|
'heading' => $data->heading,
|
||||||
'altitude' => $data->altitude,
|
'altitude' => $data->altitude,
|
||||||
'gs' => $data->groundspeed,
|
'gs' => $data->groundspeed,
|
||||||
'transponder' => $data->transponder,
|
'transponder' => $data->transponder,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->info("Update: $data->callsign, $upd[lat] x $upd[lon] \t\t"
|
$this->info("Update: $data->callsign, $upd[lat] x $upd[lon] \t\t"
|
||||||
@@ -138,7 +146,7 @@ class AcarsReplay extends Command
|
|||||||
* Parse this file and run the updates
|
* Parse this file and run the updates
|
||||||
* @param array $files
|
* @param array $files
|
||||||
*/
|
*/
|
||||||
protected function runUpdates(array $files)
|
protected function updatesFromFile(array $files)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var $flights Collection
|
* @var $flights Collection
|
||||||
@@ -227,7 +235,7 @@ class AcarsReplay extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->runUpdates(explode(',', $files));
|
$this->updatesFromFile(explode(',', $files));
|
||||||
$this->info('Done!');
|
$this->info('Done!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Services\GeoService;
|
||||||
use Log;
|
use Log;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -20,14 +21,19 @@ use App\Http\Controllers\AppBaseController;
|
|||||||
|
|
||||||
class PirepController extends AppBaseController
|
class PirepController extends AppBaseController
|
||||||
{
|
{
|
||||||
protected $acarsRepo, $pirepRepo, $pirepSvc;
|
protected $acarsRepo,
|
||||||
|
$geoSvc,
|
||||||
|
$pirepRepo,
|
||||||
|
$pirepSvc;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AcarsRepository $acarsRepo,
|
AcarsRepository $acarsRepo,
|
||||||
|
GeoService $geoSvc,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
PIREPService $pirepSvc
|
PIREPService $pirepSvc
|
||||||
) {
|
) {
|
||||||
$this->acarsRepo = $acarsRepo;
|
$this->acarsRepo = $acarsRepo;
|
||||||
|
$this->geoSvc = $geoSvc;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
$this->pirepSvc = $pirepSvc;
|
$this->pirepSvc = $pirepSvc;
|
||||||
}
|
}
|
||||||
@@ -183,11 +189,18 @@ class PirepController extends AppBaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return the GeoJSON for the ACARS line
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
|
* @return \Illuminate\Contracts\Routing\ResponseFactory
|
||||||
*/
|
*/
|
||||||
public function geojson($id, Request $request)
|
public function geojson($id, Request $request)
|
||||||
{
|
{
|
||||||
$pirep = $this->pirepRepo->find($id);
|
$pirep = $this->pirepRepo->find($id);
|
||||||
|
$geodata = $this->geoSvc->getFeatureFromAcars($pirep);
|
||||||
|
|
||||||
|
return response(\json_encode($geodata), 200, [
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-45
@@ -18,11 +18,9 @@ use App\Models\Pirep;
|
|||||||
use App\Repositories\NavdataRepository;
|
use App\Repositories\NavdataRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all of the coordinates, start to finish
|
* Return different points/features in GeoJSON format
|
||||||
* Returned in the GeoJSON format
|
|
||||||
* https://tools.ietf.org/html/rfc7946
|
* https://tools.ietf.org/html/rfc7946
|
||||||
*
|
*
|
||||||
* TODO: Save this data:
|
|
||||||
* Once a PIREP is accepted, save this returned structure as a
|
* Once a PIREP is accepted, save this returned structure as a
|
||||||
* JSON-encoded string into the raw_data field of the PIREP row
|
* JSON-encoded string into the raw_data field of the PIREP row
|
||||||
*
|
*
|
||||||
@@ -36,7 +34,14 @@ class GeoService extends BaseService
|
|||||||
$this->navRepo = $navRepo;
|
$this->navRepo = $navRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClosestCoords($coordStart, $all_coords, $measure='flat')
|
/**
|
||||||
|
* Determine the closest set of coordinates from the starting position
|
||||||
|
* @param array $coordStart
|
||||||
|
* @param array $all_coords
|
||||||
|
* @return mixed
|
||||||
|
* @throws \League\Geotools\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function getClosestCoords($coordStart, $all_coords)
|
||||||
{
|
{
|
||||||
$distance = [];
|
$distance = [];
|
||||||
$geotools = new Geotools();
|
$geotools = new Geotools();
|
||||||
@@ -45,12 +50,7 @@ class GeoService extends BaseService
|
|||||||
foreach($all_coords as $coords) {
|
foreach($all_coords as $coords) {
|
||||||
$coord = new Coordinate($coords);
|
$coord = new Coordinate($coords);
|
||||||
$dist = $geotools->distance()->setFrom($start)->setTo($coord);
|
$dist = $geotools->distance()->setFrom($start)->setTo($coord);
|
||||||
|
$distance[] = $dist->greatCircle();
|
||||||
if($measure === 'flat') {
|
|
||||||
$distance[] = $dist->flat();
|
|
||||||
} elseif ($measure === 'greatcircle') {
|
|
||||||
$distance[] = $dist->greatCircle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$distance = collect($distance);
|
$distance = collect($distance);
|
||||||
@@ -61,7 +61,7 @@ class GeoService extends BaseService
|
|||||||
/**
|
/**
|
||||||
* @param $dep_icao string ICAO to ignore
|
* @param $dep_icao string ICAO to ignore
|
||||||
* @param $arr_icao string ICAO to ignore
|
* @param $arr_icao string ICAO to ignore
|
||||||
* @param $start_coords array [x, y]
|
* @param $start_coords array Starting point, [x, y]
|
||||||
* @param $route string Textual route
|
* @param $route string Textual route
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -86,7 +86,7 @@ class GeoService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Log::info('Looking for ' . $route_point);
|
Log::debug('Looking for ' . $route_point);
|
||||||
|
|
||||||
$points = $this->navRepo->findWhere(['id' => $route_point]);
|
$points = $this->navRepo->findWhere(['id' => $route_point]);
|
||||||
$size = \count($points);
|
$size = \count($points);
|
||||||
@@ -168,9 +168,9 @@ 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 array
|
* @return FeatureCollection
|
||||||
*/
|
*/
|
||||||
protected function getFeatureFromAcars(Pirep $pirep)
|
public function getFeatureFromAcars(Pirep $pirep)
|
||||||
{
|
{
|
||||||
$route_line = [];
|
$route_line = [];
|
||||||
$route_points = [];
|
$route_points = [];
|
||||||
@@ -183,26 +183,19 @@ class GeoService extends BaseService
|
|||||||
foreach ($pirep->acars as $point)
|
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]), [
|
||||||
'name' => $point->altitude,
|
'pirep_id' => $pirep->id,
|
||||||
'popup' => 'GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
|
'name' => $point->altitude,
|
||||||
]);
|
'popup' => 'GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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));
|
||||||
|
|
||||||
# Convert to a feature
|
return new FeatureCollection([$route_line, $route_points]);
|
||||||
$route_line = new Feature(new LineString($route_line), [], 1);
|
|
||||||
|
|
||||||
# TODO: Draw the plane icon from the last point
|
|
||||||
|
|
||||||
return [
|
|
||||||
'line' => new FeatureCollection([$route_line]),
|
|
||||||
'points' => new FeatureCollection($route_points)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,11 +216,12 @@ class GeoService extends BaseService
|
|||||||
$point = $pirep->position;
|
$point = $pirep->position;
|
||||||
$flight_points[] = new Feature(
|
$flight_points[] = new Feature(
|
||||||
new Point([$point->lon, $point->lat]), [
|
new Point([$point->lon, $point->lat]), [
|
||||||
'gs' => $point->gs,
|
'pirep_id' => $pirep->id,
|
||||||
'alt' => $point->altitude,
|
'gs' => $point->gs,
|
||||||
'heading' => $point->heading ?: 0,
|
'alt' => $point->altitude,
|
||||||
'popup' => 'Flight: ' . $pirep->ident,
|
'heading' => $point->heading ?: 0,
|
||||||
]);
|
'popup' => 'Flight: ' . $pirep->ident,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FeatureCollection($flight_points);
|
return new FeatureCollection($flight_points);
|
||||||
@@ -242,7 +236,6 @@ class GeoService extends BaseService
|
|||||||
{
|
{
|
||||||
$route_coords = [];
|
$route_coords = [];
|
||||||
$route_points = [];
|
$route_points = [];
|
||||||
#$features = [];
|
|
||||||
|
|
||||||
## Departure Airport
|
## Departure Airport
|
||||||
$route_coords[] = [$flight->dpt_airport->lon, $flight->dpt_airport->lat];
|
$route_coords[] = [$flight->dpt_airport->lon, $flight->dpt_airport->lat];
|
||||||
@@ -288,8 +281,8 @@ class GeoService extends BaseService
|
|||||||
$planned_route_line = new FeatureCollection([new Feature(new LineString($route_coords), [])]);
|
$planned_route_line = new FeatureCollection([new Feature(new LineString($route_coords), [])]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'route_points' => $route_points,
|
'route_points' => $route_points,
|
||||||
'planned_route_line' => $planned_route_line,
|
'planned_route_line' => $planned_route_line,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,9 +299,9 @@ class GeoService extends BaseService
|
|||||||
$planned_rte_coords[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat];
|
$planned_rte_coords[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat];
|
||||||
$route_points[] = new Feature(
|
$route_points[] = new Feature(
|
||||||
new Point([$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]), [
|
new Point([$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]), [
|
||||||
'name' => $pirep->dpt_airport->icao,
|
'name' => $pirep->dpt_airport->icao,
|
||||||
'popup' => $pirep->dpt_airport->full_name,
|
'popup' => $pirep->dpt_airport->full_name,
|
||||||
'icon' => 'airport',
|
'icon' => 'airport',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -323,9 +316,9 @@ class GeoService extends BaseService
|
|||||||
foreach ($all_route_points as $point) {
|
foreach ($all_route_points as $point) {
|
||||||
$planned_rte_coords[] = [$point->lon, $point->lat];
|
$planned_rte_coords[] = [$point->lon, $point->lat];
|
||||||
$route_points[] = new Feature(new Point([$point->lon, $point->lat]), [
|
$route_points[] = new Feature(new Point([$point->lon, $point->lat]), [
|
||||||
'name' => $point->name,
|
'name' => $point->name,
|
||||||
'popup' => $point->name . ' (' . $point->name . ')',
|
'popup' => $point->name . ' (' . $point->name . ')',
|
||||||
'icon' => ''
|
'icon' => ''
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,9 +326,9 @@ class GeoService extends BaseService
|
|||||||
$planned_rte_coords[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
|
$planned_rte_coords[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
|
||||||
$route_points[] = new Feature(
|
$route_points[] = new Feature(
|
||||||
new Point([$pirep->arr_airport->lon, $pirep->arr_airport->lat]), [
|
new Point([$pirep->arr_airport->lon, $pirep->arr_airport->lat]), [
|
||||||
'name' => $pirep->arr_airport->icao,
|
'name' => $pirep->arr_airport->icao,
|
||||||
'popup' => $pirep->arr_airport->full_name,
|
'popup' => $pirep->arr_airport->full_name,
|
||||||
'icon' => 'airport',
|
'icon' => 'airport',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -350,10 +343,10 @@ class GeoService extends BaseService
|
|||||||
$actual_route = $this->getFeatureFromAcars($pirep);
|
$actual_route = $this->getFeatureFromAcars($pirep);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'route_points' => $route_points,
|
'route_points' => $route_points,
|
||||||
'planned_route_line' => $planned_route,
|
'planned_route_line' => $planned_route,
|
||||||
'actual_route_line' => $actual_route['line'],
|
'actual_route_line' => $actual_route['line'],
|
||||||
'actual_route_points' => $actual_route['points'],
|
'actual_route_points' => $actual_route['points'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
const phpvms = (function() {
|
const phpvms = (function() {
|
||||||
|
|
||||||
|
const PLAN_ROUTE_COLOR = '#36b123';
|
||||||
|
const ACTUAL_ROUTE_COLOR = '#172aea';
|
||||||
|
|
||||||
const draw_base_map = (opts) => {
|
const draw_base_map = (opts) => {
|
||||||
|
|
||||||
opts = _.defaults(opts, {
|
opts = _.defaults(opts, {
|
||||||
@@ -123,7 +126,7 @@ const phpvms = (function() {
|
|||||||
let geodesicLayer = L.geodesic([], {
|
let geodesicLayer = L.geodesic([], {
|
||||||
weight: 7,
|
weight: 7,
|
||||||
opacity: 0.9,
|
opacity: 0.9,
|
||||||
color: '#36b123',
|
color: PLAN_ROUTE_COLOR,
|
||||||
steps: 50,
|
steps: 50,
|
||||||
wrap: false,
|
wrap: false,
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
@@ -137,7 +140,7 @@ const phpvms = (function() {
|
|||||||
onEachFeature: onFeaturePointClick,
|
onEachFeature: onFeaturePointClick,
|
||||||
pointToLayer: pointToLayer,
|
pointToLayer: pointToLayer,
|
||||||
style: {
|
style: {
|
||||||
"color": "#36b123",
|
"color": PLAN_ROUTE_COLOR,
|
||||||
"weight": 5,
|
"weight": 5,
|
||||||
"opacity": 0.65,
|
"opacity": 0.65,
|
||||||
},
|
},
|
||||||
@@ -154,7 +157,7 @@ const phpvms = (function() {
|
|||||||
let geodesicLayer = L.geodesic([], {
|
let geodesicLayer = L.geodesic([], {
|
||||||
weight: 7,
|
weight: 7,
|
||||||
opacity: 0.9,
|
opacity: 0.9,
|
||||||
color: '#172aea',
|
color: ACTUAL_ROUTE_COLOR,
|
||||||
steps: 50,
|
steps: 50,
|
||||||
wrap: false,
|
wrap: false,
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
@@ -168,7 +171,7 @@ const phpvms = (function() {
|
|||||||
onEachFeature: onFeaturePointClick,
|
onEachFeature: onFeaturePointClick,
|
||||||
pointToLayer: pointToLayer,
|
pointToLayer: pointToLayer,
|
||||||
style: {
|
style: {
|
||||||
"color": "#172aea",
|
"color": ACTUAL_ROUTE_COLOR,
|
||||||
"weight": 5,
|
"weight": 5,
|
||||||
"opacity": 0.65,
|
"opacity": 0.65,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user