将Openlayers更新为> 4.0时,使用precompose
挂钩时地图旋转完全中断:
function precompose(event) {
var context = event.context;
context.beginPath();
context.moveTo(0, 0);
context.lineTo(100, 0);
context.lineTo(100, 100);
context.lineTo(0, 100);
context.lineTo(0, 0);
context.closePath();
context.fillStyle = "rgba(0, 5, 25, 0.75)";
context.fill();
}
答案 0 :(得分:1)
保存画布上下文非常重要,有关详细信息,请参阅MDN CanvasRenderingContext2d
function precompose(event) {
var context = event.context;
context.save(); // be sure to save the context before anything is done
// ...
}
另外,在context.restore()
挂钩中使用postcompose
。