Codes et extraits donnés par chat-gpt ou Codex(sandbox). /* a function to read latitude and longitude from a .txt file */ function readTextFile(file) { var rawFile = new XMLHttpRequest(); rawFile.open("GET", file, false); rawFile.onreadystatechange = function () { if(rawFile.readyState === 4) { if(rawFile.status === 200 || rawFile.status == 0) { var allText = rawFile.responseText; alert(allText); } } } rawFile.send(null); } /* then post this to another function */ function plotOnWebglEarth(lat, lon) { /* i need a function to read latitude and longitude from a .txt or .xml file, and post those datas to a function that plots it on webgl-earth. As this will work on esp8266 stand alone server, i can't use node.js, but only plain pure javascript. */ var latitude = 0; var longitude = 0; function read_lat_long() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var lat_long = this.responseText; var lat_long_array = lat_long.split(","); latitude = lat_long_array[0]; longitude = lat_long_array[1]; console.log(latitude); console.log(longitude); } }; xhttp.open("GET", "lat_long.txt", true); xhttp.send(); } function plot_lat_long() { var earth = new WE.map('earth_div'); WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(earth); var marker = WE.marker([latitude, longitude]).addTo(earth); var lat = [], lon = []; for (var i = 0; i < data.length; i++) { lat.push(data[i].latitude); lon.push(data[i].longitude); } /* make a red bouncing ball */ var ball = document.createElement('div'); ball.style.width = '20px'; ball.style.height = '20px'; ball.style.backgroundColor = 'red'; ball.style.borderRadius = '10px'; ball.style.position = 'absolute'; ball.style.top = '0px'; ball.style.left = '0px'; document.body.appendChild(ball); var x = 0; var y = 0; var dx = 1; var dy = 1; function animate() { x += dx; y += dy; if (x > window.innerWidth - 20) { x = window.innerWidth - 20; dx = -dx; } if (x < 0) { x = 0; dx = -dx; } if (y > window.innerHeight - 20) { y = window.innerHeight - 20; dy = -dy; } if (y < 0) { y = 0; dy = -dy; } ball.style.left = x + 'px'; ball.style.top = y + 'px'; window.requestAnimationFrame(animate); } animate();