From 9a021c8aa42955287d6a5efbb5c7d544d0e01f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Tue, 1 Sep 2020 11:53:11 +0000 Subject: [PATCH 1/3] Update WMSCapabilities.js Fix issue when there only one single layer. --- src/ol/format/WMSCapabilities.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ol/format/WMSCapabilities.js b/src/ol/format/WMSCapabilities.js index 0ceced4465..c997feda2d 100644 --- a/src/ol/format/WMSCapabilities.js +++ b/src/ol/format/WMSCapabilities.js @@ -407,7 +407,13 @@ function readException(node, objectStack) { * @return {Object|undefined} Layer object. */ function readCapabilityLayer(node, objectStack) { - return pushParseAndPop({}, LAYER_PARSERS, node, objectStack); + const layerObject = pushParseAndPop({}, LAYER_PARSERS, node, objectStack); + + if (layerObject.Layer === undefined) { + return Object.assign(layerObject, readLayer(node, objectStack)); + } + + return layerObject; } /** From 6a811ef767ea33a9fd21c42ea24d049f2e83142f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Tue, 1 Sep 2020 11:53:49 +0000 Subject: [PATCH 2/3] Update WMS Capabilities tests Add test for WMS service with one single layer. --- test/spec/ol/format/wms/singlelayer.xml | 146 ++++++++++++++++++++ test/spec/ol/format/wmscapabilities.test.js | 37 +++++ 2 files changed, 183 insertions(+) create mode 100644 test/spec/ol/format/wms/singlelayer.xml diff --git a/test/spec/ol/format/wms/singlelayer.xml b/test/spec/ol/format/wms/singlelayer.xml new file mode 100644 index 0000000000..9feb76d839 --- /dev/null +++ b/test/spec/ol/format/wms/singlelayer.xml @@ -0,0 +1,146 @@ + + + + WMS + Acme Corp. Map Server + Map Server maintained by Acme Corporation. Contact: webmaster@wmt.acme.com. High-quality maps showing roadrunner nests and possible ambush locations. + + + bird + roadrunner + ambush + + + + + + + Jeff Smith + NASA + + Computer Scientist + + + postal +
NASA Goddard Space Flight Center
+ Greenbelt + MD + 20771 + + USA +
+ +1 301 555-1212 + user@host.com +
+ + none + + none + 16 + 2048 + 2048 +
+ + + + + text/xml + + + + + + + + + + + + + + image/gif + image/png + image/jpeg + + + + + + + + + + + + text/xml + text/plain + text/html + + + + + + + + + + + + XML + + INIMAGE + BLANK + + + ROADS_1M + Roads at 1:1M scale + Roads at a scale of 1 to 1 million. + + + road + transportation + atlas + + 123456 + + + text/plain + + + + text/xml + + + + + + + +
diff --git a/test/spec/ol/format/wmscapabilities.test.js b/test/spec/ol/format/wmscapabilities.test.js index dba7bc60ba..4ab1282068 100644 --- a/test/spec/ol/format/wmscapabilities.test.js +++ b/test/spec/ol/format/wmscapabilities.test.js @@ -160,3 +160,40 @@ describe('ol.format.WMSCapabilities', function () { }); }); }); + +describe('ol.format.WMSCapabilities', function () { + describe('when parsing singlelayer.xml', function () { + const parser = new WMSCapabilities(); + let capabilities; + before(function (done) { + afterLoadText('spec/ol/format/wms/singlelayer.xml', function (xml) { + try { + capabilities = parser.read(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('can read version', function () { + expect(capabilities.version).to.eql('1.3.0'); + }); + + it('can read Service section', function () { + // FIXME not all fields are tested + const service = capabilities.Service; + + expect(service.Name).to.eql('WMS'); + expect(service.Title).to.eql('Acme Corp. Map Server'); + }); + + it('can read Capability.Layer', function () { + const layer = capabilities.Capability.Layer; + + expect(layer.Title).to.eql('Roads at 1:1M scale'); + expect(layer.Name).to.be('ROADS_1M'); + expect(layer.queryable).to.be(true); + }); + }); +}); From eec4b46ac1242553039efbe7b7f3d82e5e6cb41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Tue, 1 Sep 2020 12:06:22 +0000 Subject: [PATCH 3/3] Update WMSCapabilities.js --- src/ol/format/WMSCapabilities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/format/WMSCapabilities.js b/src/ol/format/WMSCapabilities.js index c997feda2d..4a72564fa4 100644 --- a/src/ol/format/WMSCapabilities.js +++ b/src/ol/format/WMSCapabilities.js @@ -409,7 +409,7 @@ function readException(node, objectStack) { function readCapabilityLayer(node, objectStack) { const layerObject = pushParseAndPop({}, LAYER_PARSERS, node, objectStack); - if (layerObject.Layer === undefined) { + if (layerObject['Layer'] === undefined) { return Object.assign(layerObject, readLayer(node, objectStack)); }