From 4ff7fc94eb342d992ec91a460b1b187eb39a6068 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 25 Oct 2017 11:28:59 +0200 Subject: [PATCH] Take the imageType into account for WMS layers --- contribs/gmf/src/directives/print.js | 1 + contribs/gmf/src/services/syncLayertreeMap.js | 6 ++++-- contribs/gmf/src/services/themesservice.js | 2 ++ src/services/layerHelper.js | 8 ++++++-- test/spec/services/layerHelper.spec.js | 9 +++++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/contribs/gmf/src/directives/print.js b/contribs/gmf/src/directives/print.js index c811727caaf7..f2ec5e9484d7 100644 --- a/contribs/gmf/src/directives/print.js +++ b/contribs/gmf/src/directives/print.js @@ -698,6 +698,7 @@ gmf.PrintController.prototype.print = function(format) { layer = this.ngeoLayerHelper_.createBasicWMSLayer( server.url, layer_names, + server.imageType, server.type ); } else { diff --git a/contribs/gmf/src/services/syncLayertreeMap.js b/contribs/gmf/src/services/syncLayertreeMap.js index fa95a030c82d..8d84cd9c5c5d 100644 --- a/contribs/gmf/src/services/syncLayertreeMap.js +++ b/contribs/gmf/src/services/syncLayertreeMap.js @@ -197,8 +197,9 @@ gmf.SyncLayertreeMap.prototype.createLayerFromGroup_ = function(treeCtrl, goog.asserts.assert(ogcServer); goog.asserts.assert(ogcServer.url); goog.asserts.assert(ogcServer.type); + goog.asserts.assert(ogcServer.imageType); layer = this.layerHelper_.createBasicWMSLayer( - ogcServer.url, '', ogcServer.type, timeParam + ogcServer.url, '', ogcServer.imageType, ogcServer.type, timeParam ); var hasActiveChildren = false; treeCtrl.traverseDepthFirst(function(ctrl) { @@ -238,8 +239,9 @@ gmf.SyncLayertreeMap.prototype.createLeafInAMixedGroup_ = function(treeCtrl, map goog.asserts.assert(ogcServer.url); goog.asserts.assert(ogcServer.type); goog.asserts.assert(gmfLayerWMS.layers); + goog.asserts.assert(ogcServer.imageType); layer = this.layerHelper_.createBasicWMSLayer(ogcServer.url, - gmfLayerWMS.layers, ogcServer.type, timeParam); + gmfLayerWMS.layers, ogcServer.imageType, ogcServer.type, timeParam); } // Update layer information and tree state. layer.set('layerNodeName', gmfLayer.name); // Really useful ? diff --git a/contribs/gmf/src/services/themesservice.js b/contribs/gmf/src/services/themesservice.js index 0ea9d6423ef9..1e5b6677a29d 100644 --- a/contribs/gmf/src/services/themesservice.js +++ b/contribs/gmf/src/services/themesservice.js @@ -289,9 +289,11 @@ gmf.Themes.prototype.getBgLayers = function(appDimensions) { var server = ogcServers[gmfLayerWMS.ogcServer]; goog.asserts.assert(server, 'The OGC server was not found'); goog.asserts.assert(server.url, 'The server URL is required'); + goog.asserts.assert(server.imageType, 'The server image type is required'); return callback(gmfLayer, layerHelper.createBasicWMSLayer( server.url, gmfLayerWMS.layers || '', + server.imageType, server.type, undefined, // time gmfLayer.dimensions diff --git a/src/services/layerHelper.js b/src/services/layerHelper.js index 73fc6abc19a0..986af30b0d1b 100644 --- a/src/services/layerHelper.js +++ b/src/services/layerHelper.js @@ -57,6 +57,7 @@ ngeo.LayerHelper.REFRESH_PARAM = 'random'; * * @param {string} sourceURL The source URL. * @param {string} sourceLayersName A comma separated names string. + * @param {string} sourceFormat Image format, for example 'image/png'. * @param {string=} opt_serverType Type of the server ("mapserver", * "geoserver", "qgisserver", …). * @param {string=} opt_time time parameter for layer queryable by time/periode @@ -65,9 +66,12 @@ ngeo.LayerHelper.REFRESH_PARAM = 'random'; * @export */ ngeo.LayerHelper.prototype.createBasicWMSLayer = function(sourceURL, - sourceLayersName, opt_serverType, opt_time, opt_params) { + sourceLayersName, sourceFormat, opt_serverType, opt_time, opt_params) { - var params = {'LAYERS': sourceLayersName}; + var params = { + 'FORMAT': sourceFormat, + 'LAYERS': sourceLayersName + }; var olServerType; if (opt_time) { params['TIME'] = opt_time; diff --git a/test/spec/services/layerHelper.spec.js b/test/spec/services/layerHelper.spec.js index 75a0f7d43ea2..07d3ebcc78af 100644 --- a/test/spec/services/layerHelper.spec.js +++ b/test/spec/services/layerHelper.spec.js @@ -23,9 +23,14 @@ describe('ngeo.LayerHelper', function() { }); it('Create a basic WMS layer', function() { - layer = ngeoLayerHelper.createBasicWMSLayer('', ''); + layer = ngeoLayerHelper.createBasicWMSLayer('http://example.com/', 'a,b,c', 'image/jpeg'); expect(layer.constructor).toBe(ol.layer.Image); - expect(layer.getSource().constructor).toBe(ol.source.ImageWMS); + var source = layer.getSource(); + expect(source.constructor).toBe(ol.source.ImageWMS); + expect(source.getUrl()).toBe('http://example.com/'); + var params = source.getParams(); + expect(params.LAYERS).toBe('a,b,c'); + expect(params.FORMAT).toBe('image/jpeg'); }); it('Create a WMTS layer from capabilitites', function() {