diff --git a/frontend/src/Metamaps/Util.js b/frontend/src/Metamaps/Util.js index 4b55342a..9dfc8d3b 100644 --- a/frontend/src/Metamaps/Util.js +++ b/frontend/src/Metamaps/Util.js @@ -237,10 +237,10 @@ const Util = { return obj }, {}) }, - updateQueryParams: function(newValues) { + updateQueryParams: function(newValues, pathname = window.location.pathname) { const qp = Object.assign({}, Util.queryParams(), newValues) const newString = Object.keys(qp).filter(key => !!key).map(key => `${key}=${qp[key]}`).join('&') - history.replaceState({}, document.title, `${window.location.pathname}?${newString}`) + history.replaceState({}, document.title, `${pathname}?${newString}`) } } diff --git a/frontend/src/Metamaps/Visualize.js b/frontend/src/Metamaps/Visualize.js index bacf7f03..ea337ba2 100644 --- a/frontend/src/Metamaps/Visualize.js +++ b/frontend/src/Metamaps/Visualize.js @@ -1,4 +1,4 @@ -/* global $ */ +/* global $, window */ import { find as _find, indexOf as _indexOf, uniq as _uniq, debounce } from 'lodash' @@ -151,8 +151,9 @@ const Visualize = { // monkey patch scale function const oldScale = self.mGraph.canvas.scale + const cachedPathname = window.location.pathname const updateScaleInUrl = debounce(() => { - Util.updateQueryParams({ scale: self.mGraph.canvas.scaleOffsetX.toFixed(2) }) + Util.updateQueryParams({ scale: self.mGraph.canvas.scaleOffsetX.toFixed(2) }, pathname) }, 200) self.mGraph.canvas.scale = function(x, y, disablePlot) { const returnValue = oldScale.apply(self.mGraph.canvas, arguments) @@ -165,7 +166,7 @@ const Visualize = { const updateTranslateInUrl = debounce(() => { const newX = self.mGraph.canvas.translateOffsetX.toFixed(2) const newY = self.mGraph.canvas.translateOffsetY.toFixed(2) - Util.updateQueryParams({ translate: `${newX},${newY}` }) + Util.updateQueryParams({ translate: `${newX},${newY}` }, pathname) }, 200) self.mGraph.canvas.translate = function(x, y, disablePlot) { const returnValue = oldTranslate.apply(self.mGraph.canvas, arguments)