Skip to content

Commit

Permalink
Merge pull request #3649 from camptocamp/selected_scale_must_not_change
Browse files Browse the repository at this point in the history
Print - Selected scale must not be auto. adapted
  • Loading branch information
ger-benjamin committed Mar 12, 2018
2 parents 4957daf + 484e609 commit 5ad6ec9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 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 Down

0 comments on commit 5ad6ec9

Please sign in to comment.