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 #5657

Merged
merged 1 commit into from
Mar 27, 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.
Jump to
Jump to file
Failed to load files.
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 @@ -252,6 +252,7 @@ module.component('gmfPrint', printComponent);
* @typedef {Object} OptionsType
* @property {boolean} [scaleInput]
* @property {OptionsLegendType} [legend]
* @property {number} [goodnessOfFit]
*/


Expand Down Expand Up @@ -424,6 +425,12 @@ export class PrintController {
params: {},
};

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

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

/**
Expand Down Expand Up @@ -1055,6 +1065,8 @@ export class PrintController {
throw new Error('Wrong layoutInfo.layout type');
}

customAttributes.goodnessOfFit = this.goodnessOfFit_;

// convert the WMTS layers to WMS
const map = new olMap({});
map.setView(this.map.getView());
Expand Down
10 changes: 9 additions & 1 deletion src/print/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export function PrintService(url, $http, gettextCatalog, ngeoLayerHelper) {
* @private
*/
this.printNativeAngle_ = true;

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


Expand Down Expand Up @@ -157,6 +163,8 @@ PrintService.prototype.createSpec = function(
rotation: customAttributes.rotation
});

this.goodnessOfFit_ = customAttributes['goodnessOfFit'];

this.encodeMap_(map, scale, specMap);

/** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintAttributes} */
Expand Down Expand Up @@ -253,7 +261,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
19 changes: 14 additions & 5 deletions src/print/VectorEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,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) {
/**
* @type {import("ol/source/Vector.js").default<import("ol/geom/Geometry.js").default>}
*/
Expand Down Expand Up @@ -141,7 +142,7 @@ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) {
this.encodeVectorStyle(
/** @type {Object<string, import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizers>} */(
/** @type {*} */(mapfishStyleObject)
), geometryType, style, styleId, featureStyleProp
), geometryType, style, styleId, featureStyleProp, goodnessOfFit
);
geojsonFeature.properties[featureStyleProp] = styleId;
}
Expand Down Expand Up @@ -175,8 +176,11 @@ 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 @@ -211,7 +215,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 @@ -407,9 +411,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 @@ -494,6 +499,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 @@ -254,6 +254,7 @@
* @property {number} haloOpacity
* @property {number} haloRadius
* @property {string} fontColor
* @property {number} goodnessOfFit
*/


Expand Down