Skip to content

Repository files navigation

react-msfs

Hooks

To be written. Most hooks are already documented in their JSDoc.

Game hooks

It is possible to hook into avionics lifecycle / interaction events.

useUpdate

Triggers a callback when an update is performed in the main loop of the instrument;

useInteractionEvent

Triggers a callback when an interaction event (H-event) is received by the instrument.

SimVar hooks

Hooks are provided to interface with MSFS SimVars and GameVars.

The following features are supported to make interaction easier:

  • use of split SimVar + K-event structure for changing value;
  • use of SimVar and H-event to only refresh when a certain interaction event is fired.

Misc. hooks

useImageLoader

The issue with HTMLImageElements is that loading the actual image is an asynchronous task and would make drawing Icons on a canvas layer very difficult. The useImageLoader allows you to preload these elements and pass them as parameters to the Icon component. Once the image is successfully loaded, the state is updated and the image can be drawn on the canvas.

constairplaneIcon=useImageLoader('/Pages/VCockpit/Instruments/a22x/assets/MAP/ND_AIRPLANE.svg');constairportIcon=useImageLoader('/Pages/VCockpit/Instruments/a22x/assets/MAP/ND_AIRPORT.svg');

Components

CanvasMap

The following is the most basic usage of the CanvasMap component. This will create a Bing map layer that is tied to the aircraft's position and heading. The map will be larger than it's parent container so that the entire container is filled in even when the map rotates.

const[latitude]=useSimVar('A:PLANE LATITUDE','Degrees');const[longitude]=useSimVar('A:PLANE LONGITUDE','Degrees');const[headingTrue]=useSimVar('A:PLANE HEADING DEGREES TRUE','Degrees');return(<CanvasMapbingConfigFolder="/Pages/VCockpit/Instruments/.../assets/MAP/"mapId="MAP"centerLla={{lat: latitude,long: longitude}}range={10}rotation={-headingTrue}/>)
NameTypeDefaultDescription
bingConfigFolderstringPath to mapConfig.json file
mapIdstringUnique identifier
centerLlaLatLongAltLatitude and longitude of map's center
showMapbooleantrueShow Bing map layer
rangenumber80Distance in nautical miles from map's center to top of parent container
rotationnumber0Map rotation in degrees

Icon

The Icon component allows you to place images and text onto the map. An icon can either have text, icon, or both! The icon is locked to a coordinate position so as the map moves around, so does the icon. The component(s) must be included as a child of your CanvasMap component.

const[headingTrue]=useSimVar('A:PLANE HEADING DEGREES TRUE','Degrees');constairportIcon=useImageLoader('/Pages/VCockpit/Instruments/.../assets/MAP/ND_AIRPORT.svg');constairports=// some array of nearby airportsreturn(<CanvasMap...>
airports.map(airport =>(<Iconposition={{lat: airport.latitude,long: airport.longitude}}icon={airportIcon}iconWidth={21}iconHeight={21}rotation={headingTrue}text={airport.ident}textFill="#00AFF0"fontFamily="LetterGothic-Bold"fontSize={25}/>
))
</CanvasMap>)
NameTypeDefaultDescription
positionLatLongAltLatitude and longitude of icon
rotationnumber0Icon rotation in degrees
iconHTMLImageElementOptionalPreloaded (useImageLoader) image for icon
iconWidthnumberOptionalIcon with in px
iconHeightnumberOptionalIcon height in px
textstringOptionalText to display next to icon
textFillstringOptionalText fill color
textPositionstringOptionalText position (top, bottom, left, right)
fontFamilystringOptionalText font family
fontSizenumberOptionalText font size

Geometry

The Geometry component allows you to draw lines and arcs on the map using the GeoPath and GeoArc classes, respectively. The paths are locked to coordinate positions so as the map moves around, so do the paths. The component(s) must be included as a child of your CanvasMap component.

constwaypoints=flightPlanManager.getWaypoints();constroutePaths: GeoPath[]=[];for(leti=0;i<waypoints.length-1;i++){routePaths.push(GeoPath.pathFromLatLongAlt(waypoints[i].infos.coordinates,waypoints[i+1].infos.coordinates,));}return(<CanvasMap...><GeometrygeoPaths={routePaths}strokeWidth={3}strokeColor="magenta"outlineWidth={6}outlineColor="black"/></CanvasMap>)
NameTypeDefaultDescription
geoPathsGeoPath[]Array of GeoPath objects to draw
strokeWidthnumber1
strokeColorstringwhite
outlineWidthnumber1Drawn below the stroke
outlineColorstringwhiteDrawn below the stroke

Classes

GeoPath

The GeoPath object stores two geodesyLatLon objects to represent a geographical line.

classGeoPath{start: LatLon;// line start pointend: LatLon;// line end point}

There are two ways to create these objects:

constpath1=GeoPath.pathFromLatLongAlt(start: LatLongAlt,end: LatLongAlt,);constpath2=GeoPath.pathFromCoordinates(startLat: number,startLong: number,endLat: number,endLong: number,);

GeoArc

The GeoArc object stores three geodesyLatLon objects and a radius to represent a geographical arc.

classGeoArcextendsGeoPath{// start and end inherited from GeoPathcontrol: LatLon;// arc control pointradius: number;// arc radius}

There are two ways to create these objects:

constarc1=GeoArc.arcFromLatLongAlt(start: LatLongAlt,control: LatLongAlt,end: LatLongAlt,radius: number,);constarc2=GeoArc.arcFromCoordinates(startLat: number,startLong: number,controlLat: number,controlLong: number,endLat: number,endLong: number,radius: number,);

About

React utilities and hooks for Microsoft Flight Simulator UIs and displays

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages