使用图像静态使用openlayers canvas源
我一直在尝试使用OpenLayers(v6.1.1)来绘制画布,但不幸的是,我正在努力实施画布。
我已经尝试了这种简单的方法:
const extent = [0, 0, 1024, 968];
const projection = new ol.proj.Projection({
code: 'pixel-projection',
units: 'pixels',
extent: extent,
});
let canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 968;
let ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);
const imageLayer = new ol.layer.Image({
source: new ol.source.ImageCanvas({
canvas: canvas,
projection: projection,
imageExtent: extent,
}),
});
但是我遇到了一个未定义的错误:
https://jsfiddle.net/loque/urque/ur5gw270/4/感谢,谢谢。
I've been trying to draw on the Canvas using OpenLayers (v6.1.1) but unfortunately, I'm struggling with the Canvas implementation.
I've tried this simple approach:
const extent = [0, 0, 1024, 968];
const projection = new ol.proj.Projection({
code: 'pixel-projection',
units: 'pixels',
extent: extent,
});
let canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 968;
let ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);
const imageLayer = new ol.layer.Image({
source: new ol.source.ImageCanvas({
canvas: canvas,
projection: projection,
imageExtent: extent,
}),
});
but I'm getting an undefined error:
Also, here is a fiddle for easier navigation:
https://jsfiddle.net/Loque/ur5gw270/4/
Any help would be highly appreciated, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
imagecanvas
需要canvasFunction
选项:Imagestatic
需要url
选项:ImageCanvas
needs acanvasFunction
option:ImageStatic
needs aurl
option: