|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +title: Conversion between XYZ and Latitude/Longitude |
| 4 | +--- |
| 5 | +> Below is a tool that will help you convert up to 1000 coordinates at a time from the BTE Dymaxion projection to latitude and longitude and vice-versa. Input one coordinate pair per line, separated by a space, in the order x, z or latitude, longitude. Courtesy of [SmylerMC](https://github.com/SmylerMC). |
| 6 | +<html lang=""> |
| 7 | + <head> |
| 8 | + <meta charset="utf-8"> |
| 9 | + <link href='https://fonts.googleapis.com/css?family=Manrope' rel='stylesheet'> |
| 10 | + <style> |
| 11 | + body { |
| 12 | + text-align: center; |
| 13 | + font-family: 'Manrope';font-size: 22px; |
| 14 | + margin: 0; |
| 15 | + color: white; |
| 16 | + } |
| 17 | + main { |
| 18 | + height: 100vh; |
| 19 | + } |
| 20 | + .coordbox { |
| 21 | + display: inline-grid; |
| 22 | + width: min(400px, 85%); |
| 23 | + margin: 10px; |
| 24 | + } |
| 25 | + .coordbox textarea { |
| 26 | + min-height: 20vh; |
| 27 | + display: inline-block; |
| 28 | + border-width: 1px; |
| 29 | + border-style: solid; |
| 30 | + border-radius: 5px; |
| 31 | + border-color: #808080; |
| 32 | + resize: none; |
| 33 | + background-color: #181A1B; |
| 34 | + color: white; |
| 35 | + } |
| 36 | + .coordbox h2 { |
| 37 | + margin: 5px; |
| 38 | + } |
| 39 | + button { |
| 40 | + padding: 10px; |
| 41 | + margin: 5px; |
| 42 | + background-color: rgb(33, 150, 243); |
| 43 | + color: rgb(255, 255, 255); |
| 44 | + font-size: 1em; |
| 45 | + border-style: solid; |
| 46 | + border-radius: 5px; |
| 47 | + border-color: rgb(33, 150, 243); |
| 48 | + border-size: 8px; |
| 49 | + } |
| 50 | + button:hover { |
| 51 | + background-color: rgb(30, 136, 229); |
| 52 | + border-color: rgb(30, 136, 229); |
| 53 | + border-size: 10px; |
| 54 | + } |
| 55 | + #errorbox { |
| 56 | + background-color: rgba(190, 0, 0, 0); |
| 57 | + margin: 20px; |
| 58 | + padding: 20px; |
| 59 | + color: rgb(255, 255, 255); |
| 60 | + margin: 25px; |
| 61 | + } |
| 62 | + </style> |
| 63 | + </head> |
| 64 | + <body> |
| 65 | + <div id="content"> |
| 66 | + <main> |
| 67 | + <div id="errorbox"></div> |
| 68 | + <div class="coordbox"> |
| 69 | + <h2>Minecraft Coordinates</h2> |
| 70 | + <textarea id="mcarea"></textarea> |
| 71 | + <button onclick="mc2geo()">Minecraft → Geographic</button> |
| 72 | + </div> |
| 73 | + <div class="coordbox"> |
| 74 | + <h2>Geographic Coordinates</h2> |
| 75 | + <textarea id="geoarea"></textarea> |
| 76 | + <button onclick="geo2mc()">Geographic → Minecraft</button> |
| 77 | + </div> |
| 78 | + </main> |
| 79 | + </div> |
| 80 | + <script laguage="javascript"> |
| 81 | + const ENDPOINT = "https://smybteapi.buildtheearth.net"; |
| 82 | + function geo2mc() { |
| 83 | + clearError(); |
| 84 | + let allgeocoords = parsetextarea(document.getElementById("geoarea")); |
| 85 | + let args = []; |
| 86 | + allgeocoords.forEach(e => args.push("geopos=" + e.join(","))); |
| 87 | + let url = ENDPOINT + "/projection/fromGeo?" + args.join("&"); |
| 88 | + let req = new XMLHttpRequest(); |
| 89 | + req.onreadystatechange = function() { |
| 90 | + if (req.readyState == 4 && req.status == 200) { |
| 91 | + let res = JSON.parse(req.responseText).mc_positions; |
| 92 | + let entries = []; |
| 93 | + res.forEach(e => { |
| 94 | + if(e != null) { |
| 95 | + entries.push(e.join(" ")); |
| 96 | + } else { |
| 97 | + entries.push("Outside projection bounds"); |
| 98 | + } |
| 99 | + }); |
| 100 | + document.getElementById("mcarea").value = entries.join("\n"); |
| 101 | + } else if(req.readyState == 4 && req.status == 400) { |
| 102 | + let res = JSON.parse(req.responseText); |
| 103 | + let str = "Error: " + res.error + " (" + res.details + ")"; |
| 104 | + setError(str); |
| 105 | + } else if(req.readyState == 4){ |
| 106 | + setError("Unknown error: " + req.status); |
| 107 | + } |
| 108 | + } |
| 109 | + req.open("GET", url, true); |
| 110 | + req.send(null); |
| 111 | + } |
| 112 | + function mc2geo() { |
| 113 | + clearError(); |
| 114 | + let allmccoords = parsetextarea(document.getElementById("mcarea")); |
| 115 | + let args = []; |
| 116 | + allmccoords.forEach(e => args.push("mcpos=" + e.join(","))); |
| 117 | + let url = ENDPOINT + "/projection/toGeo?" + args.join("&"); |
| 118 | + let req = new XMLHttpRequest(); |
| 119 | + req.onreadystatechange = function() { |
| 120 | + if (req.readyState == 4 && req.status == 200) { |
| 121 | + let res = JSON.parse(req.responseText).geo_positions; |
| 122 | + let entries = []; |
| 123 | + res.forEach(e => { |
| 124 | + if(e != null) { |
| 125 | + entries.push(e.join(" ")); |
| 126 | + } else { |
| 127 | + entries.push("Outside projection bounds"); |
| 128 | + } |
| 129 | + }); |
| 130 | + document.getElementById("geoarea").value = entries.join("\n"); |
| 131 | + } else if(req.readyState == 4 && req.status == 400) { |
| 132 | + let res = JSON.parse(req.responseText); |
| 133 | + let str = "Error: " + res.error + " (" + res.details + ")"; |
| 134 | + setError(str); |
| 135 | + } else if(req.readyState == 4){ |
| 136 | + setError("Unknown error: " + req.status); |
| 137 | + } |
| 138 | + } |
| 139 | + req.open("GET", url, true); |
| 140 | + req.send(null); |
| 141 | + } |
| 142 | + function parsetextarea(textarea) { |
| 143 | + let lines = textarea.value.split("\n"); |
| 144 | + let coords = []; |
| 145 | + for(let i=0; i<lines.length; i++) { |
| 146 | + let strs = lines[i].split(" "); |
| 147 | + if(strs.length != 2) setError("Invalid line: " + lines[i]); |
| 148 | + let c1 = parseFloat(strs[0]); |
| 149 | + let c2 = parseFloat(strs[1]); |
| 150 | + if(Number.isNaN(c1) || Number.isNaN(c2)) { |
| 151 | + setError("Invalid line: " + lines[i]); |
| 152 | + return; |
| 153 | + } |
| 154 | + coords.push([c1, c2]); |
| 155 | + } |
| 156 | + return coords |
| 157 | + } |
| 158 | + function setError(err) { |
| 159 | + let element = document.getElementById("errorbox"); |
| 160 | + element.textContent = err; |
| 161 | + element.style.backgroundColor = "#FF0000"; |
| 162 | + } |
| 163 | + function clearError() { |
| 164 | + let element = document.getElementById("errorbox"); |
| 165 | + element.style.backgroundColor = "#00000000"; |
| 166 | + element.textContent = ""; |
| 167 | + } |
| 168 | + </script> |
| 169 | + </body> |
| 170 | +</html> |
0 commit comments