Shrink the photo viewer if the map has been resized to be smaller

This commit is contained in:
Bryan Housel
2018-07-17 17:47:05 -04:00
parent e221dcae58
commit 7737c571aa
+33 -18
View File
@@ -283,6 +283,9 @@ export function uiInit(context) {
buildResizeListener(photoviewer, 'photoviewerResize', dispatch, { resizeOnY: true })
);
var mapDimensions = map.dimensions();
// bind events
window.onbeforeunload = function() {
return context.save();
};
@@ -291,30 +294,13 @@ export function uiInit(context) {
context.history().unlock();
};
var mapDimensions = map.dimensions();
function onResize() {
mapDimensions = utilGetDimensions(content, true);
map.dimensions(mapDimensions);
}
d3_select(window)
.on('resize.editor', onResize);
onResize();
function pan(d) {
return function() {
d3_event.preventDefault();
context.pan(d, 100);
};
}
// pan amount
var pa = 80;
var pa = 80; // pan amount
var keybinding = d3_keybinding('main')
.on('⌫', function() { d3_event.preventDefault(); })
.on('←', pan([pa, 0]))
@@ -364,6 +350,35 @@ export function uiInit(context) {
}
function onResize() {
mapDimensions = utilGetDimensions(content, true);
map.dimensions(mapDimensions);
// shrink photo viewer if it is too big
// (-90 preserves space at top and bottom of map used by menus)
var photoDimensions = utilGetDimensions(photoviewer, true);
if (photoDimensions[0] > mapDimensions[0] || photoDimensions[1] > (mapDimensions[1] - 90)) {
var setPhotoDimensions = [
Math.min(photoDimensions[0], mapDimensions[0]),
Math.min(photoDimensions[1], mapDimensions[1] - 90),
];
photoviewer
.style('width', setPhotoDimensions[0] + 'px')
.style('height', setPhotoDimensions[1] + 'px');
dispatch.call('photoviewerResize', photoviewer, setPhotoDimensions);
}
}
function pan(d) {
return function() {
d3_event.preventDefault();
context.pan(d, 100);
};
}
function buildResizeListener(target, eventName, dispatch, options) {
var resizeOnX = !!options.resizeOnX;
var resizeOnY = !!options.resizeOnY;