angular - OpenLayer 将地图导出到 Image
问题描述
我正在使用 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
});
}
解决方案
您可以使用将打印封装在控件中的ol-ext 打印控件。
推荐阅读
- android - Google Play 控制台给出错误。“Произошлаошибка。Повторите попытку позже。”
- oauth-2.0 - 角度认证 OIDC;Azue B2C:从 Azure 获取令牌后获取用户配置文件加载并承诺未捕获的错误
- javascript - 编写这些函数以检查数字是否按升序/降序连续的更简洁的方法
- typescript - 根据第一个参数的值将第二个参数定义为条件类型
- entity-framework - 如何通过 Entity Framework Core 中的多对多额外列进行排序?
- sql - Converting column to decimal in stored procedure
- python - 为什么python打印最后一个键
- python - 如何从数据库中获取数据到模态形式?
- javascript - Javascript事件目标值显示输入框的先前值
- spring - Spring Config 未获取环境变量