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 6, 2024
1 parent c5bbfce commit 99a63d1
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 @@ -45,20 +45,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 @@ -453,7 +439,20 @@ export async function createPrintJob(map, config) {
dpi,
})
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)
throw new PrintError(`Error while creating print job: ${error}`)
Expand Down

0 comments on commit 99a63d1

Please sign in to comment.