Skip to content

Commit

Permalink
Merge pull request #4861 from camptocamp/GSGMF-933
Browse files Browse the repository at this point in the history
Support GmfGroup for the background layers in the api
  • Loading branch information
fredj committed Apr 30, 2019
2 parents 1f60833 + 413b21c commit 7926f33
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
34 changes: 30 additions & 4 deletions api/src/Themes.js
Expand Up @@ -3,6 +3,7 @@ import ImageWMS from 'ol/source/ImageWMS.js';
import WMTS, {optionsFromCapabilities} from 'ol/source/WMTS.js';
import TileLayer from 'ol/layer/Tile.js';
import ImageLayer from 'ol/layer/Image.js';
import GroupLayer from 'ol/layer/Group.js';

import constants from './constants.js';

Expand Down Expand Up @@ -31,13 +32,13 @@ let overlayDefPromise;

/**
* @hidden
* @returns {Promise<Array<TileLayer|ImageLayer>>} Promise
* @returns {Promise<Array<TileLayer|ImageLayer|GroupLayer>>} Promise
*/
export function getBackgroundLayers() {
return getThemesPromise().then((themes) => {
const promises = [];
for (const config of themes.background_layers) {
if (config.type === 'WMTS') {
if (/** @type {import('gmf/themes.js').GmfLayer} */ (config).type === 'WMTS') {
const layerWMTS = /** @type {import('gmf/themes.js').GmfLayerWMTS} */(config);
promises.push(
createWMTSLayer(layerWMTS).then((layer) => {
Expand All @@ -46,7 +47,7 @@ export function getBackgroundLayers() {
return layer;
})
);
} else if (config.type === 'WMS') {
} else if (/** @type {import('gmf/themes.js').GmfLayer} */ (config).type === 'WMS') {
const layerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(config);
const ogcServer = themes.ogcServers[config.ogcServer];
promises.push(
Expand All @@ -56,9 +57,34 @@ export function getBackgroundLayers() {
return layer;
})
);
} else if (/** @type {import('gmf/themes.js').GmfGroup} */ (config).children) {
// reverse children order
const reversed = /** @type {import('gmf/themes.js').GmfGroup} */ (config).children.slice().reverse();

// create all the layers for the layer group
const groupPromise = Promise.all(reversed.map((item) => {
const child = /** @type {import('gmf/themes.js').GmfLayer} */ (item);
if (child.type === 'WMTS') {
const layerWMTS = /** @type {import('gmf/themes.js').GmfLayerWMTS} */ (child);
return createWMTSLayer(layerWMTS);
} else if (child.type === 'WMS') {
const layerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */ (child);
return createWMSLayer(layerWMS, themes.ogcServers[child.ogcServer]);
}
}));
promises.push(
groupPromise.then((layers) => {
// create a layer group for the children.
const group = new GroupLayer({
layers: layers
});
group.set('config.name', config.name);
return group;
})
);
}
}
return Promise.all(promises);
return Promise.all(/** @type {Array<Promise<TileLayer|ImageLayer|GroupLayer>>} */ (promises));
});
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/constants.js
Expand Up @@ -10,5 +10,5 @@ export default {
* The name of the layer to use as background. May be a single value
* (WMTS) or a comma-separated list of layer names (WMS).
*/
backgroundLayer: 'OSM map',
backgroundLayer: 'orthophoto',
};
8 changes: 1 addition & 7 deletions contribs/gmf/src/theme/Themes.js
Expand Up @@ -305,13 +305,7 @@ export class ThemesService extends olEventsEventTarget {
*/
getBackgroundLayersObject() {
console.assert(this.promise_ !== null);
return this.promise_.then(
/**
* @param {!import('gmf/themes.js').GmfThemesResponse} data The "themes" web service response.
* @return {!Array.<!import('gmf/themes.js').GmfLayer>} The background layers object.
*/
data => data.background_layers
);
return this.promise_.then(data => data.background_layers);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/themes.js
Expand Up @@ -9,7 +9,7 @@

/**
* @typedef {Object} GmfThemesResponse
* @property {!Array.<!GmfLayer>} background_layers
* @property {!Array.<!GmfLayer|!GmfGroup>} background_layers
* @property {!Array.<string>} errors
* @property {!GmfOgcServers} ogcServers
* @property {!Array.<!GmfTheme>} themes
Expand Down

0 comments on commit 7926f33

Please sign in to comment.