Skip to content

Commit

Permalink
Merge pull request #270 from Jenselme/base-url
Browse files Browse the repository at this point in the history
Make sure baseURL are absolute when printing
  • Loading branch information
Éric Lemoine committed Aug 10, 2015
2 parents 92dbf25 + ab28cc3 commit 2ea6be5
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/services/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,18 @@ ngeo.Print.prototype.encodeImageWmsLayer_ = function(arr, layer) {
goog.asserts.assertInstanceof(layer, ol.layer.Image);
goog.asserts.assertInstanceof(source, ol.source.ImageWMS);

this.encodeWmsLayer_(
arr, layer.getOpacity(), source.getUrl(), source.getParams());
var url = source.getUrl();
if (goog.isDef(url)) {
this.encodeWmsLayer_(
arr, layer.getOpacity(), url, source.getParams());
}
};


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {number} opacity Opacity of the layer.
* @param {string|undefined} url Url of the WMS server.
* @param {string} url Url of the WMS server.
* @param {Object} params Url parameters
* @private
*/
Expand All @@ -270,7 +273,7 @@ ngeo.Print.prototype.encodeWmsLayer_ = function(arr, opacity, url, params) {
goog.object.remove(customParams, 'FORMAT');

var object = /** @type {MapFishPrintWmsLayer} */ ({
baseURL: url,
baseURL: ngeo.Print.getAbsoluteUrl_(url),
imageFormat: 'FORMAT' in params ? params['FORMAT'] : 'image/png',
layers: params['LAYERS'].split(','),
customParams: customParams,
Expand All @@ -281,6 +284,18 @@ ngeo.Print.prototype.encodeWmsLayer_ = function(arr, opacity, url, params) {
};


/**
* @param {string} url
* @return {string} Absolute URL.
* @private
*/
ngeo.Print.getAbsoluteUrl_ = function(url) {
var a = document.createElement('a');
a.href = encodeURI(url);
return decodeURI(a.href);
};


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {ol.layer.Tile} layer Layer.
Expand Down Expand Up @@ -682,7 +697,7 @@ ngeo.Print.prototype.getWmtsUrl_ = function(source) {
if (url.indexOf('{Layer}') >= 0) {
url = url.replace('{Layer}', layer);
}
return url;
return ngeo.Print.getAbsoluteUrl_(url);
};


Expand Down

0 comments on commit 2ea6be5

Please sign in to comment.