Compare commits

..

No commits in common. "42aeba4e04f5442d86e42883ab7222af2efcbe98" and "84d1a56cb21bf9e1932579c24d54b6fa20e03a56" have entirely different histories.

2 changed files with 58 additions and 205 deletions

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>DCSW Server Map</title> <title>Honestly stolen from BlackSharkDen</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,132 +28,59 @@
<div id="map"></div> <div id="map"></div>
<pre id="info"></pre> <pre id="info"></pre>
<script> <script>
// Variables // const sleep = ms => new Promise(r => setTimeout(r, ms));
const api_key = "rYNCGwdgATyHCjyDil7t"; var api_key = "rYNCGwdgATyHCjyDil7t";
const serverURL = "http://homeplate.close-air.support:8888/"; var serverURL = "http://homeplate.close-air.support:8888/";
var latest = []; var map = new maplibregl.Map({
var oldest= [];
var Units;
// Deploy stuff
var map = new maplibregl.Map({
center: [42, 42], center: [42, 42],
container: "map", container: "map",
style: "https://api.maptiler.com/maps/topo-v2/style.json?key="+api_key, style: "https://api.maptiler.com/maps/topo-v2/style.json?key="+api_key,
zoom: 7 zoom: 7
}); });
// Update, you know...the things. map.on("load", () => {
map.on("load", () => {
window.setInterval( () => {
// Step 1 -- Update contents myData = fetchData(serverURL);
fetchContent(); for (chip in myData)
{
// Step 2 -- Add all the units added //latest.push(myData[chip].UnitName);
units_added = unitsAdded(); let UnitImage = myData[chip].UnitName+"-img";
if (units_added.length != 0) { let UnitSource = myData[chip].UnitName+"-src";
// units_added let UnitPoint = myData[chip].UnitName+"-point";
// addElements(units_added); let UnitLong = myData[chip].Longitude;
for (i in units_added) { let UnitLati = myData[chip].Latitude;
unit = fetchUnit(units_added[i]) let UnitCoalition = myData[chip].Coalition;
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( map.loadImage(
"/symbols/"+UnitCoalition+"/"+UnitType+".png", "/symbols/"+UnitCoalition+"/plane.png",
(error, image) => { (error, image) => {
if (error) throw error; if (error) throw error;
map.addImage(UnitImage, image); map.addImage(UnitImage, image);
map.addSource(UnitSource, { "type": 'geojson', 'data': { 'type': 'FeatureCollection', 'features': [{ 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [UnitLong, UnitLati] } }] } } ); 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.addLayer({
'id': UnitPoint,
'type': 'symbol',
'source': UnitSource,
'layout': {
'icon-image': UnitImage,
'icon-size': 0.25
}
}); // map.addLayer()
} }
); // map.loadImage() ); // map.loadImage()
};
};
// Step 3 -- Remove all the units removed };// End for() loop
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); }); // End map.on()
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 = { // function wait(ms){
type: 'Feature', // var start = new Date().getTime();
geometry: { // var end = start;
'type': 'Point', // while(end < start + ms) {
'coordinates': [UnitLong, UnitLati] // end = new Date().getTime();
} // };
}; // };
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' ;
@ -196,6 +123,17 @@ function fetchData(url)
document.getElementById('info').innerHTML = MGRSString(coordinate.lat, coordinate.lng); document.getElementById('info').innerHTML = MGRSString(coordinate.lat, coordinate.lng);
}); });
function fetchData(url)
{
var xhr = new XMLHttpRequest();
var retval
xhr.open("GET", url, false);
xhr.send();
return JSON.parse(xhr.responseText)
}
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,85 +0,0 @@
<!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>