From 759ec7845b59b64530b3a92000eb78425f06183b Mon Sep 17 00:00:00 2001 From: Robert Best Date: Sat, 22 Oct 2016 05:50:31 +0000 Subject: [PATCH] cleaned up the window resize function even further --- frontend/src/Metamaps/Listeners.js | 13 ++----------- frontend/src/Metamaps/Util.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/frontend/src/Metamaps/Listeners.js b/frontend/src/Metamaps/Listeners.js index 49678aac..dbebd8ab 100644 --- a/frontend/src/Metamaps/Listeners.js +++ b/frontend/src/Metamaps/Listeners.js @@ -110,17 +110,8 @@ const Listeners = { $(window).resize(function () { if (Visualize && Visualize.mGraph) { - // Store the current canvas attributes, i.e. scale and map-coordinate at the centre of the user's screen - let canvas = Visualize.mGraph.canvas; - const oldAttr = Util.logCanvasAttributes(canvas); - - // Resize the canvas to fill the new window size. Based on how JIT works, this also resets the map back to scale 1 and tranlations = 0 - canvas.resize($(window).width(), $(window).height()) - - // Return the map to the original scale, and then put the previous central map-coordinate back to the centre of user's newly resized screen - canvas.scale(oldAttr.scaleX, oldAttr.scaleY) - const newAttr = Util.logCanvasAttributes(canvas); - canvas.translate(newAttr.centreCoords.x - oldAttr.centreCoords.x, newAttr.centreCoords.y - oldAttr.centreCoords.y) + Util.resizeCanvas(Visualize.mGraph.canvas) + } if (Active.Map && Realtime.inConversation) Realtime.positionVideos() diff --git a/frontend/src/Metamaps/Util.js b/frontend/src/Metamaps/Util.js index d2ac9cd0..445a898c 100644 --- a/frontend/src/Metamaps/Util.js +++ b/frontend/src/Metamaps/Util.js @@ -1,3 +1,5 @@ +/* global $ */ + import { Parser, HtmlRenderer } from 'commonmark' import Visualize from './Visualize' @@ -133,6 +135,18 @@ const Util = { scaleY: canvas.scaleOffsetY, centreCoords: Util.pixelsToCoords({ x: canvas.canvases[0].size.width / 2, y: canvas.canvases[0].size.height / 2 }), }; + }, + resizeCanvas: function(canvas){ + // Store the current canvas attributes, i.e. scale and map-coordinate at the centre of the user's screen + const oldAttr = Util.logCanvasAttributes(canvas); + + // Resize the canvas to fill the new window size. Based on how JIT works, this also resets the map back to scale 1 and tranlations = 0 + canvas.resize($(window).width(), $(window).height()) + + // Return the map to the original scale, and then put the previous central map-coordinate back to the centre of user's newly resized screen + canvas.scale(oldAttr.scaleX, oldAttr.scaleY) + const newAttr = Util.logCanvasAttributes(canvas); + canvas.translate(newAttr.centreCoords.x - oldAttr.centreCoords.x, newAttr.centreCoords.y - oldAttr.centreCoords.y) } }