wkhtmltopdf and leaflet wait for map

杀马特。学长 韩版系。学妹 提交于 2019-12-10 16:12:24

问题


I'm using wkhtmltopdf for print my html code, this code has leaflet maps, my problem is pdf file doesnt't print the map properly, it seems it doesn't wait for the map, so I included a window-status condition without success:

In my html:

var myMap = L.map('myMap',{attributionControl: false, zoomControl:false })
    .on('load', function(){window.status = 'maploaded'});

My options for wkhtmltopdf:

 options = {
    'dpi': 300,
    'image-dpi': 400,
    'zoom': 0.7,
    'window-status': 'maploaded'
}

I check that the event is fired and the pdf is generated after it's fired, but I the map is not shown.

What should I do?


回答1:


I finally solved this issue.

The problem wasn't the time I was waiting for the map rendering but the size.

An usual "javascript-delay" is enought for this. The problem:

<div id="map" class="my-map">
      //leaflet code
</div>

.my-map{

    //not working
    //width: 80%; 
    //height:80%;

    //working
    width: 800px;
    height: 400px;
}


来源:https://stackoverflow.com/questions/50251458/wkhtmltopdf-and-leaflet-wait-for-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!