Add flight route map; algorithm for picking from multiple nav points; some tests

This commit is contained in:
Nabeel Shahzad 2017-12-20 19:12:39 -06:00
parent 8d1281d6e3
commit 6c546b5094
18 changed files with 418 additions and 221 deletions

View File

@ -25,6 +25,7 @@ class CreateNavdataTables extends Migration
$table->float('lon', 7, 4)->default(0.0);
$table->string('freq', 7)->nullable();
$table->primary(['id', 'name']);
$table->index('id');
$table->index('name');
});

View File

@ -13,13 +13,9 @@ class CreateAcarsTables extends Migration
*/
public function up()
{
/**
* See for defs, modify/update based on this
* https://github.com/skiselkov/openfmc/blob/master/airac.h
*/
Schema::create('acars', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('acars_id', 12);
$table->string('pirep_id', 12);
$table->string('name', 10)->nullable();
$table->float('lat', 7, 4)->default(0.0);
$table->float('lon', 7, 4)->default(0.0);
@ -29,8 +25,8 @@ class CreateAcarsTables extends Migration
# polymorphic relation columns.
# parent_type can be flight, pirep or acars
# once
$table->unsignedBigInteger('parent_id');
$table->string('parent_type');
#$table->unsignedBigInteger('parent_id');
#$table->string('parent_type');
$table->timestamps();

View File

@ -193,7 +193,7 @@ flights:
flight_number: 100
dpt_airport_id: KAUS
arr_airport_id: KJFK
route: KAUS KJFK
route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK
dpt_time: 6PM CST
arr_time: 11PM EST
- id: flightid_2

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Frontend;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Services\GeoService;
use Log;
use Illuminate\Http\Request;
@ -19,16 +20,21 @@ use Prettus\Repository\Exceptions\RepositoryException;
class FlightController extends AppBaseController
{
private $airlineRepo, $airportRepo, $flightRepo;
private $airlineRepo,
$airportRepo,
$flightRepo,
$geoSvc;
public function __construct(
AirlineRepository $airlineRepo,
AirportRepository $airportRepo,
FlightRepository $flightRepo
FlightRepository $flightRepo,
GeoService $geoSvc
) {
$this->airlineRepo = $airlineRepo;
$this->airportRepo = $airportRepo;
$this->flightRepo = $flightRepo;
$this->geoSvc = $geoSvc;
}
public function index(Request $request)
@ -110,13 +116,22 @@ class FlightController extends AppBaseController
}
}
public function update()
{
}
/**
* Show the flight information page
*/
public function show($id)
{
$flight = $this->flightRepo->find($id);
if (empty($flight)) {
Flash::error('Flight not found!');
return redirect(route('frontend.dashboard.index'));
}
$coords = $this->geoSvc->flightGeoJson($flight);
return $this->view('flights.show', [
'flight' => $flight,
'coords' => $coords,
]);
}
}

View File

