Skip to content

Commit

Permalink
Merge pull request #4335 from camptocamp/2.3.4-wms-styles
Browse files Browse the repository at this point in the history
Add WMS styles management (in treeview and background layers)
  • Loading branch information
sbrunner committed Oct 26, 2018
2 parents 9dd6b14 + f1eb509 commit 1149f88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions contribs/gmf/src/layertree/SyncLayertreeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,20 @@ exports.prototype.updateLayerState_ = function(layer, treeCtrl) {
// First level non mixed group
googAsserts.assertInstanceof(layer, olLayerImage);
const names = [];
const styles = [];
treeCtrl.traverseDepthFirst((treeCtrl) => {
if (treeCtrl.node.children === undefined && treeCtrl.getState() === 'on') {
names.push(treeCtrl.node.layers);
const style = (treeCtrl.node.style !== undefined) ? treeCtrl.node.style : '';
styles.push(style);
}
});
if (names.length === 0) {
layer.setVisible(false);
}
/** @type {ol.source.ImageWMS} */ (layer.getSource()).updateParams({
'LAYERS': names.reverse().join(',')
'LAYERS': names.reverse().join(','),
'STYLES': styles.reverse().join(',')
});
if (names.length !== 0) {
layer.setVisible(true);
Expand Down Expand Up @@ -262,13 +266,16 @@ exports.prototype.createLeafInAMixedGroup_ = function(treeCtrl, map) {
googAsserts.assert(ogcServer.type);
googAsserts.assert(gmfLayerWMS.layers);
googAsserts.assert(ogcServer.imageType);

const opt_params = {STYLES: gmfLayerWMS.style};

layer = this.layerHelper_.createBasicWMSLayer(
ogcServer.url,
gmfLayerWMS.layers,
ogcServer.imageType,
ogcServer.type,
timeParam,
undefined, // WMS parameters
opt_params, // WMS parameters
ogcServer.credential ? 'use-credentials' : 'anonymous'
);
}
Expand Down
11 changes: 10 additions & 1 deletion contribs/gmf/src/theme/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,22 @@ exports.prototype.getBgLayers = function() {
googAsserts.assert(server, 'The OGC server was not found');
googAsserts.assert(server.url, 'The server URL is required');
googAsserts.assert(server.imageType, 'The server image type is required');

// Manage WMS styles
const opt_params = {STYLES: gmfLayerWMS.styles};
if (gmfLayer.dimensions) {
for (const [key, value] of Object.entries(gmfLayer.dimensions)) {
opt_params[key] = value;
}
}

return callback(gmfLayer, layerHelper.createBasicWMSLayer(
server.url,
gmfLayerWMS.layers || '',
server.imageType,
server.type,
undefined, // time
gmfLayer.dimensions,
opt_params,
server.credential ? 'use-credentials' : 'anonymous',
gmfLayerWMS.metadata.customOpenLayersOptions
));
Expand Down

0 comments on commit 1149f88

Please sign in to comment.