I am attempting to do something that I assumed would be quite easy but since I'm relatively new to JavaScript, I have to be missing something. I'm trying to get the map coordinates based on screen coordinates (on a click event). The code below gives logs the screen coordinates. Reading the documentation, I assumed using the .toMap() method would convert the screen coordinates to map coordinates. Any idea what I am missing or if I'm even on the right track?
 
const map = new Map({
        basemap: "gray-vector",
    });
const view = new MapView({
        map: map,
        zoom: 7,
        center: [-93, 46.5], // longitude, latitude
        container: "viewDiv",
    });
 
const viewState = new ViewState({        view: view,
    })
document.addEventListener("click", onClickCoordinates);
function onClickCoordinates(event) {
        var outCoordinate = []
        const xCoord = event.clientX;
        const yCoord = event.clientY;
        const mapCoordinates = viewState.toMap(outCoordinate, xCoord, yCoord)
        console.log(mapCoordinates);
    };
 
Thanks!