@ -120,7 +120,7 @@ class PirepController extends Controller
return redirect(route('frontend.pirep.index'));
}
$coords = $this->geoSvc->getRouteCoordsGeoJSON($pirep);
$coords = $this->geoSvc->pirepGeoJson($pirep);
return $this->view('pireps.show', [
'pirep' => $pirep,

View File

@ -28,7 +28,8 @@ class Airport extends Model
];
protected $casts = [
'lat' => 'float',
'lon' => 'float',
];
/**

View File

@ -61,11 +61,15 @@ class Flight extends Model
/**
* Get the flight ident, e.,g JBU1900
* @param $value
*/
public function getIdentAttribute()
{
$flight_id = $this->airline->code;
$flight_id .= $this->flight_number;
# TODO: Add in code/leg if set
return $flight_id;
}
/**

View File

@ -20,7 +20,9 @@ class Navdata extends Model
];
public $casts = [
'id' => 'string',
'type' => 'integer',
'id' => 'string',
'type' => 'integer',
'lat' => 'float',
'lon' => 'float',
];
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Repositories;
use App\Models\Navdata;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
class NavdataRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
// Super short lived cache for when the navdata stuff is re-imported
protected $cacheMinutes = 5;
public function model()
{
return Navdata::class;
}
}

View File

@ -2,45 +2,200 @@
namespace App\Services;
use Log;
//use \League\Geotools\Geotools;
use App\Models\Flight;
use App\Repositories\NavdataRepository;
use \GeoJson\Geometry\LineString;
use \GeoJson\Feature\Feature;
use \GeoJson\Feature\FeatureCollection;
use League\Flysystem\Exception;
use \League\Geotools\Geotools;
use \League\Geotools\Coordinate\Coordinate;
/**
* 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
*
*/
class GeoService extends BaseService
{
private $navRepo;
public function __construct(NavdataRepository $navRepo)
{
$this->navRepo = $navRepo;
}
public function getClosestCoords($coordStart, $all_coords, $measure='flat')
{
$distance = [];
$geotools = new Geotools();
$start = new Coordinate($coordStart);
foreach($all_coords as $coords) {
$coord = new Coordinate($coords);
$dist = $geotools->distance()->setFrom($start)->setTo($coord);
if($measure === 'flat') {
$distance[] = $dist->flat();
} elseif ($measure === 'greatcircle') {
$distance[] = $dist->greatCircle();
}
}
$distance = collect($distance);
$min = $distance->min();
return $all_coords[ $distance->search($min, true) ];
}
/**
* 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
* @param $dep_icao string ICAO to ignore
* @param $arr_icao string ICAO to ignore
* @param $start_coords array [x, y]
* @param $route string Textual route
* @return array
*/
public function getRouteCoordsGeoJSON($model): array
public function getCoordsFromRoute($dep_icao, $arr_icao, $start_coords, $route)
{
# 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],
$coords = [];
$split_route = explode(' ', $route);
$skip = [
$dep_icao,
$arr_icao,
'SID',
'STAR'
];
foreach ($split_route as $route_point) {
$route_point = trim($route_point);
if (\in_array($route_point, $skip, true)) {
continue;
}
try {
Log::info('Looking for ' . $route_point);
$points = $this->navRepo->findWhere(['id' => $route_point]);
$size = \count($points);
if($size === 0) {
continue;
} else if($size === 1) {
$point = $points[0];
Log::info('name: ' . $point->id . ' - ' . $point->lat . 'x' . $point->lon);
$coords[] = [
$point->lat,
$point->lon,
];
continue;
}
# Find the point with the shortest distance
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
# If the first point happens to have multiple possibilities, use
# the starting point that was passed in
if(\count($coords) > 0) {
$start_point = $coords[\count($coords) - 1];
$start_point = [$start_point[0], $start_point[1]];
} else {
$start_point = $start_coords;
}
$coords[] = $this->getClosestCoords($start_point, $potential_coords);
} catch (\Exception $e) {
Log::error($e);
continue;
}
}
return $coords;
}
/**
* Return a FeatureCollection GeoJSON object
* @param Flight $flight
* @return array
*/
public function flightGeoJson(Flight $flight): array
{
$coords = [];
$coords[] = [$flight->dpt_airport->lon, $flight->dpt_airport->lat];
// TODO: Add markers for the start/end airports
// TODO: Read from the ACARS data table
if($flight->route) {
$route_coords =$this->getCoordsFromRoute(
$flight->dpt_airport->icao,
$flight->arr_airport->icao,
[$flight->dpt_airport->lat, $flight->dpt_airport->lon],
$flight->route);
// lat, lon needs to be reversed for GeoJSON
foreach($route_coords as $rc) {
$coords[] = [$rc[1], $rc[0]];
}
}
$coords[] = [$flight->arr_airport->lon, $flight->arr_airport->lat];
$line = new LineString($coords);
$features = new FeatureCollection([
new Feature($line, [], 1)
]);
return [
'features' => $features,
];
}
/**
* Return a GeoJSON FeatureCollection for a PIREP
* @param Pirep $pirep
* @return array
*/
public function pirepGeoJson(Pirep $pirep)
{
$coords = [];
$coords[] = [$pirep->dpt_airport->lon, $pirep->dpt_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]);
$coords[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat];
$line = new LineString($coords);
$features = new FeatureCollection([
new Feature($line, [], 1)
]);
return [
'features' => $features,
//'center' => $center,
];
}

View File

@ -46,7 +46,8 @@
"tivie/php-os-detector": "1.1.0",
"santigarcor/laratrust": "5.0.3",
"pragmarx/version": "0.2.2",
"nabeel/vacentral": "dev-master"
"nabeel/vacentral": "dev-master",
"jmikola/geojson": "1.0.2"
},
"require-dev": {
"phpunit/phpunit": "6.4.0",

126
composer.lock generated
View File

@ -427,7 +427,7 @@
"Doctrine\\DBAL\\": "lib/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -750,7 +750,7 @@
"Egulias\\EmailValidator\\": "EmailValidator"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -796,7 +796,7 @@
"Parsedown": ""
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -856,7 +856,7 @@
"GuzzleHttp\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -914,7 +914,7 @@
"src/functions_include.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -969,7 +969,7 @@
"src/functions_include.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1031,7 +1031,7 @@
"Hashids\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1138,7 +1138,7 @@
"InfyOm\\AdminLTETemplates\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1157,7 +1157,7 @@
"laravel",
"templates"
],
"time": "2017-11-25 04:43:54"
"time": "2017-11-25T04:43:54+00:00"
},
{
"name": "infyomlabs/laravel-generator",
@ -1199,7 +1199,7 @@
"src/helpers.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1223,7 +1223,7 @@
"test",
"view"
],
"time": "2017-11-25 05:18:22"
"time": "2017-11-25T05:18:22+00:00"
},
{
"name": "jackiedo/timezonelist",
@ -1249,7 +1249,7 @@
"Jackiedo\\Timezonelist\\": "src/Jackiedo/Timezonelist"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1360,7 +1360,7 @@
"stubs/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1406,7 +1406,7 @@
"Traitor\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1594,7 +1594,7 @@
"Illuminate\\": "src/Illuminate/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2017,7 +2017,7 @@
}
],
"description": "Bloom filter implementation",
"time": "2017-11-30 17:51:14"
"time": "2017-11-30T17:51:14+00:00"
},
{
"name": "monolog/monolog",
@ -2123,7 +2123,7 @@
"Cron\\": "src/Cron/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2172,7 +2172,7 @@
"src/DeepCopy/deep_copy.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2217,11 +2217,11 @@
"VaCentral\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"time": "2017-12-08 04:00:06"
"time": "2017-12-08T04:00:06+00:00"
},
{
"name": "nesbot/carbon",
@ -2311,7 +2311,7 @@
"PhpParser\\": "lib/PhpParser"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -2744,7 +2744,7 @@
]
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -2897,7 +2897,7 @@
"Prophecy\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3015,7 +3015,7 @@
"src/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -3156,7 +3156,7 @@
"src/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -3237,7 +3237,7 @@
"src/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -3358,7 +3358,7 @@
"PragmaRX\\Version\\Tests\\": "tests/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3379,16 +3379,16 @@
},
{
"name": "pragmarx/yaml",
"version": "v0.1.4",
"version": "v0.1.5",
"source": {
"type": "git",
"url": "https://github.com/antonioribeiro/yaml.git",
"reference": "b510623eb5008cc468e00a31259a3c860dd2b267"
"reference": "cc27a84e8d9760d82014596ef155c34c816c4ea5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/antonioribeiro/yaml/zipball/b510623eb5008cc468e00a31259a3c860dd2b267",
"reference": "b510623eb5008cc468e00a31259a3c860dd2b267",
"url": "https://api.github.com/repos/antonioribeiro/yaml/zipball/cc27a84e8d9760d82014596ef155c34c816c4ea5",
"reference": "cc27a84e8d9760d82014596ef155c34c816c4ea5",
"shasum": ""
},
"require": {
@ -3418,7 +3418,7 @@
"PragmaRX\\Yaml\\Tests\\": "tests/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3435,7 +3435,7 @@
"laravel",
"yaml"
],
"time": "2017-12-05T20:32:21+00:00"
"time": "2017-12-19T02:25:46+00:00"
},
{
"name": "prettus/l5-repository",
@ -3481,7 +3481,7 @@
"Prettus\\Repository\\": "src/Prettus/Repository/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -3950,7 +3950,7 @@
"Laratrust\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -4153,7 +4153,7 @@
"src/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
@ -4728,7 +4728,7 @@
"src/helpers.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -4911,7 +4911,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -4960,7 +4960,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5020,7 +5020,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5076,7 +5076,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5139,7 +5139,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5188,7 +5188,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5242,7 +5242,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5330,7 +5330,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5379,7 +5379,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5531,7 +5531,7 @@
"bootstrap.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5588,7 +5588,7 @@
"bootstrap.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5647,7 +5647,7 @@
"Resources/stubs"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5699,7 +5699,7 @@
"Symfony\\Polyfill\\Util\\": ""
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5754,7 +5754,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5811,7 +5811,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5894,7 +5894,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -5978,7 +5978,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6046,7 +6046,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6111,7 +6111,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6173,7 +6173,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6304,7 +6304,7 @@
"Tivie\\OS\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"APACHE 2.0"
],
@ -6525,7 +6525,7 @@
"Webpatser\\Uuid": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6654,7 +6654,7 @@
"src/helper.php"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -6711,7 +6711,7 @@
"Zend\\Diactoros\\": "src/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
@ -6937,7 +6937,7 @@
"Whoops\\": "src/Whoops/"
}
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -7279,7 +7279,7 @@
"/Tests/"
]
},
"notification-url": "http://packagist.org/downloads/",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],

