Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] JS: Layer ID can be used as WMS Name #4033

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion assets/src/modules/config/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ export class LayersConfig {
* @throws {RangeError|Error} The layer name is unknown or the config has been corrupted
*/
getLayerConfigByWmsName(name) {
const idx = this._names.indexOf(name);
// WMS Name can be the layer name
let idx = this._names.indexOf(name);
if (idx != -1) {
const cfg = this._configs[idx];
if (cfg.name != name) {
Expand All @@ -491,6 +492,17 @@ export class LayersConfig {
return cfg;
}

// WMS Name can be the layer id
idx = this._ids.indexOf(name);
if (idx != -1) {
const cfg = this._configs[idx];
if (cfg.id != name) {
throw 'The config has been corrupted!'
}
return cfg;
}

// WMS Name can be the short name
for (const layer of this.getLayerConfigs()) {
if (layer.shortname == name) {
return layer;
Expand Down
125 changes: 125 additions & 0 deletions tests/js-units/node/config/layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,131 @@ describe('LayersConfig', function () {
expect(complexeGetLayerConfigs.next().value).to.be.instanceOf(LayerConfig)
})

it('getLayerConfigByWmsName', function () {
const francePartsLayers = new LayersConfig({
"france_parts bordure": {
"abstract": "",
"displayInLegend": "True",
"popupMaxFeatures": 10,
"baseLayer": "False",
"noLegendImage": "False",
"id": "france_parts_copier20180110163243267",
"title": "france_parts bordure",
"singleTile": "True",
"geometryType": "polygon",
"groupAsLayer": "False",
"popupTemplate": "",
"popup": "False",
"popupDisplayChildren": "False",
"clientCacheExpiration": 300,
"link": "",
"extent": [
-5.1326269187,
46.2791909858,
3.11792890789,
49.7264741072
],
"toggled": "True",
"crs": "EPSG:4326",
"name": "france_parts bordure",
"cached": "False",
"type": "layer",
"maxScale": 1000000000000,
"popupSource": "lizmap",
"imageFormat": "image/png",
"minScale": 1,
"layerType": 'vector',
"shortname": "france_parts_bordure",
},
"france_parts tuilé en cache": {
"abstract": "",
"displayInLegend": "True",
"popupMaxFeatures": 10,
"cacheExpiration": 0,
"baseLayer": "False",
"noLegendImage": "False",
"id": "france_parts_copier20180110163329820",
"title": "france_parts tuilé en cache",
"singleTile": "False",
"geometryType": "polygon",
"groupAsLayer": "False",
"popupTemplate": "",
"popup": "False",
"popupDisplayChildren": "False",
"clientCacheExpiration": 300,
"link": "",
"extent": [
-5.1326269187,
46.2791909858,
3.11792890789,
49.7264741072
],
"toggled": "False",
"crs": "EPSG:4326",
"name": "france_parts tuilé en cache",
"cached": "True",
"type": "layer",
"maxScale": 1000000000000,
"popupSource": "lizmap",
"imageFormat": "image/png",
"minScale": 1,
"layerType": 'vector',
"shortname": "france_parts_tuile",
},
"france_parts": {
"abstract": "",
"displayInLegend": "True",
"popupMaxFeatures": 10,
"baseLayer": "False",
"noLegendImage": "False",
"id": "france_parts_8d8d649f_7748_43cc_8bde_b013e17ede29",
"title": "france_parts",
"singleTile": "True",
"geometryType": "polygon",
"groupAsLayer": "False",
"popupTemplate": "",
"popup": "True",
"popupDisplayChildren": "False",
"clientCacheExpiration": 300,
"link": "",
"extent": [
-5.1326269187,
46.2791909858,
3.11792890789,
49.7264741072
],
"toggled": "True",
"crs": "EPSG:4326",
"name": "france_parts",
"cached": "False",
"type": "layer",
"maxScale": 1000000000000,
"popupSource": "auto",
"imageFormat": "image/png",
"minScale": 1,
"layerType": 'vector',
"shortname": "france_parts",
}
})

const francePartsLayer = francePartsLayers.getLayerConfigByWmsName('france_parts_8d8d649f_7748_43cc_8bde_b013e17ede29');
expect(francePartsLayer.name).to.be.eq('france_parts')
expect(francePartsLayer.id).to.be.eq('france_parts_8d8d649f_7748_43cc_8bde_b013e17ede29')
expect(francePartsLayer.shortname).to.be.eq('france_parts')

const francePartsTuileLayer = francePartsLayers.getLayerConfigByWmsName('france_parts_tuile');
expect(francePartsTuileLayer.name).to.be.eq('france_parts tuilé en cache')
expect(francePartsTuileLayer.id).to.be.eq('france_parts_copier20180110163329820')
expect(francePartsTuileLayer.shortname).to.be.eq('france_parts_tuile')

const francePartsBordureLayer = francePartsLayers.getLayerConfigByWmsName('france_parts bordure');
expect(francePartsBordureLayer.name).to.be.eq('france_parts bordure')
expect(francePartsBordureLayer.id).to.be.eq('france_parts_copier20180110163243267')
expect(francePartsBordureLayer.shortname).to.be.eq('france_parts_bordure')

expect(francePartsLayers.getLayerConfigByWmsName('unknown')).to.be.null
})

it('ValidationError', function () {
try {
new LayersConfig()
Expand Down
Loading