Commit d18d1651 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

allow to select image size on export

parent 6db7ee2b
Pipeline #51983 passed with stage
in 16 minutes and 19 seconds
minerva (16.1.0~alpha.0) stable; urgency=medium
* Improvement: possibility to register map in minerva-net (#1595)
* Small improvement: export to image allows to define size of the image (#955)
* Small improvement: AVOGADRO unit type from SBML is parsed properly (#1612)
* Small improvement: data overlays have automatically generated legend (#205,
#1061)
......
......@@ -2386,6 +2386,18 @@ ServerConnector.getOverlaySourceDownloadUrl = function (params) {
});
};
/**
*
* @param {string} [params.projectId]
* @param {number} params.modelId
* @param {string} [params.token]
* @param {string} [params.polygonString]
* @param {string} params.handlerClass
* @param {number} params.backgroundOverlayId
* @param {number} [params.zoomLevel]
* @param {Array<number>>} [params.overlayIds]
* @return {PromiseLike<*>}
*/
ServerConnector.getImageDownloadUrl = function (params) {
var self = this;
var queryParams = {
......
......@@ -38,13 +38,78 @@ GraphicsExportPanel.prototype.init = function () {
var element = self.getElement();
var configuration;
element.appendChild(self._createSelectProjectDiv());
element.appendChild(self._createSelectResolutionDiv());
return ServerConnector.getConfiguration().then(function (result) {
configuration = result;
element.appendChild(self._createSelectGraphicsFormatDiv(configuration.getImageConverters()));
element.appendChild(self._createDownloadButton());
}).then(function () {
$(window).trigger('resize');
var model = self.getModels()[0];
var width = model.getWidth();
var height = model.getHeight();
if (width > height) {
self.recalculateRatio({width: 256});
} else {
self.recalculateRatio({height: 256});
}
$('.minerva-image-width', self.getElement()).keyup(function () {
if (/\D/g.test(this.value)) {
this.value = this.value.replace(/\D/g, '');
}
if (this.value === '') {
this.value = '1';
}
self.recalculateRatio({width: this.value});
});
$('.minerva-image-height', self.getElement()).keyup(function () {
if (/\D/g.test(this.value)) {
this.value = this.value.replace(/\D/g, '');
}
if (this.value === '') {
this.value = '1';
}
self.recalculateRatio({height: this.value});
});
});
};
/**
* @param {string|number} [param.width]
* @param {string|number} [param.height]
* @param param
*/
GraphicsExportPanel.prototype.recalculateRatio = function (param) {
var self = this;
var model = self.getSelectedSubmap();
if (model === null) {
logger.warn("Cannot find model with id: " + id);
return;
}
var ratio = model.getWidth() / model.getHeight();
var width = param.width;
var height = param.height;
if (width !== undefined) {
width = parseInt(width);
height = Math.floor(width / ratio);
} else {
height = parseInt(height);
width = Math.floor(height * ratio);
}
$('.minerva-image-height', self.getElement()).val(height);
$('.minerva-image-width', self.getElement()).val(width);
};
/**
......@@ -89,6 +154,45 @@ GraphicsExportPanel.prototype._createSelectProjectDiv = function () {
return typeDiv;
};
/**
*
* @returns {HTMLElement}
* @private
*/
GraphicsExportPanel.prototype._createSelectResolutionDiv = function () {
var self = this;
var typeDiv = Functions.createElement({
type: "div",
name: "ratioSelectDiv"
});
typeDiv.appendChild(Functions.createElement({
type: "h4",
content: "Image size:"
}));
var widthContainer = Functions.createElement({type: "div"});
widthContainer.appendChild(Functions.createElement({type: "label", content: "Width: "}));
widthContainer.appendChild(Functions.createElement({
type: "input",
className: "minerva-image-width",
value: ""
}));
typeDiv.appendChild(widthContainer);
var heightContainer = Functions.createElement({type: "div"});
heightContainer.appendChild(Functions.createElement({type: "label", content: "Height: "}));
heightContainer.appendChild(Functions.createElement({
type: "input",
className: "minerva-image-height",
value: ""
}));
typeDiv.appendChild(heightContainer);
return typeDiv;
};
/**
*
* @param {ImageConverter[]} formats
......@@ -143,6 +247,22 @@ GraphicsExportPanel.prototype.getSubmapId = function () {
return id;
};
/**
*
* @return {null|MapModel}
*/
GraphicsExportPanel.prototype.getSelectedSubmap = function () {
var self = this;
var id = self.getSubmapId();
var model = null;
for (var i = 0; i < self.getModels().length; i++) {
if (self.getModels()[i].getId() === parseInt(id)) {
model = self.getModels()[i];
}
}
return model;
};
/**
*
* @returns {string}
......@@ -176,17 +296,20 @@ GraphicsExportPanel.prototype._createDownloadButton = function () {
onclick: function () {
var identifier = null;
var defaultOverlayName = "Network";
for (var i = 0; i < self.getProject().getDataOverlays().length; i++) {
var overlay = self.getProject().getDataOverlays()[i];
if (identifier === null || overlay.getName() === defaultOverlayName) {
identifier = overlay.getId();
for (var i = 0; i < self.getProject().getBackgrounds().length; i++) {
var background = self.getProject().getBackgrounds()[i];
if (identifier === null || background.getName() === defaultOverlayName) {
identifier = background.getId();
}
}
var ratio = Math.log2(parseInt($('.minerva-image-width', self.getElement()).val()) / 256) + 2;
return ServerConnector.getImageDownloadUrl({
modelId: self.getSubmapId(),
backgroundOverlayId: identifier,
handlerClass: self.getFormatHandler()
handlerClass: self.getFormatHandler(),
zoomLevel: ratio
}).then(function (url) {
return self.downloadFile(url);
}).then(null, GuiConnector.alert);
......@@ -197,4 +320,8 @@ GraphicsExportPanel.prototype._createDownloadButton = function () {
return downloadDiv;
};
if (!Math.log2) Math.log2 = function(x) {
return Math.log(x) * Math.LOG2E;
};
module.exports = GraphicsExportPanel;
......@@ -255,7 +255,7 @@ public class ModelController extends BaseController {
final @RequestParam(value = "handlerClass") String handlerClass,
final @RequestParam(value = "backgroundOverlayId", required = false) Integer backgroundOverlayId,
final @RequestParam(value = "overlayIds", defaultValue = "") String overlayIds,
final @RequestParam(value = "zoomLevel", required = false) Integer zoomLevel,
final @RequestParam(value = "zoomLevel", required = false) Double zoomLevel,
final @RequestParam(value = "polygonString", defaultValue = "") String polygonString)
throws QueryException, IOException, InvalidDataOverlayException, CommandExecutionException, DrawingException {
User user = userService.getUserByLogin(authentication.getName());
......@@ -290,7 +290,7 @@ public class ModelController extends BaseController {
}
}
int level = Configuration.MIN_ZOOM_LEVEL;
double level = Configuration.MIN_ZOOM_LEVEL;
if (zoomLevel != null) {
level = zoomLevel;
}
......@@ -317,12 +317,10 @@ public class ModelController extends BaseController {
double scale = Math.max(originalModel.getHeight(), originalModel.getWidth())
/ (originalModel.getTileSize());
for (int i = level; i > Configuration.MIN_ZOOM_LEVEL; i--) {
scale /= 2;
}
scale /= Math.pow(2, level - Configuration.MIN_ZOOM_LEVEL);
Params params = new Params().x(minX).y(minY).height((maxY - minY) / scale).width((maxX - minX) / scale)
.level(level - Configuration.MIN_ZOOM_LEVEL)
.level((int) level - Configuration.MIN_ZOOM_LEVEL)
// automatically set nested view as disabled
.nested(false).scale(scale).colorExtractor(colorExtractor).sbgn(sbgn).model(part);
if (background != null) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment