I have a Javascript function that create a canvas, write a image and a text on it. At the and I need the base64 dataUrl but what I get is only a blank canvas.
This is my function:
function createBreadCrumb(label) { var canvas = document.createElement('canvas'); canvas.width = 25; canvas.height = 30; var img = new Image; img.src = 'map-pin-breadcrumb.png'; var ctx=canvas.getContext("2d"); img.onload = function(){ ctx.drawImage(img, 0, 0); ctx.font = "11px Arial"; ctx.textAlign="center"; ctx.fillText(label, 12, 16); }; return canvas.toDataURL(); }