From 99a63d1e5420c5dbb318ddbd583f31493e8884ed Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Tue, 6 Aug 2024 15:26:33 +0700 Subject: [PATCH] PB-790: Add replacer to fix the issue with JSON print spec. --- src/api/print.api.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/api/print.api.js b/src/api/print.api.js index 3df33d0427..54e46ba281 100644 --- a/src/api/print.api.js +++ b/src/api/print.api.js @@ -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) @@ -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}`)