mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 16:19:48 +02:00
utilSetDimensions/utilGetDimensions improvements
utilSetDimensions should always return a selection for chaining Add `force` argument to utilGetDimensions to override cached dimensions
This commit is contained in:
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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]])
|
||||
|
||||
Reference in New Issue
Block a user