I’m using the ol-ext print dialog to enable printing with Openlayers. There was no option to type the map title.
So I added the code:
// Add a title control
map.addControl(new ol.control.CanvasTitle({
title: 'my title',
visible: false,
style: new ol.style.Style({ text: new ol.style.Text({ font: '20px "Lucida Grande",Verdana,Geneva,Lucida,Arial,Helvetica,sans-serif'}) })
}));
After this update, I was no longer able to generate PDF and it shows the error:”Can’t save map canvas…”
Complete code follows.
// Print control
var printControl = new ol.control.PrintDialog({
});
printControl.setSize('A4');
map.addControl(printControl);
/* On print > save image file */
printControl.on(['print', 'error'], function(e) {
// Print success
if (e.image) {
if (e.pdf) {
// Export pdf using the print info
var pdf = new jsPDF({
orientation: e.print.orientation,
unit: e.print.unit,
format: e.print.size
});
pdf.addImage(e.image, 'JPEG', e.print.position[0], e.print.position[0], e.print.imageWidth, e.print.imageHeight);
pdf.save(e.print.legend ? 'legend.pdf' : 'map.pdf');
} else {
// Save image as file
e.canvas.toBlob(function(blob) {
var name = (e.print.legend ? 'legend.' : 'map.')+e.imageType.replace('image/','');
saveAs(blob, name);
}, e.imageType, e.quality);
}
} else {
console.warn('No canvas to export');
}
});
Does anyone know what it could be?
// Add a title control
map.addControl(new ol.control.CanvasTitle({
title: 'my title',
visible: false,
style: new ol.style.Style({ text: new ol.style.Text({ font: '20px "Lucida Grande",Verdana,Geneva,Lucida,Arial,Helvetica,sans-serif'}) })
}));