Skip to content

Commit

Permalink
Print - Selected scale must not be auto. adapted
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Mar 12, 2018
1 parent 4957daf commit f8553ee
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions contribs/gmf/src/directives/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ gmf.PrintController = function($rootScope, $scope, $timeout, $q, $injector,
*/
this.pointerDragListenerKey_;

/**
* @type {ol.EventsKey}
* @private
*/
this.mapViewResolutionChangeKey_;

/**
* Current report reference id.
* @type {string}
Expand Down Expand Up @@ -364,6 +370,12 @@ gmf.PrintController = function($rootScope, $scope, $timeout, $q, $injector,
*/
this.hiddenAttributeNames;

/**
* @type {boolean}
* @private
*/
this.scaleManuallySelected_ = false;

/**
* @return {ol.Size} Size in dots of the map to print.
*/
Expand All @@ -378,8 +390,8 @@ gmf.PrintController = function($rootScope, $scope, $timeout, $q, $injector,
// the pre-defined scales. (`scaleInput` in `gmfPrintOptions`).
goog.asserts.assert(this.layoutInfo.scales);
goog.asserts.assert(this.layoutInfo.scale !== undefined);
if (this.layoutInfo.scale === -1 ||
ol.array.includes(this.layoutInfo.scales, this.layoutInfo.scale)) {
if (!this.scaleManuallySelected_ &&
(this.layoutInfo.scale === -1 || ol.array.includes(this.layoutInfo.scales, this.layoutInfo.scale))) {
const mapSize = frameState.size;
const viewResolution = frameState.viewState.resolution;
this.layoutInfo.scale = this.getOptimalScale_(mapSize, viewResolution);
Expand Down Expand Up @@ -468,6 +480,9 @@ gmf.PrintController.prototype.togglePrintPanel_ = function(active) {
this.postcomposeListener_);
this.pointerDragListenerKey_ = this.map.on('pointerdrag',
this.onPointerDrag_.bind(this));
this.mapViewResolutionChangeKey_ = this.map.getView().on('change:resolution', () => {
this.scaleManuallySelected_ = false;
});
this.map.render();
}, (resp) => {
// Get capabilities - On error
Expand All @@ -477,6 +492,7 @@ gmf.PrintController.prototype.togglePrintPanel_ = function(active) {
} else {
ol.Observable.unByKey(this.postComposeListenerKey_);
ol.Observable.unByKey(this.pointerDragListenerKey_);
ol.Observable.unByKey(this.mapViewResolutionChangeKey_);
this.getSetRotation(0);
this.map.render(); // Redraw (remove) post compose mask;
}
Expand Down Expand Up @@ -735,15 +751,15 @@ gmf.PrintController.prototype.print = function(format) {

const mapSize = this.map.getSize();
const viewResolution = this.map.getView().getResolution();
const scale = this.getOptimalScale_(mapSize, viewResolution);
const scale = this.layoutInfo.scale || this.getOptimalScale_(mapSize, viewResolution);
const rotation = this.rotateMask_ ? -this.rotation : this.rotation;
const datasource = this.getDataSource_();

const customAttributes = {
'datasource': datasource,
'lang': this.gettextCatalog_.currentLanguage,
'rotation': rotation,
'scale': this.layoutInfo.scale
'scale': scale
};

if (this.layoutInfo.simpleAttributes) {
Expand Down Expand Up @@ -1099,6 +1115,7 @@ gmf.PrintController.prototype.getSetScale = function(opt_scale) {
const res = this.ngeoPrintUtils_.getOptimalResolution(mapSize, this.paperSize_, opt_scale);
const contrainRes = this.map.getView().constrainResolution(res, 0, 1);
this.map.getView().setResolution(contrainRes);
this.scaleManuallySelected_ = true;
}
return this.layoutInfo.scale;
};
Expand All @@ -1125,4 +1142,4 @@ gmf.PrintController.prototype.isState = function(stateEnumKey) {
return this.gmfPrintState_.state === gmf.PrintStateEnum[stateEnumKey];
};

gmf.module.controller('GmfPrintController', gmf.PrintController);
mf.module.controller('GmfPrintController', gmf.PrintController);

0 comments on commit f8553ee

Please sign in to comment.