Skip to content

Commit

Permalink
Correct print scales with constrainResolution true (#1938)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sweco-seguro authored Jan 30, 2024
1 parent 648e569 commit 34d4b03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/controls/print/print-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ const PrintComponent = function PrintComponent(options = {}) {
titleComponent,
descriptionComponent,
createdComponent,
closeButton
closeButton,
constrainResolution: view.getConstrainResolution()
});

const setScale = function setScale(scale) {
Expand Down
7 changes: 6 additions & 1 deletion src/controls/print/print-resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function PrintResize(options = {}) {
titleComponent,
descriptionComponent,
createdComponent,
closeButton
closeButton,
constrainResolution
} = options;

let {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 34d4b03

Please sign in to comment.