diff --git a/src/ol/renderer/canvas/Layer.js b/src/ol/renderer/canvas/Layer.js index 182ed8c653..8677cde559 100644 --- a/src/ol/renderer/canvas/Layer.js +++ b/src/ol/renderer/canvas/Layer.js @@ -45,8 +45,8 @@ class CanvasLayerRenderer extends LayerRenderer { */ clip(context, frameState, extent) { const pixelRatio = frameState.pixelRatio; - const width = frameState.size[0] * pixelRatio; - const height = frameState.size[1] * pixelRatio; + const halfWidth = (frameState.size[0] * pixelRatio) / 2; + const halfHeight = (frameState.size[1] * pixelRatio) / 2; const rotation = frameState.viewState.rotation; const topLeft = getTopLeft(extent); const topRight = getTopRight(extent); @@ -59,14 +59,14 @@ class CanvasLayerRenderer extends LayerRenderer { applyTransform(frameState.coordinateToPixelTransform, bottomLeft); context.save(); - rotateAtOffset(context, -rotation, width / 2, height / 2); + rotateAtOffset(context, -rotation, halfWidth, halfHeight); context.beginPath(); context.moveTo(topLeft[0] * pixelRatio, topLeft[1] * pixelRatio); context.lineTo(topRight[0] * pixelRatio, topRight[1] * pixelRatio); context.lineTo(bottomRight[0] * pixelRatio, bottomRight[1] * pixelRatio); context.lineTo(bottomLeft[0] * pixelRatio, bottomLeft[1] * pixelRatio); context.clip(); - rotateAtOffset(context, rotation, width / 2, height / 2); + rotateAtOffset(context, rotation, halfWidth, halfHeight); } /** @@ -79,10 +79,10 @@ class CanvasLayerRenderer extends LayerRenderer { dispatchComposeEvent_(type, context, frameState, opt_transform) { const layer = this.getLayer(); if (layer.hasListener(type)) { - const width = frameState.size[0] * frameState.pixelRatio; - const height = frameState.size[1] * frameState.pixelRatio; + const halfWidth = (frameState.size[0] * frameState.pixelRatio) / 2; + const halfHeight = (frameState.size[1] * frameState.pixelRatio) / 2; const rotation = frameState.viewState.rotation; - rotateAtOffset(context, -rotation, width / 2, height / 2); + rotateAtOffset(context, -rotation, halfWidth, halfHeight); const transform = opt_transform !== undefined ? opt_transform : this.getTransform(frameState, 0); const render = new CanvasImmediateRenderer( @@ -91,7 +91,7 @@ class CanvasLayerRenderer extends LayerRenderer { const composeEvent = new RenderEvent(type, render, frameState, context, null); layer.dispatchEvent(composeEvent); - rotateAtOffset(context, rotation, width / 2, height / 2); + rotateAtOffset(context, rotation, halfWidth, halfHeight); } } diff --git a/src/ol/renderer/canvas/VectorLayer.js b/src/ol/renderer/canvas/VectorLayer.js index e845c8ba74..98a421c606 100644 --- a/src/ol/renderer/canvas/VectorLayer.js +++ b/src/ol/renderer/canvas/VectorLayer.js @@ -161,10 +161,9 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer { const viewHints = frameState.viewHints; const snapToPixel = !(viewHints[ViewHint.ANIMATING] || viewHints[ViewHint.INTERACTING]); - const width = frameState.size[0] * pixelRatio; - const height = frameState.size[1] * pixelRatio; - rotateAtOffset(replayContext, -rotation, - width / 2, height / 2); + const halfWidth = (frameState.size[0] * pixelRatio) / 2; + const halfHeight = (frameState.size[1] * pixelRatio) / 2; + rotateAtOffset(replayContext, -rotation, halfWidth, halfHeight); replayGroup.replay(replayContext, transform, rotation, skippedFeatureUids, snapToPixel); if (vectorSource.getWrapX() && projection.canWrapX() && !containsExtent(projectionExtent, extent)) { @@ -189,8 +188,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer { startX -= worldWidth; } } - rotateAtOffset(replayContext, rotation, - width / 2, height / 2); + rotateAtOffset(replayContext, rotation, halfWidth, halfHeight); if (hasRenderListeners) { this.dispatchRenderEvent(replayContext, frameState, transform);