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

Allow to set goodness of fit parameter for labels #5621

Merged
merged 2 commits into from
Mar 20, 2020
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
12 changes: 12 additions & 0 deletions contribs/gmf/src/print/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ module.component('gmfPrint', printComponent);
* @typedef {Object} OptionsType
* @property {boolean} [scaleInput]
* @property {OptionsLegendType} [legend]
* @property {number} [goodnessOfFit]
*/


Expand Down Expand Up @@ -412,6 +413,12 @@ class PrintController {
params: {},
};

/**
* @type {number}
* @private
*/
this.goodnessOfFit_ = 0.5;

if ($injector.has('gmfPrintOptions')) {
/**
* @type {OptionsType}
Expand All @@ -423,6 +430,9 @@ class PrintController {
if (options.legend) {
Object.assign(this.gmfLegendOptions_, options.legend);
}
if (typeof options.goodnessOfFit === 'number') {
this.goodnessOfFit_ = options.goodnessOfFit;
}
}

/**
Expand Down Expand Up @@ -987,6 +997,8 @@ class PrintController {
}
}

customAttributes['goodnessOfFit'] = this.goodnessOfFit_;

console.assert(typeof this.layoutInfo.dpi == 'number');
console.assert(typeof this.layoutInfo.layout == 'string');

Expand Down
10 changes: 9 additions & 1 deletion src/print/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export function PrintService(url, $http, gettextCatalog, ngeoLayerHelper) {
* @private
*/
this.printNativeAngle_ = true;

/**
* @type {number}
* @private
*/
this.goodnessOfFit_;
}


Expand Down Expand Up @@ -135,6 +141,8 @@ PrintService.prototype.createSpec = function(
rotation: /** number */ (customAttributes['rotation'])
});

this.goodnessOfFit_ = customAttributes['goodnessOfFit'];

this.encodeMap_(map, scale, specMap);

/** @type {!import('ngeo/print/mapfish-print-v3.js').MapFishPrintAttributes} */
Expand Down Expand Up @@ -223,7 +231,7 @@ PrintService.prototype.encodeLayer = function(arr, layer, resolution) {
* @param {number} resolution Resolution.
*/
PrintService.prototype.encodeVectorLayer = function(arr, layer, resolution) {
this.vectorEncoder.encodeVectorLayer(arr, layer, resolution);
this.vectorEncoder.encodeVectorLayer(arr, layer, resolution, this.goodnessOfFit_);
};

/**
Expand Down
31 changes: 26 additions & 5 deletions src/print/VectorEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ const PRINT_STYLE_TYPES = {
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} arr Array.
* @param {import("ol/layer/Vector.js").default} layer Layer.
* @param {number} resolution Resolution.
* @param {number} [goodnessOfFit] Goodness of fit.
*/
VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) {
VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution, goodnessOfFit) {
const source = /** @type {olSourceVector} */(layer.getSource());
console.assert(source instanceof olSourceVector);

Expand Down Expand Up @@ -116,7 +117,14 @@ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) {

const featureStyleProp = `_ngeo_style_${j}`;
const styleId = `${olUtilGetUid(style).toString()}-${geometryType}`;
this.encodeVectorStyle(mapfishStyleObject, geometryType, style, styleId, featureStyleProp);
this.encodeVectorStyle(
mapfishStyleObject,
geometryType,
style,
styleId,
featureStyleProp,
goodnessOfFit
);
geojsonFeature.properties[featureStyleProp] = styleId;
}
}
Expand Down Expand Up @@ -149,8 +157,16 @@ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) {
* @param {import("ol/style/Style.js").default} style Style.
* @param {string} styleId Style id.
* @param {string} featureStyleProp Feature style property name.
* @param {number} [goodnessOfFit] Goodness of fit.
*/
VectorEncoder.prototype.encodeVectorStyle = function(object, geometryType, style, styleId, featureStyleProp) {
VectorEncoder.prototype.encodeVectorStyle = function(
object,
geometryType,
style,
styleId,
featureStyleProp,
goodnessOfFit
) {
if (!(geometryType in PRINT_STYLE_TYPES)) {
// unsupported geometry type
return;
Expand Down Expand Up @@ -184,7 +200,7 @@ VectorEncoder.prototype.encodeVectorStyle = function(object, geometryType, style
}
}
if (textStyle !== null) {
this.encodeTextStyle(styleObject.symbolizers, textStyle);
this.encodeTextStyle(styleObject.symbolizers, textStyle, goodnessOfFit);
}
};

Expand Down Expand Up @@ -372,9 +388,10 @@ VectorEncoder.prototype.encodeVectorStyleStroke = function(symbolizer, strokeSty
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizer>} symbolizers Array of
* MapFish Print symbolizers.
* @param {!import("ol/style/Text.js").default} textStyle Text style.
* @param {number} [goodnessOfFit] Goodness of fit.
* @protected
*/
VectorEncoder.prototype.encodeTextStyle = function(symbolizers, textStyle) {
VectorEncoder.prototype.encodeTextStyle = function(symbolizers, textStyle, goodnessOfFit) {
const symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerText} */ ({
type: 'Text'
});
Expand Down Expand Up @@ -451,6 +468,10 @@ VectorEncoder.prototype.encodeTextStyle = function(symbolizers, textStyle) {
symbolizer.labelYOffset = -textStyle.getOffsetY();
}

if (goodnessOfFit !== undefined) {
symbolizer.goodnessOfFit = goodnessOfFit;
}

symbolizers.push(symbolizer);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/print/mapfish-print-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
* @property {number} haloOpacity
* @property {number} haloRadius
* @property {string} fontColor
* @property {number} goodnessOfFit
*/


Expand Down