From c3cca3a865890ec7c7e3f6efaecbf879ce8cf97d Mon Sep 17 00:00:00 2001 From: Rolander Date: Fri, 22 Dec 2023 15:35:14 +0100 Subject: [PATCH] Correct print scales with constrainResolution true Correct print scales are now retained even when the ConstrainResolution option is true. ConstrainResolution gets temporarily set to false when using the print component and is restored once the print component is closed. --- src/controls/print/print-component.js | 3 ++- src/controls/print/print-resize.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/controls/print/print-component.js b/src/controls/print/print-component.js index c4d256f1c..54a3d6779 100644 --- a/src/controls/print/print-component.js +++ b/src/controls/print/print-component.js @@ -271,7 +271,8 @@ const PrintComponent = function PrintComponent(options = {}) { titleComponent, descriptionComponent, createdComponent, - closeButton + closeButton, + constrainResolution: view.getConstrainResolution() }); const setScale = function setScale(scale) { diff --git a/src/controls/print/print-resize.js b/src/controls/print/print-resize.js index 46eea5490..fed76174e 100644 --- a/src/controls/print/print-resize.js +++ b/src/controls/print/print-resize.js @@ -19,7 +19,8 @@ export default function PrintResize(options = {}) { titleComponent, descriptionComponent, createdComponent, - closeButton + closeButton, + constrainResolution } = options; let { @@ -404,6 +405,8 @@ export default function PrintResize(options = {}) { // Alters layer in map, if vector then set scale for feature, if image set DPI parameter for source const setLayerScale = function setLayerScale(layer) { const source = layer.getSource(); + const view = map.getView(); + view.setConstrainResolution(false); if (isVector(layer)) { const styleName = layer.get('styleName'); @@ -467,6 +470,8 @@ export default function PrintResize(options = {}) { // "Resets" layer by resetting the style and removing DPI parameter const resetLayerScale = function resetLayerScale(layer) { const source = layer.getSource(); + const view = map.getView(); + view.setConstrainResolution(constrainResolution); if (isVector(layer)) { const features = source.getFeatures(); const styleName = layer.get('styleName');