Skip to content

Commit

Permalink
PB-790: Add replacer to fix the issue with JSON print spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Aug 15, 2024
1 parent 1b7564c commit 0ac00d4
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 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 @@ -466,7 +452,20 @@ 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)

function replacer(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
}

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

0 comments on commit 0ac00d4

Please sign in to comment.