Fixed resizing of screen without making new requests to image-server
This commit is contained in:
@@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
this.getViewport().reset();
|
if (this.get3dHandler().isEnabled()) {
|
||||||
|
this.get3dHandler().refreshImage();
|
||||||
|
} else {
|
||||||
|
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',
|
'canvas[edge]=' + cropData.edge,
|
||||||
'mirror=' + (cropData.mirrored ? 1 : 0),
|
'crop[w]=' + cropData.width,
|
||||||
'canvas[edge]=' + cropData.edge,
|
'crop[h]=' + cropData.height,
|
||||||
'crop[w]=' + cropData.width,
|
'crop[x]=' + cropData.x,
|
||||||
'crop[h]=' + cropData.height,
|
'crop[y]=' + cropData.y,
|
||||||
'crop[x]=' + cropData.x,
|
];
|
||||||
'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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user