我正在尝试将运行 webgearth ( http://www.webgearth.org/ ) 的画布的输出复制到标准的 2d 画布。我按照这个问题的答案,但我只能看到画布的背景颜色。
我的代码是:
<html>
<body>
<div id="earthDiv" style="background-color:rgba(255,0,255,0.5); width:500px; height: 500px;"></div>
<canvas id="canvas" style="background-color:rgba(0,255,0,0.5); width:500px; height: 500px;"></canvas>
<script src="http://www.webglearth.com/v2/api.js"></script>
<script type="text/javascript">
window.onload = function () {
var earth = new WE.map("earthDiv");
var earthCanvas = earth.canvas;
var earthContext = earthCanvas.getContext("webgl", {
preserveDrawingBuffer: true,
});
WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {}).addTo(earth);
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
setInterval(function () {
context.drawImage(earthContext.canvas, 0, 0);
}, 1000);
};
</script>
</body>
</html>