Skip to content

Commit

Permalink
Add the DPI and bbox for QGIS server
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jul 30, 2018
1 parent 086773b commit c0912d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
19 changes: 15 additions & 4 deletions contribs/gmf/src/print/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,18 @@ exports.Controller_ = class {
}

if (this.layoutInfo.legend) {
const legend = this.getLegend_(scale);
const center = this.map.getView().getCenter();
const deltaX = this.paperSize_[0] * scale / 2 / ngeoPrintUtils.INCHES_PER_METER_ / ngeoPrintUtils.DOTS_PER_INCH_;
const deltaY = this.paperSize_[1] * scale / 2 / ngeoPrintUtils.INCHES_PER_METER_ / ngeoPrintUtils.DOTS_PER_INCH_;
const bbox = [
center[0] - deltaX,
center[1] - deltaY,
center[0] + deltaX,
center[1] + deltaY,
]
const legend = this.getLegend_(scale, this.layoutInfo.dpi, bbox);
if (legend !== null) {
customAttributes['legend'] = this.getLegend_(scale);
customAttributes['legend'] = legend;
}
}

Expand Down Expand Up @@ -1075,7 +1084,7 @@ exports.Controller_ = class {
* @return {Object?} Legend object for print report or null.
* @private
*/
getLegend_(scale) {
getLegend_(scale, dpi, bbox) {
const legend = {'classes': []};
let classes, layerNames, layerName, icons;
const gettextCatalog = this.gettextCatalog_;
Expand Down Expand Up @@ -1111,7 +1120,9 @@ exports.Controller_ = class {
icons = this.getMetadataLegendImage_(name);
if (!icons) {
icons = this.ngeoLayerHelper_.getWMSLegendURL(source.getUrl(), name,
scale);
scale, undefined, undefined, undefined, source.serverType_, dpi, bbox,
this.map.getView().getProjection().getCode()
);
}
// Don't add classes without legend url or from layers without any
// active name.
Expand Down
16 changes: 15 additions & 1 deletion src/map/LayerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,16 @@ exports.prototype.getWMTSLegendURL = function(layer) {
* @param {string=} opt_legendRule rule parameters to add to the returned URL.
* @param {number=} opt_legendWidth the legend width.
* @param {number=} opt_legendHeight the legend height.
* @param {string=} opt_servertype the OpenLayers server type.
* @param {number=} opt_dpi the DPI.
* @param {Array.Number=} opt_bbox the bbox.
* @param {string=} opt_srs The projection code.
* @return {string|undefined} The legend URL or undefined.
* @export
*/
exports.prototype.getWMSLegendURL = function(url,
layerName, opt_scale, opt_legendRule, opt_legendWidth, opt_legendHeight) {
layerName, opt_scale, opt_legendRule, opt_legendWidth, opt_legendHeight,
opt_servertype, opt_dpi, opt_bbox, opt_srs) {
if (!url) {
return undefined;
}
Expand All @@ -414,6 +419,15 @@ exports.prototype.getWMSLegendURL = function(url,
queryString['HEIGHT'] = opt_legendHeight;
}
}
if (opt_servertype == 'qgis') {
if (opt_dpi != undefined) {
queryString['DPI'] = opt_dpi;
}
if (opt_bbox != undefined && opt_srs != undefined) {
queryString['BBOX'] = opt_bbox.join(',');
queryString['SRS'] = opt_srs;
}
}
return olUri.appendParams(url, queryString);
};

Expand Down

0 comments on commit c0912d8

Please sign in to comment.