Skip to content

Commit

Permalink
Merge pull request #1021 from geoadmin/fix-790-update-mapfishprint-wi…
Browse files Browse the repository at this point in the history
…th-replacer

Fix 790 update mapfishprint with replacer - #patch
  • Loading branch information
ismailsunni authored Aug 20, 2024
2 parents 1b7564c + 7279ab9 commit 1b09a88
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
22 changes: 12 additions & 10 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 @@ -45,7 +45,7 @@
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/vue-fontawesome": "^3.0.8",
"@geoblocks/cesium-compass": "^0.5.0",
"@geoblocks/mapfishprint": "^0.2.15",
"@geoblocks/mapfishprint": "^0.2.16",
"@geoblocks/ol-maplibre-layer": "^1.0.0",
"@ivanv/vue-collapse-transition": "^1.0.2",
"@mapbox/togeojson": "^0.16.2",
Expand Down
35 changes: 20 additions & 15 deletions src/api/print.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ class GeoAdminCustomizer extends BaseCustomizer {
return super.layerFilter(layerState)
}

/**
* Remove the "editableFeature" adn "geodesic" property from the feature as it is not needed and
* can cause issues with mapfishprint
*
* @param {State} layerState
* @param {GeoJSONFeature} feature Manipulated feature
*/
feature(layerState, feature) {
// cause circular reference issues
delete feature.properties?.geodesic
// unnecessary properties for printing and cause mapfishprint to throw an error
delete feature.properties?.editableFeature
}

/**
* Manipulate the symbolizer of a line feature before printing it. In this case replace the
* strokeDashstyle to dash instead of 8 (measurement line style in the mapfishprint3 backend)
Expand Down Expand Up @@ -405,6 +391,24 @@ async function transformOlMapToPrintParams(olMap, config) {
}
}

/**
* Replacer function to manipulate some properties from the printing spec before sending it to the
* printing service. It is used as a parameter for JSON.stringify in the requestReport function. See
* more
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter
*/
function printSpecReplacer(key, value) {
// Remove the "bad" property from the feature
const badKeys = [
'editableFeature', // unnecessary properties for printing but cause mapfishprint to throw an error
'geodesic', // cause circular reference issues on JSON.stringify
]
if (badKeys.includes(key)) {
return undefined
}
return value
}

/**
* Lauches a print job on our backend with the given configuration. This job then needs to be polled
* by {@link waitForPrintJobCompletion}
Expand Down Expand Up @@ -466,7 +470,8 @@ export async function createPrintJob(map, config) {
throw new PrintError('Printing spec is too large', 'print_request_too_large')
}
log.debug('Starting print for spec', printingSpec)
return await requestReport(SERVICE_PRINT_URL, printingSpec)

return await requestReport(SERVICE_PRINT_URL, printingSpec, printSpecReplacer)
} catch (error) {
log.error('Error while creating print job', error)
if (error instanceof PrintError) {
Expand Down

0 comments on commit 1b09a88

Please sign in to comment.