Skip to content
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

Fix 790 update mapfishprint with replacer - #patch #1021

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading