Skip to content

Commit

Permalink
Use HTTPS, initial ATC sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kahn committed Aug 6, 2021
1 parent 3024390 commit 3de5770
Show file tree
Hide file tree
Showing 5 changed files with 3,339 additions and 55 deletions.
10 changes: 7 additions & 3 deletions atc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { polygon, featureCollection } from '@turf/helpers';

export async function getATCSectors(){
try{
var sectors = await getLineFeatures('https://raw.githubusercontent.com/vatSys/australia-dataset/master/Maps/ALL_SECTORS.xml');
return featureCollection(sectors);
var allSectors = await getLineFeatures('https://raw.githubusercontent.com/vatSys/australia-dataset/master/Maps/ALL_SECTORS.xml');
// var allVolumes = await getLineFeatures('https://raw.githubusercontent.com/vatSys/australia-dataset/master/Volumes.xml');
// var sectors
return featureCollection(allSectors);
}catch(err){
console.log(err)
return false;
}
}
}

// https://data.vatsim.net/v3/transceivers-data.json
109 changes: 83 additions & 26 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ export async function getVatsimData (url) {
return data;
}

export async function getVatsimAFV (url) {
var data = cache.get("vatsimAFV");
if (data == undefined) {
const res = await fetch(url)
.then(checkHTTPStatus)
.then(res => res.json())
.then( data => {
return data;
})
.catch(err => console.log(err));
data = res;
console.log(`cache:set url:${url} keys:${Object.keys(data).length}`)
cache.set("vatsimAFV", data, 15);
}else{
console.log(`cache:get url:${url} keys:${Object.keys(data).length}`)
}
return data;
}

/**
* Gets a vatsys dataset URL and returns turf Features
* @param {string} url
Expand Down Expand Up @@ -88,32 +107,70 @@ function xmlToFeatures (data) {
// (?<latD>[+-][0-9]{2})(?<latM>[0-9]{2})(?<latS>[0-9]{2}\.[0-9]{3})(?<lonD>[+-][0-9]{3})(?<lonM>[0-9]{2})(?<lonS>[0-9]{2}\.[0-9]{3})
const re = new RegExp(/(?<latRef>[+-])(?<latD>[0-9]{2})(?<latM>[0-9]{2})(?<latS>[0-9]{2}\.[0-9]{3})(?<lonRef>[+-])(?<lonD>[0-9]{3})(?<lonM>[0-9]{2})(?<lonS>[0-9]{2}\.[0-9]{3})/g)

data.Maps.Map.Line.forEach(function(obj){
var lineStringArr = [];
var matches = [...obj._text.matchAll(re)];
matches.forEach(function(match){
// Convert vaySys DMS into decimal degrees
// https://github.com/vatSys/xml-tools/blob/master/DotAIPtoXML/DotAIPtoXML/Coordinate.cs#L119
var pos = {
latitude: [
parseInt(match.groups.latD),
parseInt(match.groups.latM),
parseFloat(match.groups.latS)
],
latRef: (match.groups.latRef == '+') ? "N" : "S",
longitude: [
parseInt(match.groups.lonD),
parseInt(match.groups.lonM),
parseFloat(match.groups.lonS)
],
lonRef: (match.groups.lonRef == '+') ? "E" : "W"
}
var [ latitude, longitude ] = dms2dec(pos.latitude,pos.latRef,pos.longitude,pos.lonRef);
// Turf is geoJSON so we continue the stupidity here with long THEN lat.
lineStringArr.push([longitude, latitude]);
});
polys.push(lineToPolygon(lineString(lineStringArr),{mutate: true, properties: {name: obj._attributes.Name}}));
})
// Handle Maps - FIR Boundaries
try{
data.Maps.Map.Line.forEach(function(obj){
var lineStringArr = [];
var matches = [...obj._text.matchAll(re)];
matches.forEach(function(match){
// Convert vaySys DMS into decimal degrees
// https://github.com/vatSys/xml-tools/blob/master/DotAIPtoXML/DotAIPtoXML/Coordinate.cs#L119
var pos = {
latitude: [
parseInt(match.groups.latD),
parseInt(match.groups.latM),
parseFloat(match.groups.latS)
],
latRef: (match.groups.latRef == '+') ? "N" : "S",
longitude: [
parseInt(match.groups.lonD),
parseInt(match.groups.lonM),
parseFloat(match.groups.lonS)
],
lonRef: (match.groups.lonRef == '+') ? "E" : "W"
}
var [ latitude, longitude ] = dms2dec(pos.latitude,pos.latRef,pos.longitude,pos.lonRef);
// Turf is geoJSON so we continue the stupidity here with long THEN lat.
lineStringArr.push([longitude, latitude]);
});
polys.push(lineToPolygon(lineString(lineStringArr),{mutate: true, properties: {name: obj._attributes.Name}}));
})
}catch(err){
console.log(err);
}

// Handle volumes
try{
data.Volumes.Boundary.forEach(function(obj){
var lineStringArr = [];
var matches = [...obj._text.matchAll(re)];
matches.forEach(function(match){
// Convert vaySys DMS into decimal degrees
// https://github.com/vatSys/xml-tools/blob/master/DotAIPtoXML/DotAIPtoXML/Coordinate.cs#L119
var pos = {
latitude: [
parseInt(match.groups.latD),
parseInt(match.groups.latM),
parseFloat(match.groups.latS)
],
latRef: (match.groups.latRef == '+') ? "N" : "S",
longitude: [
parseInt(match.groups.lonD),
parseInt(match.groups.lonM),
parseFloat(match.groups.lonS)
],
lonRef: (match.groups.lonRef == '+') ? "E" : "W"
}
var [ latitude, longitude ] = dms2dec(pos.latitude,pos.latRef,pos.longitude,pos.lonRef);
// Turf is geoJSON so we continue the stupidity here with long THEN lat.
lineStringArr.push([longitude, latitude]);
});
polys.push(lineToPolygon(lineString(lineStringArr),{mutate: true, properties: {name: obj._attributes.Name}}));
})
}catch(err){
console.log(err);
}

return polys
};

Expand Down
Loading

0 comments on commit 3de5770

Please sign in to comment.