I'm using the following JS to transform Latitude and Longitude to X and Y coordinates but now I need the contrary, transforming Latitude and Longitude to X and Y.
export const latLon2xy = (lat, lon, width, height) => {
const x = Math.round((width * (180 + lon) / 360) % (1.5 * width))
const rad = lat * Math.PI / 180
const merc = 0.5 * Math.log((1 + Math.sin(rad)) / (1 - Math.sin(rad)))
const y = Math.round((width * merc / (2 * Math.PI)))
return {x: x, y: y}
}