Skip to content

PB-111: Fix print spec send to the print service #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bca7abb
PB-111: Exclude world layer/print area from the map spec.
ismailsunni Mar 21, 2024
59bdbd6
PB-111: Add GeoAdminCustomizer to exclude some layers from the spec.
ismailsunni Mar 21, 2024
e1a1600
PB-111: Use my fix in geoblocks/mapfishprint from github until they r…
ismailsunni Mar 21, 2024
1ba8624
PB-111: Add e2e test for print.
ismailsunni Mar 25, 2024
de3f04a
PB-111: Update geoblocks/mapfishprint to 0.2.9
ismailsunni Mar 25, 2024
44b46ad
PB-111: Add case with different projection.
ismailsunni Mar 25, 2024
8b7b139
PB-111: Add e2e test for print with different layers.
ismailsunni Mar 26, 2024
06fb083
PB-111: Reduce delay to fix the failed test
ismailsunni Mar 26, 2024
dddbf78
PB-111: Increase pageLoadTimeout
ismailsunni Mar 26, 2024
e193c86
PB-111: Separate test case to prevent overtime.
ismailsunni Mar 26, 2024
a2ad316
PB-111: Add GeoAdminCustomizer to exclude print area rectangle layer.
ismailsunni Mar 28, 2024
ef32adc
PB-111: Fix unit test in print.
ismailsunni Mar 28, 2024
09327cd
PB-111: Fix failed to print with grid.
ismailsunni Mar 28, 2024
d13d55b
PB-111: Use file from fixtures on cypress intercept.
ismailsunni Mar 28, 2024
178cc28
PB-239: Refactor area layer name.
ismailsunni Mar 28, 2024
73a65ac
PB-111: Add JSDoc use OpenLayers ID not name.
ismailsunni Mar 28, 2024
8a54190
PB-111: Fix unit test after removal of number in Layout.
ismailsunni Mar 28, 2024
4a64c73
PB-111: Fix missing legend.
ismailsunni Mar 29, 2024
c7a470c
PB-111: Add test for legend spec.
ismailsunni Mar 29, 2024
c8560ea
PB:111: Update geoblocks/mapfishprint for a WMTS matrix size fix.
ismailsunni Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/vue-fontawesome": "^3.0.6",
"@geoblocks/cesium-compass": "^0.5.0",
"@geoblocks/mapfishprint": "^0.2.7",
"@geoblocks/mapfishprint": "github:geoblocks/mapfishprint#4c47539f391af3c641f9455efe0d31ebdc145cfe",
"@geoblocks/ol-maplibre-layer": "^0.1.3",
"@ivanv/vue-collapse-transition": "^1.0.2",
"@mapbox/togeojson": "^0.16.2",
Expand Down
38 changes: 36 additions & 2 deletions src/api/print.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ const PRINTING_DEFAULT_POLL_INTERVAL = 2000 // interval between each polling of
const PRINTING_DEFAULT_POLL_TIMEOUT = 600000 // ms (10 minutes)

const SERVICE_PRINT_URL = `${API_SERVICES_BASE_URL}print3/print/default`

class GeoAdminCustomizer extends BaseCustomizer {
/** @param {string[]} layerIDsToExclude List of layer names to exclude from the print */
constructor(layerIDsToExclude) {
super()
this.layerIDsToExclude = layerIDsToExclude
this.layerFilter = this.layerFilter.bind(this)
}

/**
* Filter out layers that should not be printed. This function is automatically called when the
* encodeMap is called using this customizer.
*
* @param {State} layerState
* @returns {boolean} True to convert this layer, false to skip it
*/
layerFilter(layerState) {
if (this.layerIDsToExclude.includes(layerState.layer.get('id'))) {
return false
}
// Call parent layerFilter method for other layers
return super.layerFilter(layerState)
}
}

