当我尝试从使用map.capture函数返回的画布保存图像时,我收到以下错误:
未捕获DOMException:无法执行'toDataURL' 'HTMLCanvasElement':可能无法导出受污染的画布。
我正在使用Here API示例中的以下代码:
map.capture(function(canvas) {
if ( canvas ) {
snapshotContainer.innerHTML = '';
snapshotContainer.appendChild(canvas);
console.log( canvas.toDataURL() );
}else{
snapshotContainer.innerHTML = 'Capturing is not supported';
}
}, [ui], 0, 0, 1000, 1000);
画布出现在snapshotContainer对象中。
答案 0 :(得分:0)
此示例有助于:https://tcs.ext.here.com/examples/v3/fleet
function capture(map, ui) {
// Capturing area of the map is asynchronous, callback function receives HTML5 canvas
// element with desired map area rendered on it.
// We also pass a H.ui.UI reference in order to see the ScaleBar in the result.
// If dimensions are omitted, whole map will be captured, from top left corner up to
// the bottom right.
map.capture(function(canvas) {
if (canvas) {
snapshotContainer.innerHTML = '';
snapshotContainer.appendChild(canvas);
window.open(canvas.toDataURL());
} else {
// For example when map is in Panorama mode
alert('Capturing is not supported');
}
}, [ui], 0, 0, document.getElementById("mapContainer").offsetWidth, document.getElementById("mapContainer").offsetHeight);
}