View File

@ -74,6 +74,7 @@ const phpvms= (function() {
render_elem: 'map',
overlay_elem: '',
zoom: 5,
geodesic: true,
layers: [],
set_marker: false,
});
@ -82,26 +83,27 @@ const phpvms= (function() {
let map = draw_base_map(opts);
var geodesicLayer = L.geodesic([], {
weight: 7,
opacity: 0.5,
color: '#ff33ee',
steps: 50,
wrap: false,
}).addTo(map);
if(opts.geodesic) {
let geodesicLayer = L.geodesic([], {
weight: 7,
opacity: 0.5,
color: '#ff33ee',
steps: 50,
wrap: false,
}).addTo(map);
geodesicLayer.geoJson(opts.features)
map.fitBounds(geodesicLayer.getBounds());
geodesicLayer.geoJson(opts.features)
map.fitBounds(geodesicLayer.getBounds());
} else {
let route = L.geoJSON(opts.features, {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
});
/*let route = L.geoJSON(opts.features, {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
});*/
//map.setView(opts.center, opts.zoom);
//map.fitBounds(route.getBounds());
//route.addTo(map)
route.addTo(map);
map.fitBounds(route.getBounds());
}
},
/**

View File

@ -0,0 +1,18 @@
<div class="row">
<div class="col-md-12">
<h3 class="description">map</h3>
</div>
<div class="col-12">
<div class="box-body">
<div id="map" style="width: 100%; height: 800px"></div>
</div>
</div>
</div>
@section('scripts')
<script type="text/javascript">
phpvms.render_route_map({
features: {!! json_encode($coords['features']); !!},
});
</script>
@endsection

View File

@ -1,23 +1,53 @@
@extends('layouts.default.app')
@section('title', 'Flight '.$flight->ident)
@section('content')
<div class="row">
@include('layouts.default.flights.show_fields')
<div class="col-md-12">
<h3 class="description">{!! $flight->ident !!} - {!! $flight->dpt_airport->full_name !!} to {!! $flight->arr_airport->full_name !!}</h3>
</div>
</div>
@endsection
@section('scripts')
<script>
$(document).ready(function () {
$(".select2_dropdown").select2();
$(document).on('submit', 'form.pjax_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
<div class="row">
<div class="col-md-12">
<table class="table">
<tr>
<td>Departure</td>
<td>{!! $flight->dpt_airport->icao !!} @ {!! $flight->dpt_time !!}</td>
</tr>
$(document).on('pjax:complete', function() {
$(".select2_dropdown").select2();
});
});
</script>
<tr>
<td>Arrival</td>
<td>{!! $flight->arr_airport->icao !!} @ {!! $flight->arr_time !!}</td>
</tr>
<tr>
<td>Route Code/Leg:</td>
<td>{!! $flight->route_code ?: '-' !!}/{!! $flight->route_leg ?: '-' !!}</td>
</tr>
<tr>
<td>Alternate Airport</td>
<td>
@if($flight->alt_airport_id)
{!! $flight->alt_airport->full_name !!}
@else
-
@endif
</td>
</tr>
<tr>
<td>Route</td>
<td>{!! $flight->route !!}</td>
</tr>
<tr>
<td>Notes</td>
<td>{!! $flight->notes !!}</td>
</tr>
</table>
</div>
</div>
@include('layouts.default.flights.map')
@endsection

View File

@ -1,81 +0,0 @@
<div class="form-group col-sm-6">
<div class="box box-solid">
<div class="box-header with-border">
{{--<i class="fa fa-text-width"></i>--}}
<h3 class="box-title">{!! Form::label('dpt_airport_id', 'Dep ICAO') !!}</h3>
</div>
<div class="box-body"><p class="lead">
{!! $flight->dpt_airport->icao !!} - {!! $flight->dpt_airport->name !!}
</p></div>
</div>
</div>
<div class="form-group col-sm-6">
<div class="box box-solid">
<div class="box-header with-border">
{{--<i class="fa fa-text-width"></i>--}}
<h3 class="box-title">{!! Form::label('arr_airport_id', 'Arrival ICAO') !!}</h3>
</div>
<div class="box-body"><p class="lead">
{!! $flight->arr_airport->icao !!} - {!! $flight->arr_airport->name !!}
</p>
</div>
</div>
</div>
<div class="form-group col-sm-12">
<div class="box box-primary">
<div class="box-body">
<!-- Route Code Field -->
<div class="form-group">
{!! Form::label('route_code', 'Route Code:') !!}
{!! $flight->route_code !!}
</div>
<!-- Route Leg Field -->
<div class="form-group">
{!! Form::label('route_leg', 'Route Leg:') !!}
{!! $flight->route_leg !!}
</div>
<!-- Alt Airport Id Field -->
@if($flight->alt_airport_id)
<div class="form-group">
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
<p>{!! $flight->alt_airport->icao !!}</p>
</div>
@endif
<!-- Route Field -->
<div class="form-group">
{!! Form::label('route', 'Route:') !!}
<p>{!! $flight->route !!}</p>
</div>
<!-- Dpt Time Field -->
<div class="form-group">
{!! Form::label('dpt_time', 'Departure Time:') !!}
{!! $flight->dpt_time !!}
</div>
<!-- Arr Time Field -->
<div class="form-group">
{!! Form::label('arr_time', 'Arrival Time:') !!}
{!! $flight->arr_time !!}
</div>
<!-- Notes Field -->
<div class="form-group">
{!! Form::label('notes', 'Notes:') !!}
<p>{!! $flight->notes !!}</p>
</div>
<!-- Active Field -->
<div class="form-group">
{!! Form::label('active', 'Active:') !!}
<p>{!! $flight->active !!}</p>
</div>
</div>
</div>
</div>

View File

@ -11,11 +11,8 @@
@section('scripts')
<script type="text/javascript">
let opts = {
features: {!! json_encode($coords['features']); !!},
};
phpvms.render_route_map(opts);
phpvms.render_route_map({
features: {!! json_encode($coords['features']); !!},
});
</script>
@endsection

36
tests/GeoTest.php Normal file
View File

@ -0,0 +1,36 @@
<?php
use App\Facades\Utils;
class GeoTest extends TestCase
{
public function setUp() {
}
public function testClosestPoint()
{
$geoSvc = app('\App\Services\GeoService');
/**
* [2017-12-21 00:54:10] dev.INFO: Looking for ATL
* [2017-12-21 00:54:10] dev.INFO: ATL - 36.58106 x 26.375603
* [2017-12-21 00:54:10] dev.INFO: Looking for SIE
* [2017-12-21 00:54:10] dev.INFO: found 3 for SIE
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 39.0955x-74.800344
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 41.15169x-3.604667
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 52.15527x22.200833
*/
# Start at ATL
$start_point = [36.58106, 26.375603];
# These are all SIE
$potential_points = [
[39.0955, -74.800344],
[41.15169, -3.604667],
[52.15527, 22.200833],
];
$coords = $geoSvc->getClosestCoords($start_point, $potential_points);
$this->assertEquals([52.15527, 22.200833], $coords);
}
}