index.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Honestly stolen from BlackSharkDen</title>
  6. <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  7. <script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
  8. <link href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" rel="stylesheet" />
  9. <style>
  10. body { margin: 0; padding: 0; }
  11. #map { position: absolute; top: 0; bottom: 0; width: 100%; }
  12. #info {
  13. display: block;
  14. position: relative;
  15. margin: 0px auto;
  16. width: 50%;
  17. padding: 10px;
  18. border: none;
  19. border-radius: 3px;
  20. font-size: 12px;
  21. text-align: center;
  22. color: #222;
  23. background: #fff;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="map"></div>
  29. <pre id="info"></pre>
  30. <script>
  31. // const sleep = ms => new Promise(r => setTimeout(r, ms));
  32. var api_key = "rYNCGwdgATyHCjyDil7t";
  33. var serverURL = "http://homeplate.close-air.support:8888/";
  34. var map = new maplibregl.Map({
  35. center: [42, 42],
  36. container: "map",
  37. style: "https://api.maptiler.com/maps/topo-v2/style.json?key="+api_key,
  38. zoom: 7
  39. });
  40. map.on("load", () => {
  41. myData = fetchData(serverURL);
  42. for (chip in myData)
  43. {
  44. //latest.push(myData[chip].UnitName);
  45. let UnitImage = myData[chip].UnitName+"-img";
  46. let UnitSource = myData[chip].UnitName+"-src";
  47. let UnitPoint = myData[chip].UnitName+"-point";
  48. let UnitLong = myData[chip].Longitude;
  49. let UnitLati = myData[chip].Latitude;
  50. let UnitCoalition = myData[chip].Coalition;
  51. map.loadImage(
  52. "/symbols/"+UnitCoalition+"/plane.png",
  53. (error, image) => {
  54. if (error) throw error;
  55. map.addImage(UnitImage, image);
  56. map.addSource(UnitSource, { "type": 'geojson', 'data': { 'type': 'FeatureCollection', 'features': [{ 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [UnitLong, UnitLati] } }] } } );
  57. map.addLayer({
  58. 'id': UnitPoint,
  59. 'type': 'symbol',
  60. 'source': UnitSource,
  61. 'layout': {
  62. 'icon-image': UnitImage,
  63. 'icon-size': 0.25
  64. }
  65. }); // map.addLayer()
  66. }
  67. ); // map.loadImage()
  68. };// End for() loop
  69. }); // End map.on()
  70. // function wait(ms){
  71. // var start = new Date().getTime();
  72. // var end = start;
  73. // while(end < start + ms) {
  74. // end = new Date().getTime();
  75. // };
  76. // };
  77. function MGRSString (Lat, Long) {
  78. //if (Lat < -80) return 'Too far South' ; if (Lat > 84) return 'Too far North' ;
  79. var c = 1 + Math.floor ((Long+180)/6);
  80. var e = c*6 - 183 ;
  81. var k = Lat*Math.PI/180;
  82. var l = Long*Math.PI/180;
  83. var m = e*Math.PI/180;
  84. var n = Math.cos (k);
  85. var o = 0.006739496819936062*Math.pow (n,2);
  86. var p = 40680631590769/(6356752.314*Math.sqrt(1 + o));
  87. var q = Math.tan (k);
  88. var r = q*q;
  89. var s = (r*r*r) - Math.pow (q,6);
  90. var t = l - m;
  91. var u = 1.0 - r + o;
  92. var v = 5.0 - r + 9*o + 4.0*(o*o);
  93. var w = 5.0 - 18.0*r + (r*r) + 14.0*o - 58.0*r*o;
  94. var x = 61.0 - 58.0*r + (r*r) + 270.0*o - 330.0*r*o;
  95. var y = 61.0 - 479.0*r + 179.0*(r*r) - (r*r*r);
  96. var z = 1385.0 - 3111.0*r + 543.0*(r*r) - (r*r*r);
  97. var aa = p*n*t + (p/6.0*Math.pow (n,3)*u*Math.pow (t,3)) + (p/120.0*Math.pow (n,5)*w*Math.pow (t,5)) + (p/5040.0*Math.pow (n,7)*y*Math.pow (t,7));
  98. var ab = 6367449.14570093*(k - (0.00251882794504*Math.sin (2*k)) + (0.00000264354112*Math.sin (4*k)) - (0.00000000345262*Math.sin (6*k)) + (0.000000000004892*Math.sin (8*k))) + (q/2.0*p*Math.pow (n,2)*Math.pow (t,2)) + (q/24.0*p*Math.pow (n,4)*v*Math.pow (t,4)) + (q/720.0*p*Math.pow (n,6)*x*Math.pow (t,6)) + (q/40320.0*p*Math.pow (n,8)*z*Math.pow (t,8));
  99. aa = aa*0.9996 + 500000.0;
  100. ab = ab*0.9996; if (ab < 0.0) ab += 10000000.0;
  101. var ad = 'CDEFGHJKLMNPQRSTUVWXX'.charAt (Math.floor (Lat/8 + 10));
  102. var ae = Math.floor (aa/100000);
  103. var af = ['ABCDEFGH','JKLMNPQR','STUVWXYZ'][(c-1)%3].charAt (ae-1);
  104. var ag = Math.floor (ab/100000)%20;
  105. var ah = ['ABCDEFGHJKLMNPQRSTUV','FGHJKLMNPQRSTUVABCDE'][(c-1)%2].charAt (ag);
  106. function pad (val) {if (val < 10) {val = '0000' + val} else if (val < 100) {val = '000' + val} else if (val < 1000) {val = '00' + val} else if (val < 10000) {val = '0' + val};return val};
  107. aa = Math.floor (aa%100000); aa = pad (aa);
  108. ab = Math.floor (ab%100000); ab = pad (ab);
  109. return c + ad + ' ' + af + ah + ' ' + aa + ' ' + ab;
  110. };
  111. map.on('mousemove', function (e) {
  112. var coordinate = e.lngLat.wrap();
  113. document.getElementById('info').innerHTML = MGRSString(coordinate.lat, coordinate.lng);
  114. });
  115. function fetchData(url)
  116. {
  117. var xhr = new XMLHttpRequest();
  118. var retval
  119. xhr.open("GET", url, false);
  120. xhr.send();
  121. return JSON.parse(xhr.responseText)
  122. }
  123. </script>
  124. </body>
  125. </html>