Skip to content

Commit

Permalink
Merge pull request #1124 from geoadmin/fix-PB-1140-minimal-scale-for-…
Browse files Browse the repository at this point in the history
…printing

PB-1140: add a minimal scale for print specs
  • Loading branch information
ltkum authored Nov 19, 2024
2 parents df85181 + 85fb272 commit e9eebf6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/api/__tests__/print.api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai'
import { describe, it } from 'vitest'

import { PrintLayout, PrintLayoutAttribute } from '@/api/print.api.js'
import { PRINT_DPI_COMPENSATION } from '@/config/print.config'
import { MIN_PRINT_SCALE_SIZE, PRINT_DPI_COMPENSATION } from '@/config/print.config'
import { adjustWidth } from '@/utils/styleUtils'

describe('Print API unit tests', () => {
Expand Down Expand Up @@ -79,6 +79,11 @@ describe('Print API unit tests', () => {
(100 * PRINT_DPI_COMPENSATION) / 254,
1 / 254
)
// we check that the minimum print scale size is correctly enforced
expect(adjustWidth(MIN_PRINT_SCALE_SIZE / 1000, 254)).to.be.closeTo(
MIN_PRINT_SCALE_SIZE,
MIN_PRINT_SCALE_SIZE / 2
)
})
})
})
1 change: 0 additions & 1 deletion src/api/print.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { adjustWidth } from '@/utils/styleUtils'

const PRINTING_DEFAULT_POLL_INTERVAL = 2000 // interval between each polling of the printing job status (ms)
const PRINTING_DEFAULT_POLL_TIMEOUT = 600000 // ms (10 minutes)

const SERVICE_PRINT_URL = `${getViewerDedicatedServicesBaseUrl()}print3/print/mapviewer`
const MAX_PRINT_SPEC_SIZE = 1 * 1024 * 1024 // 1MB in bytes (should be in sync with the backend)

Expand Down
4 changes: 4 additions & 0 deletions src/config/print.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// In the old mapviewer, a magic number (90) was set to make some compensation between the print and the viewer,
// to keep the scale between the two services. In the current implementation, 144 seems to be giving the best results.
export const PRINT_DPI_COMPENSATION = 144

// when the scale is too low, the print backend can't read the exponent.
//So when there is a non 0 scale, we set its minimum to 0.0001
export const MIN_PRINT_SCALE_SIZE = 0.0001
6 changes: 3 additions & 3 deletions src/utils/styleUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Circle, Fill, Stroke, Style } from 'ol/style'
import CircleStyle from 'ol/style/Circle.js'

import { PRINT_DPI_COMPENSATION } from '@/config/print.config'
import { MIN_PRINT_SCALE_SIZE, PRINT_DPI_COMPENSATION } from '@/config/print.config'
import variables from '@/scss/variables-admin.module.scss'

const { red, mocassin, mocassinToRed1, mocassinToRed2, malibu, black, white } = variables
Expand Down Expand Up @@ -159,9 +159,9 @@ export const highlightPointStyle = new Style({
// Change a width according to the change of DPI (from the old geoadmin)
// Originally introduced here https://github.com/geoadmin/mf-geoadmin3/pull/3280
export function adjustWidth(width, dpi) {
if (!width || isNaN(width) || !dpi || isNaN(dpi) || dpi <= 0) {
if (!width || isNaN(width) || width <= 0.0 || !dpi || isNaN(dpi) || dpi <= 0) {
return 0
}

return (width * PRINT_DPI_COMPENSATION) / dpi
return Math.max((width * PRINT_DPI_COMPENSATION) / dpi, MIN_PRINT_SCALE_SIZE)
}

0 comments on commit e9eebf6

Please sign in to comment.