diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php
index 4fae24ed..693edcd0 100644
--- a/app/Models/Pirep.php
+++ b/app/Models/Pirep.php
@@ -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');
diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php
index 0f58fe83..aef9cc4d 100644
--- a/app/Services/GeoService.php
+++ b/app/Services/GeoService.php
@@ -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 . '
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'],
];
}
diff --git a/public/assets/system/js/system.js b/public/assets/system/js/system.js
index e32864a7..c5537260 100644
--- a/public/assets/system/js/system.js
+++ b/public/assets/system/js/system.js
@@ -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);
diff --git a/resources/views/layouts/default/pireps/map.blade.php b/resources/views/layouts/default/pireps/map.blade.php
index b4fdbf46..0e431ed9 100644
--- a/resources/views/layouts/default/pireps/map.blade.php
+++ b/resources/views/layouts/default/pireps/map.blade.php
@@ -1,6 +1,6 @@