From 43cd7e5c575997abbd38ce196d8004f1141661fb Mon Sep 17 00:00:00 2001 From: Nicolas Boisteault Date: Tue, 12 Sep 2023 17:35:05 +0200 Subject: [PATCH] Redlining: print labels w/ given size (#3876) Note: rotation does not work. Is it a QGIS bug? --- assets/src/components/Print.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/assets/src/components/Print.js b/assets/src/components/Print.js index 6513d212af..74527dd35d 100644 --- a/assets/src/components/Print.js +++ b/assets/src/components/Print.js @@ -283,8 +283,13 @@ export default class Print extends HTMLElement { const formatWKT = new WKT(); const highlightGeom = []; const highlightSymbol = []; + const highlightLabelString = []; + const highlightLabelSize = []; + const highlightLabelBufferColor = []; + const highlightLabelBufferSize = []; + const highlightLabelRotation = []; - mainLizmap.digitizing.featureDrawn?.map((featureDrawn, index) => { + mainLizmap.digitizing.featureDrawn?.forEach((featureDrawn, index) => { // Translate circle coords to WKT if (featureDrawn.getGeometry().getType() === 'Circle') { @@ -303,6 +308,21 @@ export default class Print extends HTMLElement { } highlightSymbol.push(mainLizmap.digitizing.getFeatureDrawnSLD(index)); + + // Labels + const label = featureDrawn.get('text') ? featureDrawn.get('text') : ' '; + highlightLabelString.push(label); + // Font size is 10px by default (https://github.com/openlayers/openlayers/blob/v8.1.0/src/ol/style/Text.js#L30) + let scale = featureDrawn.get('scale'); + if (scale) { + scale = scale * 10; + } + highlightLabelSize.push(scale); + + highlightLabelBufferColor.push('#FFFFFF'); + highlightLabelBufferSize.push(1.5); + + highlightLabelRotation.push(featureDrawn.get('rotation')); }); if (highlightGeom.length && highlightSymbol.length) { @@ -310,6 +330,14 @@ export default class Print extends HTMLElement { wmsParams[this._mainMapID + ':HIGHLIGHT_SYMBOL'] = highlightSymbol.join(';'); } + if (!highlightLabelString.every(label => label === ' ')){ + wmsParams[this._mainMapID + ':HIGHLIGHT_LABELSTRING'] = highlightLabelString.join(';'); + wmsParams[this._mainMapID + ':HIGHLIGHT_LABELSIZE'] = highlightLabelSize.join(';'); + wmsParams[this._mainMapID + ':HIGHLIGHT_LABELBUFFERCOLOR'] = highlightLabelBufferColor.join(';'); + wmsParams[this._mainMapID + ':HIGHLIGHT_LABELBUFFERSIZE'] = highlightLabelBufferSize.join(';'); + wmsParams[this._mainMapID + ':HIGHLIGHT_LABEL_ROTATION'] = highlightLabelRotation.join(';'); + } + // Grid if(this._gridX){ wmsParams[this._mainMapID + ':GRID_INTERVAL_X'] = this._gridX;