Skip to content

Commit

Permalink
Fixes #38: The APT 3 page would throw an error for airports without r…
Browse files Browse the repository at this point in the history
…unways
  • Loading branch information
falcon71 committed Oct 23, 2024
1 parent 88f5620 commit 645c008
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions kln90b/pages/right/Apt3MapPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AirportFacility, FSComponent, GeoPoint, RunwayUtils, VNode} from '@microsoft/msfs-sdk';
import {AirportFacility, GeoPoint, RunwayUtils, VNode} from '@microsoft/msfs-sdk';
import {PageProps, UIElementChildren} from "../Page";
import {NO_CURSOR_CONTROLLER} from "../CursorController";
import {Canvas} from "../../controls/Canvas";
Expand All @@ -23,7 +23,7 @@ export class Apt3MapPage extends WaypointPage<AirportFacility> {
super(props);

const facility = unpackFacility(this.facility);
if (!facility || isUserWaypoint(facility)) {
if (!facility || isUserWaypoint(facility) || facility.runways.length == 0) {
this.numPages = 0;
}

Expand All @@ -43,7 +43,7 @@ export class Apt3MapPage extends WaypointPage<AirportFacility> {
public changeFacility(fac: string | AirportFacility) {
super.changeFacility(fac);
const facility = unpackFacility(this.facility);
this.numPages = facility && !isUserWaypoint(facility) ? 1 : 0;
this.numPages = facility && !isUserWaypoint(facility) && facility.runways.length > 0 ? 1 : 0;
}

public getScanlist(): Scanlist {
Expand Down
22 changes: 11 additions & 11 deletions kln90b/pages/right/Apt3UserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,18 @@ export class Apt3UserPage extends WaypointPage<AirportFacility> {
private ref: NodeReference<HTMLDivElement> = FSComponent.createRef<HTMLDivElement>();
private isVisible: boolean = false;


constructor(props: PageProps) {
super(props);


const facility = unpackFacility(this.facility);
const runway = this.getRunway(facility);

this.children = new UIElementChildren<Apt3UserPageTypes>({
length: new RunwayLengthEditor(this.props.bus, facility ? this.getRunwayLength(this.getRunway(facility)) : null, this.setRunwayLength.bind(this)),
surface: new RunwaySurfaceEditor(this.props.bus, facility ? this.getRunwaySurface(this.getRunway(facility)) : null, this.setRunwaySurface.bind(this)),
length: new RunwayLengthEditor(this.props.bus, this.getRunwayLength(runway), this.setRunwayLength.bind(this)),
surface: new RunwaySurfaceEditor(this.props.bus, this.getRunwaySurface(runway), this.setRunwaySurface.bind(this)),
});


this.setVisible(facility !== null && isUserWaypoint(facility));

}

public render(): VNode {
Expand Down Expand Up @@ -107,19 +104,22 @@ export class Apt3UserPage extends WaypointPage<AirportFacility> {
return this.props.nearestLists.aptNearestList;
}

private getRunway(facility: AirportFacility): AirportRunway {
private getRunway(facility: AirportFacility | null): AirportRunway | null {
if (facility == null || facility.runways.length === 0) { //For example HEGH has no runways
return null;
}
return facility.runways[0];
}

private getRunwayLength(rwy: AirportRunway): number | null {
if (rwy.length < 0) {
private getRunwayLength(rwy: AirportRunway | null): number | null {
if (rwy == null || rwy.length < 0) {
return null;
}
return UnitType.METER.convertTo(rwy.length, UnitType.FOOT);
}

private getRunwaySurface(rwy: AirportRunway): RunwaySurfaceType | null {
if (rwy.surface === RunwaySurfaceType.WrightFlyerTrack) {
private getRunwaySurface(rwy: AirportRunway | null): RunwaySurfaceType | null {
if (rwy == null || rwy.surface === RunwaySurfaceType.WrightFlyerTrack) {
return null;
}
return rwy.surface;
Expand Down

0 comments on commit 645c008

Please sign in to comment.