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
This commit is contained in:
ahocevar
2009-06-23 20:34:27 +00:00
parent 253a8bbaf7
commit 9d74c087ce
2 changed files with 376 additions and 12 deletions

View File

@@ -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);
},
/**

View File

@@ -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.");
}
</script>
</head>
<body>
<!--
OGC example below taken from
http://schemas.opengis.net/wms/1.1.1/capabilities_1_1_1.xml
Copyright © 1994-2008 Open Geospatial Consortium, Inc. All Rights Reserved.
http://www.opengeospatial.org/ogc/document
Changes:
* fixed DTD URL
* removed comments
-->
<div id="ogcsample"><!--
<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM
"http://schemas.opengis.net/wms/1.1.1/capabilities_1_1_1.dtd"
[
<!ELEMENT VendorSpecificCapabilities EMPTY>
]>
<WMT_MS_Capabilities version="1.1.1" updateSequence="0">
<Service>
<Name>OGC:WMS</Name>
<Title>Acme Corp. Map Server</Title>
<Abstract>WMT Map Server maintained by Acme Corporation. Contact: webmaster@wmt.acme.com. High-quality maps showing roadrunner nests and possible ambush locations.</Abstract>
<KeywordList>
<Keyword>bird</Keyword>
<Keyword>roadrunner</Keyword>
<Keyword>ambush</Keyword>
</KeywordList>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple"
xlink:href="http://hostname/" />
<ContactInformation>
<ContactPersonPrimary>
<ContactPerson>Jeff deLaBeaujardiere</ContactPerson>
<ContactOrganization>NASA</ContactOrganization>
</ContactPersonPrimary>
<ContactPosition>Computer Scientist</ContactPosition>
<ContactAddress>
<AddressType>postal</AddressType>
<Address>NASA Goddard Space Flight Center, Code 933</Address>
<City>Greenbelt</City>
<StateOrProvince>MD</StateOrProvince>
<PostCode>20771</PostCode>
<Country>USA</Country>
</ContactAddress>
<ContactVoiceTelephone>+1 301 286-1569</ContactVoiceTelephone>
<ContactFacsimileTelephone>+1 301 286-1777</ContactFacsimileTelephone>
<ContactElectronicMailAddress>delabeau@iniki.gsfc.nasa.gov</ContactElectronicMailAddress>
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>none</AccessConstraints>
</Service>
<Capability>
<Request>
<GetCapabilities>
<Format>application/vnd.ogc.wms_xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://hostname:port/path" />
</Get>
<Post>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://hostname:port/path" />
</Post>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/gif</Format>
<Format>image/png</Format>
<Format>image/jpeg</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://hostname:port/path" />
</Get>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>application/vnd.ogc.gml</Format>
<Format>text/plain</Format>
<Format>text/html</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://hostname:port/path" />
</Get>
</HTTP>
</DCPType>
</GetFeatureInfo>
<DescribeLayer>
<Format>application/vnd.ogc.gml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://hostname:port/path" />
</Get>
</HTTP>
</DCPType>
</DescribeLayer>
</Request>
<Exception>
<Format>application/vnd.ogc.se_xml</Format>
<Format>application/vnd.ogc.se_inimage</Format>
<Format>application/vnd.ogc.se_blank</Format>
</Exception>
<VendorSpecificCapabilities />
<UserDefinedSymbolization SupportSLD="1" UserLayer="1" UserStyle="1"
RemoteWFS="1" />
<Layer>
<Title>Acme Corp. Map Server</Title>
<SRS>EPSG:4326</SRS>
<AuthorityURL name="DIF_ID">
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple"
xlink:href="http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html" />
</AuthorityURL>
<Layer>
<Name>ROADS_RIVERS</Name>
<Title>Roads and Rivers</Title>
<SRS>EPSG:26986</SRS>
<LatLonBoundingBox minx="-71.63" miny="41.75" maxx="-70.78" maxy="42.90"/>
<BoundingBox SRS="EPSG:4326"
minx="-71.63" miny="41.75" maxx="-70.78" maxy="42.90" resx="0.01" resy="0.01"/>
<BoundingBox SRS="EPSG:26986"
minx="189000" miny="834000" maxx="285000" maxy="962000" resx="1" resy="1" />
<Attribution>
<Title>State College University</Title>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple"
xlink:href="http://www.university.edu/" />
<LogoURL width="100" height="100">
<Format>image/gif</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.university.edu/icons/logo.gif" />
</LogoURL>
</Attribution>
<Identifier authority="DIF_ID">123456</Identifier>
<FeatureListURL>
<Format>application/vnd.ogc.se_xml"</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple"
xlink:href="http://www.university.edu/data/roads_rivers.gml" />
</FeatureListURL>
<Style>
<Name>USGS</Name>
<Title>USGS Topo Map Style</Title>
<Abstract>Features are shown in a style like that used in USGS topographic maps.</Abstract>
<LegendURL width="72" height="72">
<Format>image/gif</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.university.edu/legends/usgs.gif" />
</LegendURL>
<StyleSheetURL>
<Format>text/xsl</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.university.edu/stylesheets/usgs.xsl" />
</StyleSheetURL>
</Style>
<ScaleHint min="4000" max="35000"></ScaleHint>
<Layer queryable="1">
<Name>ROADS_1M</Name>
<Title>Roads at 1:1M scale</Title>
<Abstract>Roads at a scale of 1 to 1 million.</Abstract>
<KeywordList>
<Keyword>road</Keyword>
<Keyword>transportation</Keyword>
<Keyword>atlas</Keyword>
</KeywordList>
<Identifier authority="DIF_ID">123456</Identifier>
<MetadataURL type="FGDC">
<Format>text/plain</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.university.edu/metadata/roads.txt" />
</MetadataURL>
<MetadataURL type="FGDC">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.university.edu/metadata/roads.xml" />
</MetadataURL>
<Style>
<Name>ATLAS</Name>
<Title>Road atlas style</Title>
<Abstract>Roads are shown in a style like that used in a commercial road atlas.</Abstract>
<LegendURL width="72" height="72">
<Format>image/gif</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.university.edu/legends/atlas.gif" />
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>RIVERS_1M</Name>
<Title>Rivers at 1:1M scale</Title>
<Abstract>Rivers at a scale of 1 to 1 million.</Abstract>
<KeywordList>
<Keyword>river</Keyword>
<Keyword>canal</Keyword>
<Keyword>waterway</Keyword>
</KeywordList>
</Layer>
</Layer>
<Layer queryable="1">
<Title>Weather Forecast Data</Title>
<SRS>EPSG:4326</SRS>
<LatLonBoundingBox minx="-180" miny="-90" maxx="180" maxy="90" />
<Dimension name="time" units="ISO8601" />
<Extent name="time" default="2000-08-22">1999-01-01/2000-08-22/P1D</Extent>
<Layer>
<Name>Clouds</Name>
<Title>Forecast cloud cover</Title>
</Layer>
<Layer>
<Name>Temperature</Name>
<Title>Forecast temperature</Title>
</Layer>
<Layer>
<Name>Pressure</Name>
<Title>Forecast barometric pressure</Title>
<Dimension name="time" units="ISO8601" />
<Dimension name="elevation" units="EPSG:5030" />
<Extent name="time" default="2000-08-22">1999-01-01/2000-08-22/P1D</Extent>
<Extent name="elevation" default="0" nearestValue="1">0,1000,3000,5000,10000</Extent>
</Layer>
</Layer>
<Layer opaque="1" noSubsets="1" fixedWidth="512" fixedHeight="256">
<Name>ozone_image</Name>
<Title>Global ozone distribution (1992)</Title>
<LatLonBoundingBox minx="-180" miny="-90" maxx="180" maxy="90" />
<Extent name="time" default="1992">1992</Extent>
</Layer>
<Layer cascaded="1">
<Name>population</Name>
<Title>World population, annual</Title>
<LatLonBoundingBox minx="-180" miny="-90" maxx="180" maxy="90" />
<Extent name="time" default="2000">1990/2000/P1Y</Extent>
</Layer>
</Layer>
</Capability>
</WMT_MS_Capabilities>
--></div>
</body>
</html>