【发布时间】:2020-06-10 04:37:03
【问题描述】:
我正在使用 Angular 8
我正在尝试导出使用 openlayer 创建的地图的图像/blob,但我无法让它工作。我什至尝试将 ViewChild 与 html2canvas 一起使用,但随后我只获得了 div 中除地图之外的所有内容。
@ViewChild('download', { static: false }) public download: ElementRef;
pdfDownload() {
let domElement = this.download.nativeElement as HTMLElement;
console.log(domElement);
html2canvas(domElement).then(canvas => {
var imgData = canvas.toDataURL("image/png");
console.log(imgData); //here i get a blob that has everything from the div like buttons and so on, but not the map itself thats also inside this div
});
}
我确实看到了一些带有 openlayer 的 javascript 版本,他们设法在不使用其他库的情况下下载它,但我无法设法将其翻译成打字稿。
任何知道如何仅使用 openlayer 或使用 html2canvas 库来使其工作的人吗?或者 mby 甚至是别的什么?
也尝试了以下但没有成功,因为它基本上是一样的
pdfDownload() {
var cnvs = document.getElementById('map');
html2canvas(cnvs).then(canvas => {
var imgData = canvas.toDataURL("image/png");
console.log(imgData); //here i get a blob that has everything from the div like buttons and so on, but not the map itself thats also inside this div
});
}
【问题讨论】:
-
这是一个使用 html-to-image 的旧示例openlayers.org/en/v6.2.1/examples/export-map.html 当前版本结合了画布github.com/openlayers/openlayers/blob/master/examples/…
-
这来自 javascript,我无法将其翻译成打字稿
-
我的第一个链接与您已经尝试的非常相似。 html-to-image 可以选择按类名排除元素。 html2canvas 还有一个 ignoreElements 选项。
标签: angular openlayers html2canvas