From 645c0083efa2c79bb9e958a6d5a09c4b3f4e79e3 Mon Sep 17 00:00:00 2001 From: falcon71 Date: Wed, 23 Oct 2024 18:04:33 +0200 Subject: [PATCH] Fixes #38: The APT 3 page would throw an error for airports without runways --- kln90b/pages/right/Apt3MapPage.tsx | 6 +++--- kln90b/pages/right/Apt3UserPage.tsx | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/kln90b/pages/right/Apt3MapPage.tsx b/kln90b/pages/right/Apt3MapPage.tsx index e113a9f..ecaca18 100644 --- a/kln90b/pages/right/Apt3MapPage.tsx +++ b/kln90b/pages/right/Apt3MapPage.tsx @@ -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"; @@ -23,7 +23,7 @@ export class Apt3MapPage extends WaypointPage { super(props); const facility = unpackFacility(this.facility); - if (!facility || isUserWaypoint(facility)) { + if (!facility || isUserWaypoint(facility) || facility.runways.length == 0) { this.numPages = 0; } @@ -43,7 +43,7 @@ export class Apt3MapPage extends WaypointPage { 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 { diff --git a/kln90b/pages/right/Apt3UserPage.tsx b/kln90b/pages/right/Apt3UserPage.tsx index ba55aa3..ada5cbf 100644 --- a/kln90b/pages/right/Apt3UserPage.tsx +++ b/kln90b/pages/right/Apt3UserPage.tsx @@ -38,21 +38,18 @@ export class Apt3UserPage extends WaypointPage { private ref: NodeReference = FSComponent.createRef(); private isVisible: boolean = false; - constructor(props: PageProps) { super(props); - const facility = unpackFacility(this.facility); + const runway = this.getRunway(facility); this.children = new UIElementChildren({ - 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 { @@ -107,19 +104,22 @@ export class Apt3UserPage extends WaypointPage { 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;