javascript - 使用 JavaScript 从 msSaveBlob 对象客户端创建 GIF
问题描述
我有一个 Vue 应用程序,它只是一个 OpenLayers 地图,我可以使用从官方文档中获取的以下函数将其保存为图像。
exportMap: function () {
this.map.once('rendercomplete', function () {
const mapCanvas = document.createElement('canvas');
const divElement = document.querySelector(".map");
mapCanvas.width = divElement.offsetWidth;//size[0];
mapCanvas.height = divElement.offsetHeight;//size[1];
const mapContext = mapCanvas.getContext('2d');
Array.prototype.forEach.call(
document.querySelectorAll('.ol-layer canvas'),
function (canvas) {
if (canvas.width > 0) {
const opacity = canvas.parentNode.style.opacity;
mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity);
const transform = canvas.style.transform;
const matrix = transform
.match(/^matrix\(([^\(]*)\)$/)[1] //eslint-disable-line
.split(',')
.map(Number);
CanvasRenderingContext2D.prototype.setTransform.apply(
mapContext,
matrix
);
mapContext.drawImage(canvas, 0, 0);
}
}
);
if (navigator.msSaveBlob) {
navigator.msSaveBlob(mapCanvas.msToBlob(), 'firework_experiment.png');
} else {
const link = document.getElementById('image-download');
link.href = mapCanvas.toDataURL();
link.click();
}
});
this.map.renderSync();
}
}
这个想法是循环我的 WMS 层的时间(只是一个循环,重新渲染地图有限次数),并在每一步保存图像window.sessionStorage
,我将从中取回它们并使用少数几个库中的任何一个从图像列表中创建 .GIF。所有这些都将在客户端完成。这看起来很老套,但在理论上对我来说是合理的,但我是 Web 开发的新手,很想知道有更好的方法来解决我的问题。我的问题是,如果没有更好的方法来做到这一点,我将如何将msSaveBlob()
函数中的图像存储到window.sessionStorage
?
解决方案
推荐阅读
- amazon-web-services - 在由 S3 触发的 AWS 中运行 ETL python 脚本
- docker - Docker 容器:在没有 root 的情况下删除缓存 - 其他选项?
- mysql - 将 SQL 查询中的值格式化为数字以将它们导出到 Excel
- python-textfsm - 为 Cisco XR 创建 Textfsm 模板 // 显示 isis 数据库
- java - 如何从 Java 中的 docx 中获取部分
- c++ - 如何在不重新创建现有文件的情况下写入 .txt 文件
- python - 如何创建多个对象以及提供外键字段的外键?
- java - JaxRs 客户端不执行 MessageBodyReader
- java - 从带有对象内容的 XML 文件创建 java 代码
- c# - 在 LUIS 中使用上下文