1

I'm creating an OpenLayers draw application where I let users draw shapes and then I allow them to print maps on pdf by zooming into the drawn shape. My current code is working for - Draw Geometry, Zoom to the geometry. For printing, I'm currently using

map.once('postcompose', function(e){
var canvas = e.context.canvas;
data = canvas.toDataURL("image/jpg");
doc.addImage(data, "jpg", 10, 50, 190, 120);
})

but the problem is it doesn't wait for complete loading of basemap, because of which I'm getting blurred background. enter image description here

how can I fix this?

krishna lodha
  • 381
  • 3
  • 9
  • 2
    In OpenLayers 5 and above use `rendercomplete` as in https://openlayers.org/en/v5.3.0/examples/export-pdf.html In earlier versions you need to count the loading tiles as in https://openlayers.org/en/v4.6.5/examples/export-pdf.htm – Mike Mar 10 '21 at 13:51
  • I tried `rendercomplete` but I'm getting event.context.canvas undefined – krishna lodha Mar 10 '21 at 18:02
  • Are you using OL6? There can be multiple canvases which you need to combine https://openlayers.org/en/latest/examples/export-pdf.html – Mike Mar 10 '21 at 18:13

0 Answers0