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

Be able to configure the Print GetLegendGraphics #4146

Merged
merged 1 commit into from
Aug 23, 2018
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
46 changes: 42 additions & 4 deletions contribs/gmf/src/print/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ exports.component_ = {

exports.component('gmfPrint', exports.component_);

/**
* @typedef {{
* useBbox: (boolean|undefined),
* label: (Object.<string, boolean>),
* params: (Object.<string, Object.<string, string>>)
* }}
*/
exports.optionsLegendType;

/**
* @typedef {{
* scaleInput: (boolean|undefined),
* legend: (optionsLegendType|undefined)
* }}
*/
exports.optionsType;

/**
* @private
Expand Down Expand Up @@ -336,8 +352,27 @@ exports.Controller_ = class {
*/
this.scaleInput = false;

/**
* @type optionsLegendType
* @private
*/
this.gmfLegendOptions_ = {
useBbox: true,
label: {},
params: {},
};

if ($injector.has('gmfPrintOptions')) {
this.scaleInput = $injector.get('gmfPrintOptions')['scaleInput'];
/**
* @type optionsType
*/
const options = $injector.get('gmfPrintOptions');
if (options.scaleInput) {
this.scaleInput = options.scaleInput;
}
if (options.legend) {
Object.assign(this.gmfLegendOptions_, options.legend);
}
}

/**
Expand Down Expand Up @@ -1121,15 +1156,18 @@ exports.Controller_ = class {
let icons = this.getMetadataLegendImage_(name);
if (!icons) {
icons = this.ngeoLayerHelper_.getWMSLegendURL(source.getUrl(), name,
scale, undefined, undefined, undefined, source.serverType_, dpi, bbox,
this.map.getView().getProjection().getCode()
scale, undefined, undefined, undefined, source.serverType_, dpi,
this.gmfLegendOptions_.useBbox ? bbox : undefined,
this.map.getView().getProjection().getCode(),
this.gmfLegendOptions_.params[layer.getSource().serverType_]
);
}
// Don't add classes without legend url or from layers without any
// active name.
if (icons && name.length !== 0) {
classes.push(Object.assign({
'name': gettextCatalog.getString(name),
'name': this.gmfLegendOptions_.label[layer.getSource().serverType_] === false ? '' :
gettextCatalog.getString(name),
'icons': [icons]
}, layer.getSource().serverType_ === 'qgis' ? {
'dpi': dpi,
Expand Down
6 changes: 5 additions & 1 deletion src/map/LayerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,13 @@ exports.prototype.getWMTSLegendURL = function(layer) {
* @param {number=} opt_dpi the DPI.
* @param {Array.number=} opt_bbox the bbox.
* @param {string=} opt_srs The projection code.
* @param {Object.<string, string>=} opt_additionalQueryString Additional query string parameters.
* @return {string|undefined} The legend URL or undefined.
* @export
*/
exports.prototype.getWMSLegendURL = function(url,
layerName, opt_scale, opt_legendRule, opt_legendWidth, opt_legendHeight,
opt_servertype, opt_dpi, opt_bbox, opt_srs) {
opt_servertype, opt_dpi, opt_bbox, opt_srs, opt_additionalQueryString) {
if (!url) {
return undefined;
}
Expand Down Expand Up @@ -432,6 +433,9 @@ exports.prototype.getWMSLegendURL = function(url,
queryString['HEIGHT'] = Math.round((opt_bbox[3] - opt_bbox[1]) / opt_scale * 39.37 * opt_dpi);
}
}
if (opt_additionalQueryString) {
Object.assign(queryString, opt_additionalQueryString);
}
return olUri.appendParams(url, queryString);
};

Expand Down