/**
* Tool to transform an OpenLayers map into a "spec" for MapFishPrint3 (meaning a big JSON) that can
* then be used as request body for printing.
Expand Down Expand Up @@ -169,6 +194,8 @@ export class PrintError extends Error {
* Default is `false`
* @param {CoordinateSystem} [config.projection=null] The projection used by the map, necessary when
* the grid is to be printed (it can otherwise be null). Default is `null`
* @param {String[]} [config.excludedLayerIDs=[]] List of the IDs of OpenLayers layer to exclude
* from the print. Default is `[]`
*/
async function transformOlMapToPrintParams(olMap, config) {
const {
Expand All @@ -181,6 +208,7 @@ async function transformOlMapToPrintParams(olMap, config) {
lang = null,
printGrid = false,
projection = null,
excludedLayerIDs = [],
} = config

if (!qrCodeUrl) {
Expand All @@ -202,6 +230,8 @@ async function transformOlMapToPrintParams(olMap, config) {
throw new PrintError('Missing projection to print the grid')
}

const customizer = new GeoAdminCustomizer(excludedLayerIDs)

const attributionsOneLine = attributions.length > 0 ? `© ${attributions.join(', ')}` : ''

try {
Expand All @@ -210,7 +240,7 @@ async function transformOlMapToPrintParams(olMap, config) {
scale,
printResolution: PRINTING_RESOLUTION,
dpi: PRINTING_RESOLUTION,
customizer: new BaseCustomizer([0, 0, 10000, 10000]),
customizer: customizer,
})
if (printGrid) {
encodedMap.layers.unshift({
Expand Down Expand Up @@ -239,7 +269,7 @@ async function transformOlMapToPrintParams(olMap, config) {
layout: layout.name,
}
if (layersWithLegends.length > 0) {
spec.attributes.legends = {
spec.attributes.legend = {
name: i18n.global.t('legend'),
classes: layersWithLegends.map((layer) => {
return {
Expand Down Expand Up @@ -277,6 +307,8 @@ async function transformOlMapToPrintParams(olMap, config) {
* Default is `false`
* @param {CoordinateSystem} [config.projection=null] The projection used by the map, necessary when
* the grid is to be printed (it can otherwise be null). Default is `null`
* @param {String[]} [config.excludedLayerIDs=[]] List of IDs of OpenLayers layer to exclude from
* the print. Default is `[]`
* @returns {Promise<MFPReportResponse>} A job running on our printing backend (needs to be polled
* using {@link waitForPrintJobCompletion} to wait until its completion)
*/
Expand All @@ -291,6 +323,7 @@ export async function createPrintJob(map, config) {
lang = null,
printGrid = false,
projection = null,
excludedLayerIDs = [],
} = config
try {
const printingSpec = await transformOlMapToPrintParams(map, {
Expand All @@ -303,6 +336,7 @@ export async function createPrintJob(map, config) {
lang,
printGrid,
projection,
excludedLayerIDs,
})
log.debug('Starting print for spec', printingSpec)
return await requestReport(SERVICE_PRINT_URL, printingSpec)
Expand Down
6 changes: 6 additions & 0 deletions src/modules/map/components/openlayers/utils/printConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* The name of the OpenLayer layer that is used to render the print area.
*
* @type {String}
*/
export const PRINT_AREA_LAYER_ID = 'printAreaLayer'
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getGenerateQRCodeUrl } from '@/api/qrcode.api.js'
import { createShortLink } from '@/api/shortlink.api.js'
import log from '@/utils/logging'

import { PRINT_AREA_LAYER_ID } from './printConstants'

// const dispatcher = { dispatcher: 'usePrint.composable' }

/** @enum */
Expand Down Expand Up @@ -59,7 +61,8 @@ export function usePrint(map) {
: [],
lang: store.state.i18n.lang,
printGrid: printGrid,
projection: store.state.map.projection,
projection: store.state.position.projection,
excludedLayerIDs: [PRINT_AREA_LAYER_ID],
})
currentJobReference.value = printJob.ref
const result = await waitForPrintJobCompletion(printJob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Fill, Style } from 'ol/style'
import { computed, watch } from 'vue'
import { useStore } from 'vuex'

import { PRINT_AREA_LAYER_ID } from './printConstants'

const dispatcher = { dispatcher: 'print-area-renderer.composable' }

function createWorldPolygon() {
Expand Down Expand Up @@ -36,6 +38,7 @@ function createWorldPolygon() {
features: [worldPolygon],
}),
style: transparentStyle,
id: PRINT_AREA_LAYER_ID,
})
return vectorLayer
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/menu/components/debug/DebugToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function toggleShowLayerExtents() {
<div class="position-relative d-flex">
<div
class="debug-tools-header p-2 bg-danger-subtle border-end border-danger rounded-start-1"
data-cy="debug-tools-header"
@click="showDebugTool = !showDebugTool"
>
<FontAwesomeIcon icon="gear" title="Debug tools" />
Expand All @@ -55,13 +56,14 @@ function toggleShowLayerExtents() {
<div class="card-body">
<h5 class="text-decoration-underline">Map projection</h5>
<div class="my-1 d-flex align-content-center">
<strong class="me-2 align-self-center">
<strong class="me-2 align-self-center" data-cy="current-projection">
{{ currentProjection.epsg }}
</strong>
<button
class="toolbox-button align-self-center"
type="button"
:class="{ active: isMercatorTheCurrentProjection }"
data-cy="toggle-projection-button"
@click="toggleProjection"
>
<FontAwesomeIcon :icon="['fas', 'earth-europe']" />
Expand Down
33 changes: 26 additions & 7 deletions src/modules/menu/components/print/MenuPrintSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,16 @@ defineExpose({
@click:header="togglePrintMenu"
@open-menu-section="(id) => emits('openMenuSection', id)"
>
<div class="p-2 d-grid gap-2 menu-print-settings mx-4">
<label for="print-layout-selector " class="col-form-label fw-bold me-2">{{
<div class="p-2 d-grid gap-2 menu-print-settings mx-4" data-cy="menu-print-form">
<label for="print-layout-selector" class="col-form-label fw-bold me-2">{{
i18n.t('print_layout')
}}</label>
<select id="print-layout-selector " v-model="selectedLayoutName" class="form-select">
<select
id="print-layout-selector"
v-model="selectedLayoutName"
class="form-select"
data-cy="print-layout-selector"
>
<option
v-for="layout in availablePrintLayouts"
:key="layout.name"
Expand All @@ -128,18 +133,24 @@ defineExpose({
{{ layout.name.replace(/^\d+\.\s*/, '') }}
</option>
</select>
<label for="print-scale-selector " class="col-form-label fw-bold me-2">{{
<label for="print-scale-selector" class="col-form-label fw-bold me-2">{{
i18n.t('print_scale')
}}</label>
<select id="print-scale-selector " v-model="selectedScale" class="form-select">
<select
id="print-scale-selector"
v-model="selectedScale"
class="form-select"
data-cy="print-scale-selector"
>
<option v-for="scale in scales" :key="scale" :value="scale">
1:{{ formatThousand(scale) }}
{{ '1:' + formatThousand(scale) }}
</option>
</select>
<div class="form-check">
<input
id="checkboxLegend"
v-model="printLegend"
data-cy="checkboxLegend"
class="form-check-input"
type="checkbox"
/>
Expand All @@ -149,6 +160,7 @@ defineExpose({
<input
id="checkboxGrid"
v-model="printGrid"
data-cy="checkboxGrid"
class="form-check-input"
type="checkbox"
/>
Expand All @@ -159,11 +171,18 @@ defineExpose({
v-if="printStatus === PrintStatus.PRINTING"
type="button"
class="btn btn-danger w-100 text-white"
data-cy="abort-print-button"
@click="abortCurrentJob"
>
{{ i18n.t('abort') }}
</button>
<button v-else type="button" class="btn btn-light w-100" @click="printMap">
<button
v-else
type="button"
class="btn btn-light w-100"
data-cy="print-map-button"
@click="printMap"
>
{{ i18n.t('print_action') }}
</button>
<!-- TODO: manage failing print job-->
Expand Down
Loading
Loading