Skip to content

Commit

Permalink
Be able to configure the Print GetLegendGraphics
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 23, 2018
1 parent c75350a commit 10a4ef3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
45 changes: 41 additions & 4 deletions contribs/gmf/src/print/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ exports.component_ = {

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

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

/**
* @private
Expand Down Expand Up @@ -336,8 +351,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 +1155,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

0 comments on commit 10a4ef3

Please sign in to comment.