Skip to content

Commit

Permalink
Improve traffic radar sample
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenAR committed Aug 27, 2024
1 parent 881a37b commit a9466bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
5 changes: 2 additions & 3 deletions samples/typescript/trafficRadar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ <h1>Clouds</h1>
{
myLat = receivedData.data.lat;
myLng = receivedData.data.lng;
console.log('My pos');
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
break;
case 'traffic':
{
const latDiff = myLat - receivedData.data.lat;
const lngDiff = myLng - receivedData.data.lng;
const radarX = lngDiff * (512 / 180) * zoom + 256;
const radarX = -lngDiff * (512 / 180) * zoom + 256;
const radarY = latDiff * (512 / 180) * zoom + 256;
ctx.fillRect(radarX, radarY, 5, 5);
ctx.fillText(
receivedData.data.model,
receivedData.data.title,
radarX,
radarY
);
Expand Down
29 changes: 5 additions & 24 deletions samples/typescript/trafficRadar/trafficRadar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ open('My app', Protocol.FSX_SP2)

handle.on('simObjectDataByType', recvSimObjectData => {
if (recvSimObjectData.requestID === RequestID.NEARBY_AIRCRAFT) {
if (recvSimObjectData.outOf === 0) return; // There are no sim objects nearby

const aircraftDetails = readAircraftPosition(recvSimObjectData.data);
client?.send(
JSON.stringify({
Expand Down Expand Up @@ -92,27 +94,9 @@ function registerAircraftDetailsDefinition(handle: ConnectionHandle) {
);
handle.addToDataDefinition(
DefinitionID.AIRCRAFT_DETAILS,
'ATC MODEL',
null,
SimConnectDataType.STRING32
);
handle.addToDataDefinition(
DefinitionID.AIRCRAFT_DETAILS,
'ATC ID',
null,
SimConnectDataType.STRING32
);
handle.addToDataDefinition(
DefinitionID.AIRCRAFT_DETAILS,
'ATC AIRLINE',
null,
SimConnectDataType.STRING64
);
handle.addToDataDefinition(
DefinitionID.AIRCRAFT_DETAILS,
'ATC FLIGHT NUMBER',
'TITLE',
null,
SimConnectDataType.STRING8
SimConnectDataType.STRING128
);
}

Expand All @@ -122,9 +106,6 @@ function readAircraftPosition(rawBuffer: RawBuffer) {
lat: rawBuffer.readFloat64(),
lng: rawBuffer.readFloat64(),
altitude: rawBuffer.readInt32(),
model: rawBuffer.readString(32),
id: rawBuffer.readString(32),
airline: rawBuffer.readString(64),
flightNumber: rawBuffer.readString(8),
title: rawBuffer.readString(128),
};
}

0 comments on commit a9466bd

Please sign in to comment.