So basically I initialize an object within onMount like this-
onMount(() => {
const mapy = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/satellite-v9",
center: testCoords[0],
zoom: 19,
});
console.log(mapy);
});
Then outside I have-
function AddPoint(){
Center=mapy.getCenter;
}
AddPoint is called from a HTML button. I get this error in the console- Uncaught ReferenceError: mapy is not defined
I only press the button after it has been initialized, and I know it has been initialized because of my console.log() inside onMount