From 9d74c087ce04c1a15007f0f5cd5209449c12178c Mon Sep 17 00:00:00 2001 From: ahocevar Date: Tue, 23 Jun 2009 20:34:27 +0000 Subject: [PATCH] added parsing of Attribution, KeywordList and MetadataURL to WMSCapabilities. Thanks tschaub for the improvements to my original patch. r=tschaub (closes #2145) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9499 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/WMSCapabilities/v1_1.js | 68 +++- tests/Format/WMSCapabilities/v1_1_1.html | 320 +++++++++++++++++- 2 files changed, 376 insertions(+), 12 deletions(-) diff --git a/lib/OpenLayers/Format/WMSCapabilities/v1_1.js b/lib/OpenLayers/Format/WMSCapabilities/v1_1.js index 9e7392af18..8ea5664e53 100644 --- a/lib/OpenLayers/Format/WMSCapabilities/v1_1.js +++ b/lib/OpenLayers/Format/WMSCapabilities/v1_1.js @@ -98,8 +98,11 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class( * Method: read_cap_Format */ read_cap_Format: function(obj, node) { + var format = this.getChildValue(node); if(obj.formats) { - obj.formats.push(this.getChildValue(node)); + obj.formats.push(format); + } else { + obj.format = format; } }, @@ -131,6 +134,8 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class( var layer = { formats: capability.request.getmap.formats || [], styles: [], + metadataURLs: [], + keywords: [], queryable: (node.getAttribute("queryable") === "1" || node.getAttribute("queryable") === "true") }; @@ -216,6 +221,53 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class( } }, + /** + * Method: read_cap_Attribution + */ + read_cap_Attribution: function(obj, node) { + var attribution = {}; + this.runChildNodes(attribution, node); + obj.attribution = attribution; + }, + + /** + * Method: read_cap_LogoURL + */ + read_cap_LogoURL: function(obj, node) { + obj.logo = { + width: node.getAttribute("width"), + height: node.getAttribute("height") + }; + this.runChildNodes(obj.logo, node); + }, + + /** + * Method: read_cap_MetadataURL + */ + read_cap_MetadataURL: function(layer, node) { + var metadataURL = {}; + this.runChildNodes(metadataURL, node); + metadataURL.type = node.getAttribute("type"); + layer.metadataURLs.push(metadataURL); + }, + + /** + * Method: read_cap_KeywordList + */ + read_cap_KeywordList: function(layer, node) { + var obj = layer; + this.runChildNodes(obj, node); + }, + + /** + * Method: read_cap_Keyword + */ + read_cap_Keyword: function(obj, node) { + if(obj.keywords) { + obj.keywords.push(this.getChildValue(node)); + } + }, + /** * Method: read_cap_LatLonBoundingBox */ @@ -227,7 +279,7 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class( parseFloat(node.getAttribute("maxy")) ]; }, - + /** * Method: read_cap_Style */ @@ -241,15 +293,11 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class( * Method: read_cap_LegendURL */ read_cap_LegendURL: function(style, node) { - var legend = { - width: node.getAttribute('width'), - height: node.getAttribute('height') + style.legend = { + width: node.getAttribute("width"), + height: node.getAttribute("height") }; - var links = node.getElementsByTagName("OnlineResource"); - if(links.length > 0) { - this.read_cap_OnlineResource(legend, links[0]); - } - style.legend = legend; + this.runChildNodes(style.legend, node); }, /** diff --git a/tests/Format/WMSCapabilities/v1_1_1.html b/tests/Format/WMSCapabilities/v1_1_1.html index 55c78f77d9..e0712c464c 100644 --- a/tests/Format/WMSCapabilities/v1_1_1.html +++ b/tests/Format/WMSCapabilities/v1_1_1.html @@ -6,8 +6,8 @@ function test_read(t) { - t.plan(13); - + t.plan(14); + var format = new OpenLayers.Format.WMSCapabilities(); var obj = format.read(doc); @@ -45,13 +45,329 @@ "http://publicus.opengeo.org:80/geoserver/wms/GetLegendGraphic?VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=tiger:tiger_roads", "[2] correct legend url" ); + t.eq( + layer.styles[0].legend.format, "image/png", + "[2] correct legend format" + ); t.eq(layer.queryable, true, "[2] correct queryable attribute"); } + function test_ogc(t) { + t.plan(12) + + var xml = document.getElementById("ogcsample").firstChild.nodeValue; + var doc = new OpenLayers.Format.XML().read(xml); + + var obj = new OpenLayers.Format.WMSCapabilities().read(doc); + var capability = obj.capability; + + var attribution = capability.layers[2].attribution; + t.eq(attribution.title, "State College University", "attribution title parsed correctly."); + t.eq(attribution.href, "http://www.university.edu/", "attribution href parsed correctly.") + t.eq(attribution.logo.href, "http://www.university.edu/icons/logo.gif", "attribution logo url parsed correctly."); + t.eq(attribution.logo.format, "image/gif", "attribution logo format parsed correctly."); + t.eq(attribution.logo.width, "100", "attribution logo width parsed correctly."); + t.eq(attribution.logo.height, "100", "attribution logo height parsed correctly."); + + var keywords = capability.layers[0].keywords; + t.eq(keywords.length, 3, "layer has 3 keywords."); + t.eq(keywords[0], "road", "1st keyword parsed correctly."); + + var metadataURLs = capability.layers[0].metadataURLs; + t.eq(metadataURLs.length, 2, "layer has 2 metadata urls."); + t.eq(metadataURLs[0].type, "FGDC", "type parsed correctly."); + t.eq(metadataURLs[0].format, "text/plain", "format parsed correctly."); + t.eq(metadataURLs[0].href, "http://www.university.edu/metadata/roads.txt", "href parsed correctly."); + } + + +
+