使用预合成剪切图层时,Openlayers旋转中断

时间:2017-10-20 13:50:37

标签: openlayers-3

将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();
}

1 个答案:

答案 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