Compare commits
5 Commits
8a1f42c6be
...
trunk
Author | SHA1 | Date | |
---|---|---|---|
e7ec5b7ed9 | |||
42aeba4e04 | |||
ac13371e40 | |||
84d1a56cb2 | |||
6ae9200c06 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
package*
|
package*
|
||||||
node_modules
|
node_modules
|
||||||
|
testthings
|
||||||
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
128
index.html
128
index.html
@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Honestly stolen from BlackSharkDen</title>
|
<title>DCSW Server Map</title>
|
||||||
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
|
||||||
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
|
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
|
||||||
<link href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" rel="stylesheet" />
|
<link href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" rel="stylesheet" />
|
||||||
@ -28,18 +28,132 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
<pre id="info"></pre>
|
<pre id="info"></pre>
|
||||||
<script>
|
<script>
|
||||||
var map = new maplibregl.Map({
|
// Variables
|
||||||
container: 'map',
|
const api_key = "rYNCGwdgATyHCjyDil7t";
|
||||||
style: 'https://api.maptiler.com/maps/topo-v2/style.json?key=<replace-me>',
|
const serverURL = "http://homeplate.close-air.support:8888/";
|
||||||
|
var latest = [];
|
||||||
|
var oldest= [];
|
||||||
|
var Units;
|
||||||
|
|
||||||
|
// Deploy stuff
|
||||||
|
var map = new maplibregl.Map({
|
||||||
center: [42, 42],
|
center: [42, 42],
|
||||||
|
container: "map",
|
||||||
|
style: "https://api.maptiler.com/maps/topo-v2/style.json?key="+api_key,
|
||||||
zoom: 7
|
zoom: 7
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('load', function () {
|
// Update, you know...the things.
|
||||||
|
map.on("load", () => {
|
||||||
|
window.setInterval( () => {
|
||||||
|
|
||||||
|
// Step 1 -- Update contents
|
||||||
|
fetchContent();
|
||||||
|
|
||||||
});
|
// Step 2 -- Add all the units added
|
||||||
|
units_added = unitsAdded();
|
||||||
|
if (units_added.length != 0) {
|
||||||
|
// units_added
|
||||||
|
// addElements(units_added);
|
||||||
|
for (i in units_added) {
|
||||||
|
unit = fetchUnit(units_added[i])
|
||||||
|
let UnitImage = unit.UnitName+"-img";
|
||||||
|
let UnitSource = unit.UnitName+"-src";
|
||||||
|
let UnitPoint = unit.UnitName+"-point";
|
||||||
|
let UnitLong = unit.Longitude;
|
||||||
|
let UnitLati = unit.Latitude;
|
||||||
|
let UnitCoalition = unit.Coalition;
|
||||||
|
let UnitType = unit.Type;
|
||||||
|
|
||||||
|
map.loadImage(
|
||||||
|
"/symbols/"+UnitCoalition+"/"+UnitType+".png",
|
||||||
|
(error, image) => {
|
||||||
|
if (error) throw error;
|
||||||
|
map.addImage(UnitImage, image);
|
||||||
|
map.addSource(UnitSource, { "type": 'geojson', 'data': { 'type': 'FeatureCollection', 'features': [{ 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [UnitLong, UnitLati] } }] } } );
|
||||||
|
map.addLayer({ 'id': UnitPoint, 'type': 'symbol', 'source': UnitSource, 'layout': { 'icon-image': UnitImage, 'icon-size': 0.25 } }); // map.addLayer()
|
||||||
|
}
|
||||||
|
); // map.loadImage()
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 3 -- Remove all the units removed
|
||||||
|
units_rmved = unitsRemoved();
|
||||||
|
if (units_rmved != 0) {
|
||||||
|
for (i in units_rmved) {
|
||||||
|
unit = units_rmved[i];
|
||||||
|
let UnitImage = unit+"-img";
|
||||||
|
let UnitSource = unit+"-src";
|
||||||
|
let UnitPoint = unit+"-point";
|
||||||
|
|
||||||
|
if (map.getLayer(UnitPoint)) map.removeLayer(UnitPoint);
|
||||||
|
map.removeSource(UnitSource);
|
||||||
|
if (map.hasImage(UnitImage)) map.removeImage(UnitImage);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 4 -- Update all the Units positions
|
||||||
|
for (i in Units) {
|
||||||
|
let UnitSource = Units[i].UnitName+"-src";
|
||||||
|
let UnitLong = Units[i].Longitude;
|
||||||
|
let UnitLati = Units[i].Latitude;
|
||||||
|
|
||||||
|
const json = {
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
'type': 'Point',
|
||||||
|
'coordinates': [UnitLong, UnitLati]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
map.getSource(UnitSource).setData(json);
|
||||||
|
};
|
||||||
|
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
function fetchUnit(unitName) {
|
||||||
|
for (i in Units) {
|
||||||
|
if (unitName == Units[i].UnitName) {
|
||||||
|
return Units[i];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function fetchContent() {
|
||||||
|
oldest = latest;
|
||||||
|
Units = fetchData(serverURL);
|
||||||
|
latest = convertJSON(Units);
|
||||||
|
};
|
||||||
|
|
||||||
|
function convertJSON(jsonFile) {
|
||||||
|
var myArray = [];
|
||||||
|
for (index in jsonFile) { myArray.push(jsonFile[index].UnitName); };
|
||||||
|
return myArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
function unitsRemoved() {
|
||||||
|
var myArray = [];
|
||||||
|
myArray = oldest.filter(x => !latest.includes(x));
|
||||||
|
return myArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
function unitsAdded() {
|
||||||
|
var myArray = [];
|
||||||
|
myArray = latest.filter(x => !oldest.includes(x));
|
||||||
|
return myArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
function fetchData(url)
|
||||||
|
{
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var retval
|
||||||
|
|
||||||
|
xhr.open("GET", url, false);
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
|
return JSON.parse(xhr.responseText)
|
||||||
|
};
|
||||||
|
|
||||||
function MGRSString (Lat, Long) {
|
function MGRSString (Lat, Long) {
|
||||||
//if (Lat < -80) return 'Too far South' ; if (Lat > 84) return 'Too far North' ;
|
//if (Lat < -80) return 'Too far South' ; if (Lat > 84) return 'Too far North' ;
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
[{"AgeInSeconds":90,"UnitName":"Aerial-1-2","GroupName":"Aerial-1","Name":"MiG-29S","Latitude":45.399451,"Longitude":38.184781,"AltitudeInFeet":1999.321414,"SpeedInKnots":427.77154101671533,"SpeedInKph":792.2328949576491,"SpeedInMps":220.06469304379144,"SpeedInMph":492.2715144573788,"HeadingInRads":1.762799,"Heading":101.000942829882,"PitchInRads":0.038021,"Pitch":2.178442832866903,"BankInRads":-0.000001,"Bank":-0.00005729577951308232,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-1","GroupName":"Ground-1","Name":"T-90","Latitude":43.946023,"Longitude":44.562986,"AltitudeInFeet":161.113172,"SpeedInKnots":3.6273796551731814,"SpeedInKph":6.717907129815437,"SpeedInMps":1.8660853138376214,"SpeedInMph":4.174320881935929,"HeadingInRads":4.544874,"Heading":260.4020986187405,"PitchInRads":0.003241,"Pitch":0.1856956214018998,"BankInRads":0.002799,"Bank":0.16037088685711742,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-2","GroupName":"Ground-1","Name":"T-90","Latitude":43.946122,"Longitude":44.563687,"AltitudeInFeet":160.948273,"SpeedInKnots":1.4199601085148394,"SpeedInKph":2.6297661242713,"SpeedInMps":0.7304905900753611,"SpeedInMph":1.6340636205631784,"HeadingInRads":3.643277,"Heading":208.74439569708403,"PitchInRads":0.000169,"Pitch":0.009682986737710913,"BankInRads":0.004216,"Bank":0.24155900642715508,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-3","GroupName":"Ground-1","Name":"T-90","Latitude":43.945995,"Longitude":44.564075,"AltitudeInFeet":161.089632,"SpeedInKnots":0.19183802600390937,"SpeedInKph":0.355284024605319,"SpeedInMps":0.09869000683481083,"SpeedInMph":0.22076362388906176,"HeadingInRads":3.66174,"Heading":209.80224767423405,"PitchInRads":0.000088,"Pitch":0.005042028597151244,"BankInRads":0.004218,"Bank":0.24167359798618127,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-4","GroupName":"Ground-1","Name":"T-90","Latitude":43.945688,"Longitude":44.564064,"AltitudeInFeet":161.178002,"SpeedInKnots":0,"SpeedInKph":0,"SpeedInMps":0,"SpeedInMph":0,"HeadingInRads":4.934405,"Heading":282.72058090825095,"PitchInRads":-0.004003,"Pitch":-0.2293550053908685,"BankInRads":0.001321,"Bank":0.07568772473678174,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Aerial-2-1","GroupName":"Aerial-2","Name":"A-10C_2","Latitude":41.2104,"Longitude":45.184938,"AltitudeInFeet":1999.999785,"SpeedInKnots":236.19889286071293,"SpeedInKph":437.44035012727096,"SpeedInMps":121.51120836868638,"SpeedInMph":271.8132824482493,"HeadingInRads":4.818095,"Heading":276.05650879308433,"PitchInRads":0.092196,"Pitch":5.282441687988138,"BankInRads":-0.000002,"Bank":-0.00011459155902616463,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-2-1","GroupName":"Ground-2","Name":"Hummer","Latitude":42.1653,"Longitude":41.67057,"AltitudeInFeet":5.001005,"SpeedInKnots":1.3131832788749105,"SpeedInKph":2.432015435529865,"SpeedInMps":0.6755598432027402,"SpeedInMph":1.5111868356539377,"HeadingInRads":1.662548,"Heading":95.25698363791598,"PitchInRads":-0,"Pitch":-0,"BankInRads":-0,"Bank":-0,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Sioctan","GroupName":"Aerial-3","Name":"A-10C_2","Latitude":42.528224,"Longitude":44.792756,"AltitudeInFeet":9473.65321,"SpeedInKnots":297.3013025691407,"SpeedInKph":550.60201304936,"SpeedInMps":152.94500362482222,"SpeedInMph":342.12879640850986,"HeadingInRads":4.867281,"Heading":278.87465900421483,"PitchInRads":0.128914,"Pitch":7.386228120149495,"BankInRads":0.000006,"Bank":0.00034377467707849394,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Naval-1-1","GroupName":"Naval-1","Name":"CV_1143_5","Latitude":43.283263,"Longitude":39.612781,"AltitudeInFeet":0,"SpeedInKnots":15.5569259904678,"SpeedInKph":28.81142697052071,"SpeedInMps":8.003174158477975,"SpeedInMph":17.902620402065722,"HeadingInRads":2.158191,"Heading":123.65523568311865,"PitchInRads":0,"Pitch":0,"BankInRads":-0,"Bank":-0,"Coalition":"Allies","Type":"table"}]
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
[{"AgeInSeconds":90,"UnitName":"Aerial-1-1","GroupName":"Aerial-1","Name":"MiG-29S","Latitude":45.407235,"Longitude":38.195719,"AltitudeInFeet":1999.999786,"SpeedInKnots":427.7474485540045,"SpeedInKph":792.1882757166527,"SpeedInMps":220.0522988101813,"SpeedInMph":492.24378930044696,"HeadingInRads":1.762797,"Heading":101.00082823832298,"PitchInRads":0.03797,"Pitch":2.175520748111736,"BankInRads":-0.000001,"Bank":-0.00005729577951308232,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Aerial-1-2","GroupName":"Aerial-1","Name":"MiG-29S","Latitude":45.399451,"Longitude":38.184781,"AltitudeInFeet":1999.321414,"SpeedInKnots":427.77154101671533,"SpeedInKph":792.2328949576491,"SpeedInMps":220.06469304379144,"SpeedInMph":492.2715144573788,"HeadingInRads":1.762799,"Heading":101.000942829882,"PitchInRads":0.038021,"Pitch":2.178442832866903,"BankInRads":-0.000001,"Bank":-0.00005729577951308232,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-1","GroupName":"Ground-1","Name":"T-90","Latitude":43.946023,"Longitude":44.562986,"AltitudeInFeet":161.113172,"SpeedInKnots":3.6273796551731814,"SpeedInKph":6.717907129815437,"SpeedInMps":1.8660853138376214,"SpeedInMph":4.174320881935929,"HeadingInRads":4.544874,"Heading":260.4020986187405,"PitchInRads":0.003241,"Pitch":0.1856956214018998,"BankInRads":0.002799,"Bank":0.16037088685711742,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-2","GroupName":"Ground-1","Name":"T-90","Latitude":43.946122,"Longitude":44.563687,"AltitudeInFeet":160.948273,"SpeedInKnots":1.4199601085148394,"SpeedInKph":2.6297661242713,"SpeedInMps":0.7304905900753611,"SpeedInMph":1.6340636205631784,"HeadingInRads":3.643277,"Heading":208.74439569708403,"PitchInRads":0.000169,"Pitch":0.009682986737710913,"BankInRads":0.004216,"Bank":0.24155900642715508,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-3","GroupName":"Ground-1","Name":"T-90","Latitude":43.945995,"Longitude":44.564075,"AltitudeInFeet":161.089632,"SpeedInKnots":0.19183802600390937,"SpeedInKph":0.355284024605319,"SpeedInMps":0.09869000683481083,"SpeedInMph":0.22076362388906176,"HeadingInRads":3.66174,"Heading":209.80224767423405,"PitchInRads":0.000088,"Pitch":0.005042028597151244,"BankInRads":0.004218,"Bank":0.24167359798618127,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-4","GroupName":"Ground-1","Name":"T-90","Latitude":43.945688,"Longitude":44.564064,"AltitudeInFeet":161.178002,"SpeedInKnots":0,"SpeedInKph":0,"SpeedInMps":0,"SpeedInMph":0,"HeadingInRads":4.934405,"Heading":282.72058090825095,"PitchInRads":-0.004003,"Pitch":-0.2293550053908685,"BankInRads":0.001321,"Bank":0.07568772473678174,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Aerial-2-1","GroupName":"Aerial-2","Name":"A-10C_2","Latitude":41.2104,"Longitude":45.184938,"AltitudeInFeet":1999.999785,"SpeedInKnots":236.19889286071293,"SpeedInKph":437.44035012727096,"SpeedInMps":121.51120836868638,"SpeedInMph":271.8132824482493,"HeadingInRads":4.818095,"Heading":276.05650879308433,"PitchInRads":0.092196,"Pitch":5.282441687988138,"BankInRads":-0.000002,"Bank":-0.00011459155902616463,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-2-1","GroupName":"Ground-2","Name":"Hummer","Latitude":42.1653,"Longitude":41.67057,"AltitudeInFeet":5.001005,"SpeedInKnots":1.3131832788749105,"SpeedInKph":2.432015435529865,"SpeedInMps":0.6755598432027402,"SpeedInMph":1.5111868356539377,"HeadingInRads":1.662548,"Heading":95.25698363791598,"PitchInRads":-0,"Pitch":-0,"BankInRads":-0,"Bank":-0,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Sioctan","GroupName":"Aerial-3","Name":"A-10C_2","Latitude":42.528224,"Longitude":44.792756,"AltitudeInFeet":9473.65321,"SpeedInKnots":297.3013025691407,"SpeedInKph":550.60201304936,"SpeedInMps":152.94500362482222,"SpeedInMph":342.12879640850986,"HeadingInRads":4.867281,"Heading":278.87465900421483,"PitchInRads":0.128914,"Pitch":7.386228120149495,"BankInRads":0.000006,"Bank":0.00034377467707849394,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Naval-1-1","GroupName":"Naval-1","Name":"CV_1143_5","Latitude":43.283263,"Longitude":39.612781,"AltitudeInFeet":0,"SpeedInKnots":15.5569259904678,"SpeedInKph":28.81142697052071,"SpeedInMps":8.003174158477975,"SpeedInMph":17.902620402065722,"HeadingInRads":2.158191,"Heading":123.65523568311865,"PitchInRads":0,"Pitch":0,"BankInRads":-0,"Bank":-0,"Coalition":"Allies","Type":"table"}]
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
[{"AgeInSeconds":90,"UnitName":"Aerial-1-1","GroupName":"Aerial-1","Name":"MiG-29S","Latitude":45.407235,"Longitude":38.195719,"AltitudeInFeet":1999.999786,"SpeedInKnots":427.7474485540045,"SpeedInKph":792.1882757166527,"SpeedInMps":220.0522988101813,"SpeedInMph":492.24378930044696,"HeadingInRads":1.762797,"Heading":101.00082823832298,"PitchInRads":0.03797,"Pitch":2.175520748111736,"BankInRads":-0.000001,"Bank":-0.00005729577951308232,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Aerial-1-2","GroupName":"Aerial-1","Name":"MiG-29S","Latitude":45.399451,"Longitude":38.184781,"AltitudeInFeet":1999.321414,"SpeedInKnots":427.77154101671533,"SpeedInKph":792.2328949576491,"SpeedInMps":220.06469304379144,"SpeedInMph":492.2715144573788,"HeadingInRads":1.762799,"Heading":101.000942829882,"PitchInRads":0.038021,"Pitch":2.178442832866903,"BankInRads":-0.000001,"Bank":-0.00005729577951308232,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-1","GroupName":"Ground-1","Name":"T-90","Latitude":43.946023,"Longitude":44.562986,"AltitudeInFeet":161.113172,"SpeedInKnots":3.6273796551731814,"SpeedInKph":6.717907129815437,"SpeedInMps":1.8660853138376214,"SpeedInMph":4.174320881935929,"HeadingInRads":4.544874,"Heading":260.4020986187405,"PitchInRads":0.003241,"Pitch":0.1856956214018998,"BankInRads":0.002799,"Bank":0.16037088685711742,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-2","GroupName":"Ground-1","Name":"T-90","Latitude":43.946122,"Longitude":44.563687,"AltitudeInFeet":160.948273,"SpeedInKnots":1.4199601085148394,"SpeedInKph":2.6297661242713,"SpeedInMps":0.7304905900753611,"SpeedInMph":1.6340636205631784,"HeadingInRads":3.643277,"Heading":208.74439569708403,"PitchInRads":0.000169,"Pitch":0.009682986737710913,"BankInRads":0.004216,"Bank":0.24155900642715508,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-3","GroupName":"Ground-1","Name":"T-90","Latitude":43.945995,"Longitude":44.564075,"AltitudeInFeet":161.089632,"SpeedInKnots":0.19183802600390937,"SpeedInKph":0.355284024605319,"SpeedInMps":0.09869000683481083,"SpeedInMph":0.22076362388906176,"HeadingInRads":3.66174,"Heading":209.80224767423405,"PitchInRads":0.000088,"Pitch":0.005042028597151244,"BankInRads":0.004218,"Bank":0.24167359798618127,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-1-4","GroupName":"Ground-1","Name":"T-90","Latitude":43.945688,"Longitude":44.564064,"AltitudeInFeet":161.178002,"SpeedInKnots":0,"SpeedInKph":0,"SpeedInMps":0,"SpeedInMph":0,"HeadingInRads":4.934405,"Heading":282.72058090825095,"PitchInRads":-0.004003,"Pitch":-0.2293550053908685,"BankInRads":0.001321,"Bank":0.07568772473678174,"Coalition":"Allies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Aerial-2-1","GroupName":"Aerial-2","Name":"A-10C_2","Latitude":41.2104,"Longitude":45.184938,"AltitudeInFeet":1999.999785,"SpeedInKnots":236.19889286071293,"SpeedInKph":437.44035012727096,"SpeedInMps":121.51120836868638,"SpeedInMph":271.8132824482493,"HeadingInRads":4.818095,"Heading":276.05650879308433,"PitchInRads":0.092196,"Pitch":5.282441687988138,"BankInRads":-0.000002,"Bank":-0.00011459155902616463,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Ground-2-1","GroupName":"Ground-2","Name":"Hummer","Latitude":42.1653,"Longitude":41.67057,"AltitudeInFeet":5.001005,"SpeedInKnots":1.3131832788749105,"SpeedInKph":2.432015435529865,"SpeedInMps":0.6755598432027402,"SpeedInMph":1.5111868356539377,"HeadingInRads":1.662548,"Heading":95.25698363791598,"PitchInRads":-0,"Pitch":-0,"BankInRads":-0,"Bank":-0,"Coalition":"Enemies","Type":"table"},{"AgeInSeconds":90,"UnitName":"Sioctan","GroupName":"Aerial-3","Name":"A-10C_2","Latitude":42.528224,"Longitude":44.792756,"AltitudeInFeet":9473.65321,"SpeedInKnots":297.3013025691407,"SpeedInKph":550.60201304936,"SpeedInMps":152.94500362482222,"SpeedInMph":342.12879640850986,"HeadingInRads":4.867281,"Heading":278.87465900421483,"PitchInRads":0.128914,"Pitch":7.386228120149495,"BankInRads":0.000006,"Bank":0.00034377467707849394,"Coalition":"Enemies","Type":"table"}]
|
|
||||||
|
|
85
test.html
Normal file
85
test.html
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>DCSW Server Map: Table Edition</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<table border="1" cellpadding="5" cellspacing="0" id="myList" id="myTable"></table>
|
||||||
|
|
||||||
|
<p id="notes">Notes go here.</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Global Vars, cuzz we <3 anti-patterns
|
||||||
|
const serverURL = "http://homeplate.close-air.support:8888/";
|
||||||
|
var latest;
|
||||||
|
var oldest;
|
||||||
|
var Units;
|
||||||
|
|
||||||
|
// Update, you know...the things.
|
||||||
|
window.setInterval(updateContents, 5000);
|
||||||
|
|
||||||
|
function updateContents() {
|
||||||
|
|
||||||
|
var notifications = "";
|
||||||
|
|
||||||
|
fetchContent();
|
||||||
|
units_added = unitsAdded();
|
||||||
|
if (units_added.length != 0) {
|
||||||
|
notifications = notifications + "Units Added: "+units_added+"<br/>";
|
||||||
|
};
|
||||||
|
units_rmved = unitsRemoved();
|
||||||
|
if (units_rmved != 0) {
|
||||||
|
notifications = notifications + "Units Removed: "+units_rmved+"<br/>";
|
||||||
|
};
|
||||||
|
document.getElementById("notes").innerHTML = notifications;
|
||||||
|
renderContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchContent() {
|
||||||
|
oldest = latest;
|
||||||
|
Units = fetchData(serverURL);
|
||||||
|
latest = convertJSON(Units);
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertJSON(jsonFile) {
|
||||||
|
var myArray = [];
|
||||||
|
for (index in jsonFile) { myArray.push(jsonFile[index].UnitName); };
|
||||||
|
return myArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unitsRemoved() {
|
||||||
|
var myArray = [];
|
||||||
|
myArray = oldest.filter(x => !latest.includes(x));
|
||||||
|
return myArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unitsAdded() {
|
||||||
|
var myArray = [];
|
||||||
|
myArray = latest.filter(x => !oldest.includes(x));
|
||||||
|
return myArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderContents() {
|
||||||
|
var myTable
|
||||||
|
for (unitIndex in Units)
|
||||||
|
{
|
||||||
|
myTable = myTable + "<tr><td>"+Units[unitIndex].UnitName+"</td><td>"+Units[unitIndex].Name+"</td><td>"+Units[unitIndex].SpeedInKnots+"</td>";
|
||||||
|
};
|
||||||
|
document.getElementById("myList").innerHTML = myTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchData(url)
|
||||||
|
{
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var retval;
|
||||||
|
|
||||||
|
xhr.open("GET", url, false);
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
|
return JSON.parse(xhr.responseText);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user