Skip to content

Commit

Permalink
fix(ui): Fix map canvas size
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Mar 15, 2021
1 parent 25eac7c commit 3c05e2d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client/js/js-modules/vacuum-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,15 @@ export function VacuumMap(canvasElement) {
size.y = mapData.size.y;
size.pixelSize = mapData.pixelSize;

if (mapData.size.x !== mapDrawer.canvas.width) {
mapDrawer.canvas.width = mapData.size.x;
let pixelX = Math.round(size.x / size.pixelSize);
let pixelY = Math.round(size.y / size.pixelSize);

if (pixelX !== mapDrawer.canvas.width) {
mapDrawer.canvas.width = pixelX;
}

if (mapData.size.y !== mapDrawer.canvas.height) {
mapDrawer.canvas.height = mapData.size.y;
if (pixelY !== mapDrawer.canvas.height) {
mapDrawer.canvas.height = pixelY;
}

mapDrawer.draw(mapData.layers);
Expand Down Expand Up @@ -344,6 +347,17 @@ export function VacuumMap(canvasElement) {
size.y = data.size.y;
size.pixelSize = data.pixelSize;

let pixelX = Math.round(size.x / size.pixelSize);
let pixelY = Math.round(size.y / size.pixelSize);

if (pixelX !== mapDrawer.canvas.width) {
mapDrawer.canvas.width = pixelX;
}

if (pixelY !== mapDrawer.canvas.height) {
mapDrawer.canvas.height = pixelY;
}

window.addEventListener("resize", () => {
// Save the current transformation and recreate it
// as the transformation state is lost when changing canvas size
Expand Down

0 comments on commit 3c05e2d

Please sign in to comment.