Fixed resizing of screen without making new requests to image-server

This commit is contained in:
Erik Tiekstra
2017-05-23 16:44:29 +02:00
parent fe0d96dd8e
commit 86f9412335
3 changed files with 54 additions and 16 deletions
+35 -4
View File
@@ -52,6 +52,40 @@ function ThreeDHandler(canvas) {
return _overlay.visible; return _overlay.visible;
}; };
this.getResizedImage = function(img) {
// Calculate maxHeight and maxWidth of the 3d image
// and scale the image accoring to those values
var maxHeight = canvas.getHeight() - 100;
var maxWidth = canvas.getWidth() - 100;
img.scaleX = img.scaleY = 1;
if (maxHeight < img.height) {
img.scaleToHeight(maxHeight);
}
if (maxWidth < (img.width * img.scaleX)) {
img.scaleToWidth(maxWidth);
}
return img;
};
this.refreshImage = function() {
_overlay.set({
width: canvas.width,
});
this.applyImage();
};
this.applyImage = function(img) {
img = img || _image;
_overlay
.remove(_image)
.add(_image = this.getResizedImage(img));
};
/** /**
* @return {ThreeDHandler} * @return {ThreeDHandler}
*/ */
@@ -61,10 +95,7 @@ function ThreeDHandler(canvas) {
originY: 'center', originY: 'center',
}); });
_overlay this.applyImage(img);
.remove(_image)
.add(_image = img);
return this.enable(); return this.enable();
}; };
+13 -5
View File
@@ -37,7 +37,11 @@ var Canvas = fabric.util.createClass(fabric.Canvas, {
this.setHeight(args.height); this.setHeight(args.height);
this.setWidth(args.width); this.setWidth(args.width);
this.getButtonMenu().render(); this.getButtonMenu().render();
if (this.get3dHandler().isEnabled()) {
this.get3dHandler().refreshImage();
} else {
this.getViewport().reset(); this.getViewport().reset();
}
this.sendToBack(this.getImage()); this.sendToBack(this.getImage());
this.getDragbars().resetPosition(); this.getDragbars().resetPosition();
this.renderAll(); this.renderAll();
@@ -53,16 +57,20 @@ var Canvas = fabric.util.createClass(fabric.Canvas, {
*/ */
get3dUrl: function () { get3dUrl: function () {
var cropData = this.getImage().transformation.getData(); var cropData = this.getImage().transformation.getData();
return this.getImage().__url.replace(/\?h=\d+$/, '?') + var params = [
[ 'h=400',
'h=313',
'mirror=' + (cropData.mirrored ? 1 : 0),
'canvas[edge]=' + cropData.edge, 'canvas[edge]=' + cropData.edge,
'crop[w]=' + cropData.width, 'crop[w]=' + cropData.width,
'crop[h]=' + cropData.height, 'crop[h]=' + cropData.height,
'crop[x]=' + cropData.x, 'crop[x]=' + cropData.x,
'crop[y]=' + cropData.y, 'crop[y]=' + cropData.y,
].join('&'); ];
if (cropData.mirrored) {
params.push('mirror=1');
}
return this.getImage().__url.replace(/\?h=\d+$/, '?') + params.join('&');
}, },
getApertures: function () { getApertures: function () {
@@ -56,7 +56,6 @@ function Viewport(canvas) {
// Apertures sometimes overlaps the viewports bounding rect. // Apertures sometimes overlaps the viewports bounding rect.
// Solve this by bringing it to the front after apertures are applied. // Solve this by bringing it to the front after apertures are applied.
_rect.bringToFront(); _rect.bringToFront();
canvas.refresh3dView();
} }
function getCroppedData() { function getCroppedData() {