首页 > 解决方案 > OpenLayers 版本 5.3.0,地图导出 pdf 的问题

问题描述

我使用 openlayers 5.3.0 版,我想导出地图 pdf。问题是导出的地图范围不正确。它打印错误的高度。在 openlayers(5.3.0 版)示例中(https://openlayers.org/en/v5.3.0/examples/export-pdf.html?q=pdf),结果与我的相同。打印的地图高度大于地图的范围。我在最新版本(https://openlayers.org/en/latest/examples/export-pdf.html)上也检查了相同的内容,这是绝对正确的。它准确地打印地图范围。如何在我的版本上修复它而无需更改版本?

提前致谢。

// Reset original map size
map.setSize(size);
map.getView().fit(map.getView().calculateExtent(map.getSize()), {constrainResolution: false});
map.getView().setResolution(viewResolution);
document.body.style.cursor = 'auto';


// Set print size
let printSize = [width, height];
map.setSize(printSize);
let scaling = Math.min(width / size[0], height / size[1]);
map.getView().fit(map.getView().calculateExtent(map.getSize()), { size: printSize , constrainResolution: false});
map.getView().setResolution(viewResolution/scaling);

标签: versionopenlayersexport-to-pdf

解决方案


推荐阅读