diff --git a/modules/ui/init.js b/modules/ui/init.js index 2dab1a569..801e0c461 100644 --- a/modules/ui/init.js +++ b/modules/ui/init.js @@ -6,7 +6,7 @@ import { tooltip } from '../util/tooltip'; import { svgDefs, svgIcon } from '../svg/index'; import { modeBrowse } from '../modes/index'; import { behaviorHash } from '../behavior/index'; -import { utilSetDimensions } from '../util/dimensions'; +import { utilGetDimensions } from '../util/dimensions'; import { uiAccount } from './account'; import { uiAttribution } from './attribution'; @@ -229,7 +229,7 @@ export function uiInit(context) { var mapDimensions = map.dimensions(); function onResize() { - mapDimensions = utilSetDimensions(content, null); + mapDimensions = utilGetDimensions(content, true); map.dimensions(mapDimensions); } diff --git a/modules/util/dimensions.js b/modules/util/dimensions.js index 34aa656e1..bf835ff59 100644 --- a/modules/util/dimensions.js +++ b/modules/util/dimensions.js @@ -5,23 +5,24 @@ function refresh(selection, node) { return prop; } - -export function utilGetDimensions(selection) { +export function utilGetDimensions(selection, force) { if (!selection || selection.empty()) { return [0, 0]; } - var node = selection.node(); - return selection.property('__dimensions__') || refresh(selection, node); + var node = selection.node(), + cached = selection.property('__dimensions__'); + return (!cached || force) ? refresh(selection, node) : cached; } export function utilSetDimensions(selection, dimensions) { if (!selection || selection.empty()) { - return [0, 0]; + return selection; } var node = selection.node(); if (dimensions === null) { - return refresh(selection, node); + refresh(selection, node); + return selection; } return selection .property('__dimensions__', [dimensions[0], dimensions[1]])