Add markers for the navpoints on the flight and pirep maps
This commit is contained in:
parent
a5196136dc
commit
70b1476e93
1
Makefile
1
Makefile
@ -59,6 +59,7 @@ reset: clean
|
|||||||
reload-db:
|
reload-db:
|
||||||
@php artisan database:create --reset
|
@php artisan database:create --reset
|
||||||
@php artisan migrate:refresh --seed
|
@php artisan migrate:refresh --seed
|
||||||
|
@php artisan phpvms:navdata
|
||||||
|
|
||||||
.PHONY: tests
|
.PHONY: tests
|
||||||
tests: test
|
tests: test
|
||||||
|
@ -127,11 +127,11 @@ class FlightController extends AppBaseController
|
|||||||
return redirect(route('frontend.dashboard.index'));
|
return redirect(route('frontend.dashboard.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$coords = $this->geoSvc->flightGeoJson($flight);
|
$map_features = $this->geoSvc->flightGeoJson($flight);
|
||||||
|
|
||||||
return $this->view('flights.show', [
|
return $this->view('flights.show', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'coords' => $coords,
|
'map_features' => $map_features,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,11 +120,11 @@ class PirepController extends Controller
|
|||||||
return redirect(route('frontend.pirep.index'));
|
return redirect(route('frontend.pirep.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$coords = $this->geoSvc->pirepGeoJson($pirep);
|
$map_featuers = $this->geoSvc->pirepGeoJson($pirep);
|
||||||
|
|
||||||
return $this->view('pireps.show', [
|
return $this->view('pireps.show', [
|
||||||
'pirep' => $pirep,
|
'pirep' => $pirep,
|
||||||
'coords' => $coords,
|
'map_features' => $map_featuers,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,4 +42,16 @@ class NavaidType extends EnumBase
|
|||||||
NavaidType::ANY_VOR => 'VOR',
|
NavaidType::ANY_VOR => 'VOR',
|
||||||
NavaidType::ANY_LOC => 'Localizer',
|
NavaidType::ANY_LOC => 'Localizer',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static $icons = [
|
||||||
|
NavaidType::VOR => 'VOR',
|
||||||
|
NavaidType::VOR_DME => 'VOR DME',
|
||||||
|
NavaidType::LOC => 'Localizer',
|
||||||
|
NavaidType::LOC_DME => 'Localizer DME',
|
||||||
|
NavaidType::NDB => 'Non-directional Beacon',
|
||||||
|
NavaidType::TACAN => 'TACAN',
|
||||||
|
NavaidType::UNKNOWN => 'Unknown',
|
||||||
|
NavaidType::ANY_VOR => 'VOR',
|
||||||
|
NavaidType::ANY_LOC => 'Localizer',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,18 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use Log;
|
use Log;
|
||||||
//use \League\Geotools\Geotools;
|
|
||||||
use App\Models\Flight;
|
use \GeoJson\Geometry\Point;
|
||||||
use App\Repositories\NavdataRepository;
|
|
||||||
use \GeoJson\Geometry\LineString;
|
use \GeoJson\Geometry\LineString;
|
||||||
use \GeoJson\Feature\Feature;
|
use \GeoJson\Feature\Feature;
|
||||||
use \GeoJson\Feature\FeatureCollection;
|
use \GeoJson\Feature\FeatureCollection;
|
||||||
|
|
||||||
use League\Flysystem\Exception;
|
|
||||||
use \League\Geotools\Geotools;
|
use \League\Geotools\Geotools;
|
||||||
use \League\Geotools\Coordinate\Coordinate;
|
use \League\Geotools\Coordinate\Coordinate;
|
||||||
|
|
||||||
|
use App\Models\Flight;
|
||||||
|
use App\Repositories\NavdataRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all of the coordinates, start to finish
|
* Return all of the coordinates, start to finish
|
||||||
* Returned in the GeoJSON format
|
* Returned in the GeoJSON format
|
||||||
@ -33,7 +34,6 @@ class GeoService extends BaseService
|
|||||||
$this->navRepo = $navRepo;
|
$this->navRepo = $navRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getClosestCoords($coordStart, $all_coords, $measure='flat')
|
public function getClosestCoords($coordStart, $all_coords, $measure='flat')
|
||||||
{
|
{
|
||||||
$distance = [];
|
$distance = [];
|
||||||
@ -92,39 +92,41 @@ class GeoService extends BaseService
|
|||||||
if($size === 0) {
|
if($size === 0) {
|
||||||
continue;
|
continue;
|
||||||
} else if($size === 1) {
|
} else if($size === 1) {
|
||||||
|
|
||||||
$point = $points[0];
|
$point = $points[0];
|
||||||
|
|
||||||
Log::info('name: ' . $point->id . ' - ' . $point->lat . 'x' . $point->lon);
|
Log::info('name: ' . $point->id . ' - ' . $point->lat . 'x' . $point->lon);
|
||||||
|
$coords[] = $point;
|
||||||
$coords[] = [
|
|
||||||
$point->lat,
|
|
||||||
$point->lon,
|
|
||||||
];
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Find the point with the shortest distance
|
# Find the point with the shortest distance
|
||||||
Log::info('found ' . $size . ' for '. $route_point);
|
Log::info('found ' . $size . ' for '. $route_point);
|
||||||
|
|
||||||
$potential_coords = [];
|
|
||||||
foreach($points as $point) {
|
|
||||||
#Log::debug('name: ' . $point->id . ' - '.$point->lat .'x'.$point->lon);
|
|
||||||
$potential_coords[] = [$point->lat, $point->lon];
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get the start point and then reverse the lat/lon reference
|
# Get the start point and then reverse the lat/lon reference
|
||||||
# If the first point happens to have multiple possibilities, use
|
# If the first point happens to have multiple possibilities, use
|
||||||
# the starting point that was passed in
|
# the starting point that was passed in
|
||||||
if(\count($coords) > 0) {
|
if (\count($coords) > 0) {
|
||||||
$start_point = $coords[\count($coords) - 1];
|
$start_point = $coords[\count($coords) - 1];
|
||||||
$start_point = [$start_point[0], $start_point[1]];
|
$start_point = [$start_point->lat, $start_point->lon];
|
||||||
} else {
|
} else {
|
||||||
$start_point = $start_coords;
|
$start_point = $start_coords;
|
||||||
}
|
}
|
||||||
|
|
||||||
$coords[] = $this->getClosestCoords($start_point, $potential_coords);
|
# Put all of the lat/lon sets into an array to pick of what's clsest
|
||||||
|
# to the starting point
|
||||||
|
$potential_coords = [];
|
||||||
|
foreach($points as $point) {
|
||||||
|
$potential_coords[] = [$point->lat, $point->lon];
|
||||||
|
}
|
||||||
|
|
||||||
|
# returns an array with the closest lat/lon to start point
|
||||||
|
$closest_coords = $this->getClosestCoords($start_point, $potential_coords);
|
||||||
|
foreach($points as $point) {
|
||||||
|
if($point->lat === $closest_coords[0] && $point->lon === $closest_coords[1]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$coords[] = $point;
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error($e);
|
Log::error($e);
|
||||||
@ -142,34 +144,56 @@ class GeoService extends BaseService
|
|||||||
*/
|
*/
|
||||||
public function flightGeoJson(Flight $flight): array
|
public function flightGeoJson(Flight $flight): array
|
||||||
{
|
{
|
||||||
$coords = [];
|
$route_coords = [];
|
||||||
$coords[] = [$flight->dpt_airport->lon, $flight->dpt_airport->lat];
|
$route_points = [];
|
||||||
|
#$features = [];
|
||||||
|
|
||||||
|
## Departure Airport
|
||||||
|
$route_coords[] = [$flight->dpt_airport->lon, $flight->dpt_airport->lat];
|
||||||
|
|
||||||
|
$route_points[] = new Feature(
|
||||||
|
new Point([$flight->dpt_airport->lon, $flight->dpt_airport->lat]), [
|
||||||
|
'name' => $flight->dpt_airport->icao,
|
||||||
|
'popup' => $flight->dpt_airport->full_name,
|
||||||
|
'icon' => 'airport',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Add markers for the start/end airports
|
|
||||||
// TODO: Read from the ACARS data table
|
|
||||||
if($flight->route) {
|
if($flight->route) {
|
||||||
$route_coords =$this->getCoordsFromRoute(
|
$all_route_points = $this->getCoordsFromRoute(
|
||||||
$flight->dpt_airport->icao,
|
$flight->dpt_airport->icao,
|
||||||
$flight->arr_airport->icao,
|
$flight->arr_airport->icao,
|
||||||
[$flight->dpt_airport->lat, $flight->dpt_airport->lon],
|
[$flight->dpt_airport->lat, $flight->dpt_airport->lon],
|
||||||
$flight->route);
|
$flight->route);
|
||||||
|
|
||||||
// lat, lon needs to be reversed for GeoJSON
|
// lat, lon needs to be reversed for GeoJSON
|
||||||
foreach($route_coords as $rc) {
|
foreach($all_route_points as $point) {
|
||||||
$coords[] = [$rc[1], $rc[0]];
|
$route_coords[] = [$point->lon, $point->lat];
|
||||||
}
|
$route_points[] = new Feature(new Point([$point->lon, $point->lat]), [
|
||||||
}
|
'name' => $point->name,
|
||||||
|
'popup' => $point->name . ' (' . $point->name . ')',
|
||||||
$coords[] = [$flight->arr_airport->lon, $flight->arr_airport->lat];
|
'icon' => ''
|
||||||
|
|
||||||
$line = new LineString($coords);
|
|
||||||
|
|
||||||
$features = new FeatureCollection([
|
|
||||||
new Feature($line, [], 1)
|
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## Arrival Airport
|
||||||
|
$route_coords[] = [$flight->arr_airport->lon, $flight->arr_airport->lat,];
|
||||||
|
|
||||||
|
$route_points[] = new Feature(
|
||||||
|
new Point([$flight->arr_airport->lon, $flight->arr_airport->lat]), [
|
||||||
|
'name' => $flight->arr_airport->icao,
|
||||||
|
'popup' => $flight->arr_airport->full_name,
|
||||||
|
'icon' => 'airport',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$route_points = new FeatureCollection($route_points);
|
||||||
|
$planned_route_line = new FeatureCollection([new Feature(new LineString($route_coords), [])]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'features' => $features,
|
'route_points' => $route_points,
|
||||||
|
'planned_route_line' => $planned_route_line,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,35 +204,60 @@ class GeoService extends BaseService
|
|||||||
*/
|
*/
|
||||||
public function pirepGeoJson($pirep)
|
public function pirepGeoJson($pirep)
|
||||||
{
|
{
|
||||||
$coords = [];
|
$route_points = [];
|
||||||
$coords[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat];
|
$planned_rte_coords = [];
|
||||||
|
|
||||||
|
$planned_rte_coords[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat];
|
||||||
|
$route_points[] = new Feature(
|
||||||
|
new Point([$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]), [
|
||||||
|
'name' => $pirep->dpt_airport->icao,
|
||||||
|
'popup' => $pirep->dpt_airport->full_name,
|
||||||
|
'icon' => 'airport',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Add markers for the start/end airports
|
// TODO: Add markers for the start/end airports
|
||||||
|
|
||||||
// TODO: Check if there's data in the ACARS table
|
// TODO: Check if there's data in the ACARS table
|
||||||
if (!empty($pirep->route)) {
|
if (!empty($pirep->route)) {
|
||||||
$route_coords = $this->getCoordsFromRoute(
|
$all_route_points = $this->getCoordsFromRoute(
|
||||||
$pirep->dpt_airport->icao,
|
$pirep->dpt_airport->icao,
|
||||||
$pirep->arr_airport->icao,
|
$pirep->arr_airport->icao,
|
||||||
[$pirep->dpt_airport->lat, $pirep->dpt_airport->lon],
|
[$pirep->dpt_airport->lat, $pirep->dpt_airport->lon],
|
||||||
$pirep->route);
|
$pirep->route);
|
||||||
|
|
||||||
// lat, lon needs to be reversed for GeoJSON
|
// lat, lon needs to be reversed for GeoJSON
|
||||||
foreach ($route_coords as $rc) {
|
foreach ($all_route_points as $point) {
|
||||||
$coords[] = [$rc[1], $rc[0]];
|
$planned_rte_coords[] = [$point->lon, $point->lat];
|
||||||
|
$route_points[] = new Feature(new Point([$point->lon, $point->lat]), [
|
||||||
|
'name' => $point->name,
|
||||||
|
'popup' => $point->name . ' (' . $point->name . ')',
|
||||||
|
'icon' => ''
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$coords[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
|
$planned_rte_coords[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
|
||||||
|
$route_points[] = new Feature(
|
||||||
|
new Point([$pirep->arr_airport->lon, $pirep->arr_airport->lat]), [
|
||||||
|
'name' => $pirep->arr_airport->icao,
|
||||||
|
'popup' => $pirep->arr_airport->full_name,
|
||||||
|
'icon' => 'airport',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$line = new LineString($coords);
|
$route_points = new FeatureCollection($route_points);
|
||||||
|
|
||||||
$features = new FeatureCollection([
|
$planned_route_line = new LineString($planned_rte_coords);
|
||||||
new Feature($line, [], 1)
|
|
||||||
|
$planned_route = new FeatureCollection([
|
||||||
|
new Feature($planned_route_line, [], 1)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'features' => $features,
|
'actual_route' => false,
|
||||||
|
'route_points' => $route_points,
|
||||||
|
'planned_route_line' => $planned_route,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,21 @@ const phpvms= (function() {
|
|||||||
return map;
|
return map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show some popup text when a feature is clicked on
|
||||||
|
* @param feature
|
||||||
|
* @param layer
|
||||||
|
*/
|
||||||
|
const onFeaturePointClick = (feature, layer) => {
|
||||||
|
let popup_html = "";
|
||||||
|
if (feature.properties && feature.properties.popup) {
|
||||||
|
popup_html += feature.properties.popup;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer.bindPopup(popup_html);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +84,9 @@ const phpvms= (function() {
|
|||||||
render_route_map: (opts) => {
|
render_route_map: (opts) => {
|
||||||
|
|
||||||
opts = _.defaults(opts, {
|
opts = _.defaults(opts, {
|
||||||
features: null, // [ {name, lat, lon}, {name, lat, lon} ];
|
route_points: null,
|
||||||
|
planned_route_line: null, // [ {name, lat, lon}, {name, lat, lon} ];
|
||||||
|
actual_route_line: null,
|
||||||
center: [],
|
center: [],
|
||||||
render_elem: 'map',
|
render_elem: 'map',
|
||||||
overlay_elem: '',
|
overlay_elem: '',
|
||||||
@ -79,8 +96,6 @@ const phpvms= (function() {
|
|||||||
set_marker: false,
|
set_marker: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(opts.features);
|
|
||||||
|
|
||||||
let map = draw_base_map(opts);
|
let map = draw_base_map(opts);
|
||||||
|
|
||||||
if(opts.geodesic) {
|
if(opts.geodesic) {
|
||||||
@ -92,10 +107,10 @@ const phpvms= (function() {
|
|||||||
wrap: false,
|
wrap: false,
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
geodesicLayer.geoJson(opts.features)
|
geodesicLayer.geoJson(opts.planned_route_line);
|
||||||
map.fitBounds(geodesicLayer.getBounds());
|
map.fitBounds(geodesicLayer.getBounds());
|
||||||
} else {
|
} else {
|
||||||
let route = L.geoJSON(opts.features, {
|
let route = L.geoJSON(opts.planned_route_line, {
|
||||||
"color": "#ff7800",
|
"color": "#ff7800",
|
||||||
"weight": 5,
|
"weight": 5,
|
||||||
"opacity": 0.65
|
"opacity": 0.65
|
||||||
@ -104,6 +119,31 @@ const phpvms= (function() {
|
|||||||
route.addTo(map);
|
route.addTo(map);
|
||||||
map.fitBounds(route.getBounds());
|
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,
|
||||||
|
style: {
|
||||||
|
"color": "#1bff00",
|
||||||
|
"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);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
@section('scripts')
|
@section('scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
phpvms.render_route_map({
|
phpvms.render_route_map({
|
||||||
features: {!! json_encode($coords['features']); !!},
|
route_points: {!! json_encode($map_features['route_points']) !!},
|
||||||
|
planned_route_line: {!! json_encode($map_features['planned_route_line']); !!},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
@section('scripts')
|
@section('scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
phpvms.render_route_map({
|
phpvms.render_route_map({
|
||||||
features: {!! json_encode($coords['features']); !!},
|
route_points: {!! json_encode($map_features['route_points']) !!},
|
||||||
|
planned_route_line: {!! json_encode($map_features['planned_route_line']); !!},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
Loading…
Reference in New Issue
Block a user