plot actual flight path and datapoints from ACARS table
This commit is contained in:
@@ -90,6 +90,12 @@ class Pirep extends BaseModel
|
||||
/**
|
||||
* Foreign Keys
|
||||
*/
|
||||
|
||||
public function acars()
|
||||
{
|
||||
return $this->hasMany('App\Models\Acars', 'pirep_id');
|
||||
}
|
||||
|
||||
public function aircraft()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Aircraft', 'aircraft_id');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Acars;
|
||||
use Log;
|
||||
|
||||
use \GeoJson\Geometry\Point;
|
||||
@@ -13,6 +14,7 @@ use \League\Geotools\Geotools;
|
||||
use \League\Geotools\Coordinate\Coordinate;
|
||||
|
||||
use App\Models\Flight;
|
||||
use App\Models\Pirep;
|
||||
use App\Repositories\NavdataRepository;
|
||||
|
||||
/**
|
||||
@@ -137,6 +139,44 @@ class GeoService extends BaseService
|
||||
return $coords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an array/relationship of ACARS model points
|
||||
* @param Pirep $pirep
|
||||
* @return array
|
||||
*/
|
||||
protected function getFeatureFromAcars(Pirep $pirep)
|
||||
{
|
||||
$route_line = [];
|
||||
$route_points = [];
|
||||
|
||||
$route_line[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat];
|
||||
|
||||
/**
|
||||
* @var $point \App\Models\Acars
|
||||
*/
|
||||
foreach ($pirep->acars as $point)
|
||||
{
|
||||
$route_line[] = [$point->lon, $point->lat];
|
||||
|
||||
$route_points[] = new Feature(
|
||||
new Point([$point->lon, $point->lat]), [
|
||||
'name' => $point->altitude,
|
||||
'popup' => 'GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
|
||||
]);
|
||||
}
|
||||
|
||||
# Arrival
|
||||
$route_line[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
|
||||
|
||||
# Convert to a feature
|
||||
$route_line = new Feature(new LineString($route_line), [], 1);
|
||||
|
||||
return [
|
||||
'line' => new FeatureCollection([$route_line]),
|
||||
'points' => new FeatureCollection($route_points)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a FeatureCollection GeoJSON object
|
||||
* @param Flight $flight
|
||||
@@ -202,7 +242,7 @@ class GeoService extends BaseService
|
||||
* @param Pirep $pirep
|
||||
* @return array
|
||||
*/
|
||||
public function pirepGeoJson($pirep)
|
||||
public function pirepGeoJson(Pirep $pirep)
|
||||
{
|
||||
$route_points = [];
|
||||
$planned_rte_coords = [];
|
||||
@@ -216,9 +256,6 @@ class GeoService extends BaseService
|
||||
]
|
||||
);
|
||||
|
||||
// TODO: Add markers for the start/end airports
|
||||
|
||||
// TODO: Check if there's data in the ACARS table
|
||||
if (!empty($pirep->route)) {
|
||||
$all_route_points = $this->getCoordsFromRoute(
|
||||
$pirep->dpt_airport->icao,
|
||||
@@ -249,15 +286,18 @@ class GeoService extends BaseService
|
||||
$route_points = new FeatureCollection($route_points);
|
||||
|
||||
$planned_route_line = new LineString($planned_rte_coords);
|
||||
|
||||
$planned_route = new FeatureCollection([
|
||||
new Feature($planned_route_line, [], 1)
|
||||
]);
|
||||
|
||||
|
||||
$actual_route = $this->getFeatureFromAcars($pirep);
|
||||
|
||||
return [
|
||||
'actual_route' => false,
|
||||
'route_points' => $route_points,
|
||||
'planned_route_line' => $planned_route,
|
||||
'actual_route_line' => $actual_route['line'],
|
||||
'actual_route_points' => $actual_route['points'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const phpvms= (function() {
|
||||
const phpvms = (function() {
|
||||
|
||||
const draw_base_map = (opts) => {
|
||||
|
||||
@@ -75,6 +75,17 @@ const phpvms= (function() {
|
||||
layer.bindPopup(popup_html);
|
||||
};
|
||||
|
||||
const pointToLayer = function (feature, latlng) {
|
||||
return L.circleMarker(latlng, {
|
||||
radius: 12,
|
||||
fillColor: "#ff7800",
|
||||
color: "#000",
|
||||
weight: 1,
|
||||
opacity: 1,
|
||||
fillOpacity: 0.8
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
@@ -86,6 +97,7 @@ const phpvms= (function() {
|
||||
opts = _.defaults(opts, {
|
||||
route_points: null,
|
||||
planned_route_line: null, // [ {name, lat, lon}, {name, lat, lon} ];
|
||||
actual_route_points: null,
|
||||
actual_route_line: null,
|
||||
center: [],
|
||||
render_elem: 'map',
|
||||
@@ -98,48 +110,78 @@ const phpvms= (function() {
|
||||
|
||||
let map = draw_base_map(opts);
|
||||
|
||||
if(opts.geodesic) {
|
||||
//if(opts.geodesic) {
|
||||
let geodesicLayer = L.geodesic([], {
|
||||
weight: 7,
|
||||
opacity: 0.5,
|
||||
color: '#ff33ee',
|
||||
opacity: 0.9,
|
||||
color: '#36b123',
|
||||
steps: 50,
|
||||
wrap: false,
|
||||
}).addTo(map);
|
||||
|
||||
geodesicLayer.geoJson(opts.planned_route_line);
|
||||
map.fitBounds(geodesicLayer.getBounds());
|
||||
} else {
|
||||
|
||||
if(opts.actual_route_line !== null) {
|
||||
let geodesicLayer = L.geodesic([], {
|
||||
weight: 7,
|
||||
opacity: 0.9,
|
||||
color: '#172aea',
|
||||
steps: 50,
|
||||
wrap: false,
|
||||
}).addTo(map);
|
||||
|
||||
geodesicLayer.geoJson(opts.actual_route_line);
|
||||
map.fitBounds(geodesicLayer.getBounds());
|
||||
}
|
||||
/*} else {
|
||||
let route = L.geoJSON(opts.planned_route_line, {
|
||||
"color": "#ff7800",
|
||||
"weight": 5,
|
||||
"opacity": 0.65
|
||||
"weight": 7,
|
||||
"opacity": 0.9
|
||||
});
|
||||
|
||||
route.addTo(map);
|
||||
map.fitBounds(route.getBounds());
|
||||
}
|
||||
|
||||
if(opts.actual_route_line !== null) {
|
||||
let route = L.geoJSON(opts.actual_route_line, {
|
||||
"color": "#36b123",
|
||||
"weight": 7,
|
||||
"opacity": 0.9
|
||||
});
|
||||
|
||||
route.addTo(map);
|
||||
map.fitBounds(route.getBounds());
|
||||
}
|
||||
}*/
|
||||
|
||||
// Draw the route points after
|
||||
if (opts.route_points !== null) {
|
||||
console.log(opts.route_points);
|
||||
let route_points = L.geoJSON(opts.route_points, {
|
||||
onEachFeature: onFeaturePointClick,
|
||||
pointToLayer: pointToLayer,
|
||||
style: {
|
||||
"color": "#1bff00",
|
||||
"color": "#36b123",
|
||||
"weight": 5,
|
||||
"opacity": 0.65,
|
||||
},
|
||||
});
|
||||
|
||||
route_points.addTo(map);
|
||||
}
|
||||
|
||||
|
||||
if(opts.actual_route_points !== null) {
|
||||
let route_points = L.geoJSON(opts.actual_route_points, {
|
||||
onEachFeature: onFeaturePointClick,
|
||||
pointToLayer: pointToLayer,
|
||||
style: {
|
||||
"color": "#172aea",
|
||||
"weight": 5,
|
||||
"opacity": 0.65,
|
||||
},
|
||||
pointToLayer: function (feature, latlng) {
|
||||
return L.circleMarker(latlng, {
|
||||
radius: 12,
|
||||
fillColor: "#ff7800",
|
||||
color: "#000",
|
||||
weight: 1,
|
||||
opacity: 1,
|
||||
fillOpacity: 0.8
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
route_points.addTo(map);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3 class="description">map</h3>
|
||||
<h3 class="description">flight map</h3>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="box-body">
|
||||
@@ -14,6 +14,8 @@
|
||||
phpvms.render_route_map({
|
||||
route_points: {!! json_encode($map_features['route_points']) !!},
|
||||
planned_route_line: {!! json_encode($map_features['planned_route_line']); !!},
|
||||
actual_route_line: {!! json_encode($map_features['actual_route_line']); !!},
|
||||
actual_route_points: {!! json_encode($map_features['actual_route_points']); !!},
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if(count($pirep->fields) > 0)
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3 class="description">fields</h3>
|
||||
@@ -89,6 +90,7 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@include('layouts.default.pireps.map')
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user