Minimize canvas size for rotated views

This commit is contained in:
Andreas Hocevar
2022-07-08 17:47:49 +02:00
parent 22dba410ad
commit 6ffbfa1a4a
2 changed files with 17 additions and 20 deletions

View File

@@ -168,18 +168,17 @@ class CanvasImageLayerRenderer extends CanvasLayerRenderer {
const viewState = frameState.viewState;
const viewCenter = viewState.center;
const viewResolution = viewState.resolution;
const size = frameState.size;
const scale =
(pixelRatio * imageResolution) / (viewResolution * imagePixelRatio);
let width = Math.round(size[0] * pixelRatio);
let height = Math.round(size[1] * pixelRatio);
const extent = frameState.extent;
const resolution = viewState.resolution;
const rotation = viewState.rotation;
if (rotation) {
const size = Math.round(Math.sqrt(width * width + height * height));
width = size;
height = size;
}
// desired dimensions of the canvas in pixels
const width = Math.round((getWidth(extent) / resolution) * imagePixelRatio);
const height = Math.round(
(getHeight(extent) / resolution) * imagePixelRatio
);
// set forward and inverse pixel transforms
composeTransform(

View File

@@ -18,8 +18,10 @@ import {
containsCoordinate,
createEmpty,
equals,
getHeight,
getIntersection,
getTopLeft,
getWidth,
intersects,
} from '../../extent.js';
import {cssOpacity} from '../../css.js';
@@ -263,6 +265,14 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
const tileResolution = tileGrid.getResolution(z);
let extent = frameState.extent;
const resolution = frameState.viewState.resolution;
const tilePixelRatio = tileSource.getTilePixelRatio(pixelRatio);
// desired dimensions of the canvas in pixels
const width = Math.round((getWidth(extent) / resolution) * tilePixelRatio);
const height = Math.round(
(getHeight(extent) / resolution) * tilePixelRatio
);
const layerExtent =
layerState.extent && fromUserExtent(layerState.extent, projection);
if (layerExtent) {
@@ -272,18 +282,6 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
);
}
const tilePixelRatio = tileSource.getTilePixelRatio(pixelRatio);
// desired dimensions of the canvas in pixels
let width = Math.round(frameState.size[0] * tilePixelRatio);
let height = Math.round(frameState.size[1] * tilePixelRatio);
if (rotation) {
const size = Math.round(Math.sqrt(width * width + height * height));
width = size;
height = size;
}
const dx = (tileResolution * width) / 2 / tilePixelRatio;
const dy = (tileResolution * height) / 2 / tilePixelRatio;
const canvasExtent = [