I'm facing some problems with jquery and javascript interoperability.
I have a piece of code that attempts to create a PNG from the canvas and write it to a variable.
jQuery.getScript('https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js', function() {
    //script is loaded and executed put your dependent JS here
    mapboxgl.accessToken = '<ACCESS_TOKEN>';
    var mapcanvas = new mapboxgl.Map({
        container: 'mapimg',
        style: 'mapbox://styles/mapbox/streets-v9',
        lon: center[1].toFixed(6),
        lat: center[0].toFixed(6),
        zoom: zoominfo.zoom,
        preserveDrawingBuffer: true
    });
    var getbasemapimg = mapcanvas.getCanvas().toDataURL('image/png');
    alert("Inside jQuery: " + getbasemapimg);
});
This works fine inside the jQuery section above (the alert returns getbasemapimg in its base64 string format), but further along in the script, I attempt to call the getbasemapimg variable and this time it says it's undefined:   getbasemapimg is not defined
I had to wrap the first section up in jQuery as it was calling an external javascript source and I could figure out how to get it to work without employing jQuery.
I think I need to set the value getbasemapimg globally but can't work out how to do it.
 
     
    