-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mapping): VRPs and Mapping Elements (#874)
* Create VRP Tables * Start VRP Data Patch * VRP Data * VRP Dependency * Interface for mapping elements * Mapping things * Add mapping dependency * Mapping dependency tweak * Style
- Loading branch information
Showing
18 changed files
with
2,588 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Helpers\Airfield; | ||
|
||
use App\Models\Mapping\MappingElement; | ||
use Illuminate\Support\Collection; | ||
|
||
interface MappingElementProvider | ||
{ | ||
/** | ||
* Returns an array of mapping elements. | ||
* | ||
* @return MappingElement[] | Collection | ||
*/ | ||
public function mappingElements(): Collection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Models\Airfield; | ||
|
||
use App\Models\Mapping\MappingElement; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
use Location\Coordinate; | ||
|
||
class VisualReferencePoint extends Model implements MappingElement | ||
{ | ||
protected $fillable = [ | ||
'name', | ||
'short_name', | ||
'latitude', | ||
'longitude', | ||
]; | ||
|
||
public function airfields(): BelongsToMany | ||
{ | ||
return $this->belongsToMany(Airfield::class); | ||
} | ||
|
||
public function elementId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function elementType(): string | ||
{ | ||
return 'visual_reference_point'; | ||
} | ||
|
||
public function elementName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function elementCoordinate(): Coordinate | ||
{ | ||
return new Coordinate($this->latitude, $this->longitude); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Models\Mapping; | ||
|
||
use Location\Coordinate; | ||
|
||
interface MappingElement | ||
{ | ||
/** | ||
* The id that uniquely identifies the element within its | ||
* type. | ||
*/ | ||
public function elementId(): int; | ||
|
||
/** | ||
* The type of the element. e.g. visual_reference_point | ||
*/ | ||
public function elementType(): string; | ||
|
||
/** | ||
* The name of the element, for labels etc | ||
*/ | ||
public function elementName(): string; | ||
|
||
/** | ||
* The coordinate of the element. | ||
*/ | ||
public function elementCoordinate(): Coordinate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use App\Services\MappingService; | ||
use App\Services\VrpService; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class MappingProvider extends ServiceProvider | ||
{ | ||
public function boot() | ||
{ | ||
$this->app->singleton(MappingService::class, function (Application $application) { | ||
return new MappingService( | ||
[ | ||
$application->make(VrpService::class) | ||
] | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Helpers\Airfield\MappingElementProvider; | ||
use App\Models\Mapping\MappingElement; | ||
|
||
class MappingService | ||
{ | ||
/** | ||
* @var MappingElementProvider[] | ||
*/ | ||
private array $elementProviders; | ||
|
||
public function __construct(array $elementProviders) | ||
{ | ||
$this->elementProviders = $elementProviders; | ||
} | ||
|
||
public function providers(): array | ||
{ | ||
return $this->elementProviders; | ||
} | ||
|
||
public function getMappingElementsDependency(): array | ||
{ | ||
return collect( | ||
array_map( | ||
fn (MappingElementProvider $provider) => $provider->mappingElements()->map( | ||
fn (MappingElement $element) => [ | ||
'id' => $element->elementId(), | ||
'name' => $element->elementName(), | ||
'type' => $element->elementType(), | ||
'latitude' => $element->elementCoordinate()->getLat(), | ||
'longitude' => $element->elementCoordinate()->getLng(), | ||
] | ||
), | ||
$this->elementProviders, | ||
) | ||
)->flatten(1)->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Helpers\Airfield\MappingElementProvider; | ||
use App\Models\Airfield\VisualReferencePoint; | ||
use Illuminate\Support\Collection; | ||
|
||
class VrpService implements MappingElementProvider | ||
{ | ||
public function getVrpDependency(): array | ||
{ | ||
return VisualReferencePoint::all('id', 'name', 'short_name', 'latitude', 'longitude')->map( | ||
fn (VisualReferencePoint $visualReferencePoint) => array_merge( | ||
$visualReferencePoint->toArray(), | ||
['airfields' => $visualReferencePoint->airfields->pluck('id')->toArray()] | ||
) | ||
)->toArray(); | ||
} | ||
|
||
public function mappingElements(): Collection | ||
{ | ||
return VisualReferencePoint::all(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
database/migrations/2022_03_06_212416_create_visual_reference_points_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateVisualReferencePointsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('visual_reference_points', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name')->comment('The name of the VRP'); | ||
$table->string('short_name')->comment('The short name of the VRP'); | ||
$table->double('latitude', 10, 8) | ||
->comment('The latitude of the VRP in decimal degrees'); | ||
$table->double('longitude', 11, 8) | ||
->comment('The longitude of the VRP in decimal degrees'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('visual_reference_points'); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
database/migrations/2022_03_06_212608_create_airfield_visual_reference_point_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use App\Models\Airfield\Airfield; | ||
use App\Models\Airfield\VisualReferencePoint; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateAirfieldVisualReferencePointTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('airfield_visual_reference_point', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedInteger('airfield_id'); | ||
$table->foreignIdFor(VisualReferencePoint::class); | ||
|
||
$table->foreign('airfield_id')->references('id')->on('airfield'); | ||
$table->foreign('visual_reference_point_id', 'airfield_visual_reference_vrp')->references('id')->on('visual_reference_points'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('airfield_visual_reference_point'); | ||
} | ||
} |
Oops, something went wrong.