diff --git a/lib/OpenLayers/Format/WCSCapabilities/v1.js b/lib/OpenLayers/Format/WCSCapabilities/v1.js index 47aa0b9411..54d2f3e0b7 100644 --- a/lib/OpenLayers/Format/WCSCapabilities/v1.js +++ b/lib/OpenLayers/Format/WCSCapabilities/v1.js @@ -28,6 +28,11 @@ OpenLayers.Format.WCSCapabilities.v1 = OpenLayers.Class( ows: "http://www.opengis.net/ows" }, + regExes: { + trimSpace: (/^\s*|\s*$/g), + splitSpace: (/\s+/) + }, + /** * Property: defaultPrefix */ @@ -78,16 +83,6 @@ OpenLayers.Format.WCSCapabilities.v1 = OpenLayers.Class( "WCS_Capabilities": function(node, obj) { // In 1.0.0, this was WCS_Capabilties, changed in 1.1.0 this.readChildNodes(node, obj); }, - "Name": function(node, obj) { //???? - var name = this.getChildValue(node); - if(name) { - var parts = name.split(":"); - obj.name = parts.pop(); - if(parts.length > 0) { - obj.featureNS = this.lookupNamespaceURI(node, parts[0]); - } - } - }, "Title": function(node, obj) { var title = this.getChildValue(node); if(title) { diff --git a/lib/OpenLayers/Format/WCSCapabilities/v1_0_0.js b/lib/OpenLayers/Format/WCSCapabilities/v1_0_0.js index e5d0803b62..d175f2a9f3 100644 --- a/lib/OpenLayers/Format/WCSCapabilities/v1_0_0.js +++ b/lib/OpenLayers/Format/WCSCapabilities/v1_0_0.js @@ -36,59 +36,142 @@ OpenLayers.Format.WCSCapabilities.v1_0_0 = OpenLayers.Class( */ readers: { "wcs": OpenLayers.Util.applyDefaults({ - "Service": function(node, capabilities) { - capabilities.service = {}; - this.readChildNodes(node, capabilities.service); + "Service": function(node, obj) { + obj.service = {}; + this.readChildNodes(node, obj.service); }, - "Fees": function(node, service) { - var fees = this.getChildValue(node); - if (fees && fees.toLowerCase() != "none") { - service.fees = fees; - } + "name": function(node, service) { + service.name = this.getChildValue(node); }, - "AccessConstraints": function(node, service) { - var constraints = this.getChildValue(node); - if (constraints && constraints.toLowerCase() != "none") { - service.accessConstraints = constraints; - } + "label": function(node, service) { + service.label = this.getChildValue(node); }, - "OnlineResource": function(node, service) { - var onlineResource = this.getChildValue(node); - if (onlineResource && onlineResource.toLowerCase() != "none") { - service.onlineResource = onlineResource; - } + "keywords": function(node, service) { + service.keywords = []; + this.readChildNodes(node, service.keywords); }, - "Keywords": function(node, service) { - var keywords = this.getChildValue(node); - if (keywords && keywords.toLowerCase() != "none") { - service.keywords = keywords.split(', '); - } + "keyword": function(node, keywords) { + keywords.push(this.getChildValue(node)); // Append the keyword to the keywords list }, - "Capability": function(node, capabilities) { - capabilities.capability = {}; - this.readChildNodes(node, capabilities.capability); + "responsibleParty": function(node, service) { + service.responsibleParty = {}; + this.readChildNodes(node, service.responsibleParty); }, - "Request": function(node, obj) { - obj.request = {}; - this.readChildNodes(node, obj.request); + "individualName": function(node, responsibleParty) { + responsibleParty.individualName = this.getChildValue(node); }, - "GetFeature": function(node, request) { - request.getfeature = { - href: {}, // DCPType - formats: [] // ResultFormat - }; - this.readChildNodes(node, request.getfeature); + "organisationName": function(node, responsibleParty) { + responsibleParty.organisationName = this.getChildValue(node); }, - "ResultFormat": function(node, obj) { - var children = node.childNodes; - var childNode; - for(var i=0; i. Only write the data if everything parsed neatly. + // This works well for the data samples I have access to, but may need to be generalized to cover other possible use cases. + var nodeList = this.getElementsByTagNameNS(node, "http://www.opengis.net/gml", "pos"); + + // We expect two nodes here, to create the corners of a bounding box + if(nodeList.length == 2) { + var min = {}, + max = {}; + + var ok = true; + + // min + var coordString = nodeList[0].firstChild.nodeValue; + + coordString = coordString.replace(this.regExes.trimSpace, ""); + var coords = coordString.split(this.regExes.splitSpace); + + if(coords.length == 2) { + min.lon = coords[0]; + min.lat = coords[1]; + } else { + ok = false; + } + + // max + var coordString = nodeList[1].firstChild.nodeValue; + + coordString = coordString.replace(this.regExes.trimSpace, ""); + var coords = coordString.split(this.regExes.splitSpace); + + if(coords.length == 2) { + max.lon = coords[0]; + max.lat = coords[1]; + } else { + ok = false; + } + + if(ok) { + coverageOfferingBrief.lonLatEnvelope = {}; + coverageOfferingBrief.lonLatEnvelope.srsName = node.getAttribute("srsName"); + coverageOfferingBrief.lonLatEnvelope.min = min; + coverageOfferingBrief.lonLatEnvelope.max = max; } } + }, + + //////////////////////////////////////////////////////////////////////////////////////////// + + "DCPType": function(node, obj) { this.readChildNodes(node, obj); }, diff --git a/tests/Format/WCSCapabilities/v1.html b/tests/Format/WCSCapabilities/v1.html index ea4dd1129c..24bc5ec2d7 100644 --- a/tests/Format/WCSCapabilities/v1.html +++ b/tests/Format/WCSCapabilities/v1.html @@ -21,26 +21,41 @@ } function test_read(t) { - t.plan(37); // Number of tests performed: If you add a test below, be sure to increment this accordingly + t.plan(25); // Number of tests performed: If you add a test below, be sure to increment this accordingly var parser = new OpenLayers.Format.WCSCapabilities(); // GeoServer, v1.0.0 - var text = 'MapServer WCSGeospatial WebServicesLuxembourg!Franko LemmerCRP Henri TudorR+D engineer00352 4321 234500352 43210 123
128, rue de LuxembourgEsch-sur-Alzette4221Luxembourgfranko.lemmer@flensburger.de
nonenone
application/vnd.ogc.se_xmlro_dsm4.44444 51.5151515.55555 52.525252ro_dsm_mini4.47489346945755 51.91594537869274.47687824892444 51.9170706688033ro_irra4.471333734139 51.9128134273834.4808508475645 51.9248713705576ro_irra_ext4.10024171314823 51.93597649928444.21909054278063 52.001415228243
'; + var text = 'MapServer WCSGeospatial WebServicesLuxembourg!Franko LemmerCRP Henri TudorR+D engineer64633206465955
66, rue de LuxembourgEsch-sur-Alzette97202Luxembourgfranko.lemmer@flensburger.de
mucho dineroOpen to the public
application/vnd.ogc.se_xmlro_dsm4.44444 51.5151515.55555 52.525252ro_dsm_mini4.47489346945755 51.91594537869274.47687824892444 51.9170706688033ro_irra4.471333734139 51.9128134273834.4808508475645 51.9248713705576ro_irra_ext4.10024171314823 51.93597649928444.21909054278063 52.001415228243
'; -debugger; var res = parser.read(text); t.ok(!res.error, "Parsing XML generated no errors"); - t.eq(res.operationsMetadata["GetFeature"].dcp.http.get[0].url, "http://services.magnificent.get.lu/cgi-bin/mapserv?", "GetFeature GET endpoint correctly parsed"); - t.eq(res.operationsMetadata["GetFeature"].dcp.http.post[0].url, "http://services.magnificent.post.lu/cgi-bin/mapserv?", "GetFeature POST endpoint correctly parsed"); - var ft = res.featureTypeList.featureTypes; - t.eq(ft.length, 4, "number of feature types correct"); - t.eq(ft[0]["label"], "Rotterdam DSM", "label of first feature type correct"); - t.eq(ft[0]["name"], "ro_dsm", "name of first feature type correct"); - t.eq(ft[0]["featureNS"], "http://www.census.gov", "ns of first feature type correct"); - t.eq(ft[0]["srs"], "urn:ogc:def:crs:OGC:1.3:CRS84", "srs of first feature type correct"); - t.eq(ft[0]["title"], "Manhattan (NY) landmarks", "title of first feature type correct"); + t.eq(res.service.fees, "mucho dinero", "Service>Fees correctly parsed"); + t.eq(res.service.accessConstraints, "Open to the public", "Service>AccessConstraints correctly parsed"); + t.eq(res.service.keywords.length, 2, "Correct number of Service>Keywords found"); + t.eq(res.service.keywords[0], "Geospatial WebServices", "Service>Keywords correctly parsed"); + t.eq(res.service.label, "WCS Sample Data Server 1.0.0", "Service>Label correctly parsed"); + t.eq(res.service.name, "MapServer WCS", "Service>Name correctly parsed"); + t.eq(res.service.responsibleParty.individualName, "Franko Lemmer", "Service>ResponsibleParty>IndividualName correctly parsed"); + t.eq(res.service.responsibleParty.organisationName, "CRP Henri Tudor", "Service>ResponsibleParty>OrganisationName correctly parsed"); + t.eq(res.service.responsibleParty.positionName, "R+D engineer", "Service>ResponsibleParty>PositionName correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.address.city, "Esch-sur-Alzette", "Service>responsibleParty>ContactInfo>Address>City correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.address.country, "Luxembourg", "Service>responsibleParty>ContactInfo>Address>Country correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.address.deliveryPoint, "66, rue de Luxembourg", "Service>responsibleParty>ContactInfo>Address>DeliveryPoint correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.address.electronicMailAddress, "franko.lemmer@flensburger.de", "Service>responsibleParty>ContactInfo>Address>ElectronicMailAddress correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.address.postalCode, "97202", "Service>responsibleParty>ContactInfo>Address>PostalCode correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.phone.facsimile, "6465955", "Service>responsibleParty>ContactInfo>Phone>Facsimile correctly parsed"); + t.eq(res.service.responsibleParty.contactInfo.phone.voice, "6463320", "Service>responsibleParty>ContactInfo>Phone>Voice correctly parsed"); + t.eq(res.contentMetadata.length, 4, "Correct number of metadata records found"); + t.eq(res.contentMetadata[0].label, "Rotterdam DSM", "ContentMetadata>Label correctly parsed"); + t.eq(res.contentMetadata[0].lonLatEnvelope.min.lat, "51.515151", "ContentMetadata>lonLatEnvelope>Min>Lat correctly parsed"); + t.eq(res.contentMetadata[0].lonLatEnvelope.min.lon, "4.44444", "ContentMetadata>lonLatEnvelope>Min>Lon correctly parsed"); + t.eq(res.contentMetadata[0].lonLatEnvelope.max.lat, "52.525252", "ContentMetadata>lonLatEnvelope>Max>Lat correctly parsed"); + t.eq(res.contentMetadata[0].lonLatEnvelope.max.lon, "5.55555", "ContentMetadata>lonLatEnvelope>Max>Lon correctly parsed"); + t.eq(res.contentMetadata[0].lonLatEnvelope.srsName, "urn:ogc:def:crs:OGC:1.3:CRS84", "ContentMetadata>lonLatEnvelope>SrsName correctly parsed"); + t.eq(res.contentMetadata[0].name, "ro_dsm", "ContentMetadata>Name correctly parsed"); + // // GeoServer, v1.0.0 // text = 'WFSGeoServer Web Feature ServiceThis is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.WFS, WMS, GEOSERVERhttp://localhost:80/geoserver/wfsNONENONEtiger:poly_landmarksManhattan (NY) landmarksManhattan landmarks, identifies water, lakes, parks, interesting buildilngsDS_poly_landmarks, poly_landmarks, landmarks, manhattanEPSG:4326tiger:poiManhattan (NY) points of interestPoints of interest in New York, New York (on Manhattan). One of the attributes contains the name of a file with a picture of the point of interest.poi, DS_poi, points_of_interest, ManhattanEPSG:4326tiger:tiger_roadsManhattan (NY) roadsHighly simplified road layout of Manhattan in New York..DS_tiger_roads, tiger_roads, roadsEPSG:4326sf:archsitesSpearfish archeological sitesSample data from GRASS, archeological sites location, Spearfish, South Dakota, USAarchsites, sfArchsites, spearfish, archeologyEPSG:26713sf:bugsitesSpearfish bug locationsSample data from GRASS, bug sites location, Spearfish, South Dakota, USAsfBugsites, bugsites, insects, spearfish, tiger_beetlesEPSG:26713sf:restrictedSpearfish restricted areasSample data from GRASS, restricted areas, Spearfish, South Dakota, USArestricted, sfRestricted, spearfish, areasEPSG:26713sf:roadsSpearfish roadsSample data from GRASS, road layout, Spearfish, South Dakota, USAsfRoads, roads, spearfishEPSG:26713sf:streamsSpearfish streamsSample data from GRASS, streams, Spearfish, South Dakota, USAsfStreams, streams, spearfishEPSG:26713topp:tasmania_citiesTasmania citiesCities in Tasmania (actually, just the capital)cities, TasmaniaEPSG:4326topp:tasmania_roadsTasmania roadsMain Tasmania roadsRoads, TasmaniaEPSG:4326topp:tasmania_state_boundariesTasmania state boundariesTasmania state boundariestasmania_state_boundaries, Tasmania, boundariesEPSG:4326topp:tasmania_water_bodiesTasmania water bodiesTasmania water bodiesLakes, Bodies, Australia, Water, TasmaniaEPSG:4326topp:statesUSA PopulationThis is some census data on the states.census, united, boundaries, state, statesEPSG:4326tiger:giant_polygonWorld rectangleA simple rectangular polygon covering most of the world, it\'s only used for the purpose of providing a background (WMS bgcolor could be used instead)DS_giant_polygon, giant_polygonEPSG:4326absabs_2abs_3abs_4acosAreaasinatanatan2betweenboundaryboundaryDimensionbufferbufferWithSegmentsceilcentroidclassifyCollection_AverageCollection_BoundsCollection_CountCollection_MaxCollection_MedianCollection_MinCollection_SumCollection_UniqueConcatenatecontainsconvexHullcoscrossesdateFormatdateParsedifferencedimensiondisjointdistancedouble2boolendPointenvelopeEqualIntervalequalsExactequalsExactToleranceequalToexpexteriorRingfloorgeometryTypegeomFromWKTgeomLengthgetGeometryNgetXgetYgetZgreaterEqualThangreaterThanidIEEEremainderif_then_elsein10in2in3in4in5in6in7in8in9int2bboolint2ddoubleinteriorPointinteriorRingNintersectionintersectsisClosedisEmptyisLikeisNullisRingisSimpleisValidisWithinDistancelengthlessEqualThanlessThanlogmaxmax_2max_3max_4minmin_2min_3min_4notnotEqualTonumGeometriesnumInteriorRingnumPointsoverlapsparseBooleanparseDoubleparseIntpipointNpowPropertyExistsQuantilerandomrelaterelatePatternrintroundround_2roundDoublesinsqrtStandardDeviationstartPointstrConcatstrEndsWithstrEqualsIgnoreCasestrIndexOfstrLastIndexOfstrLengthstrMatchesstrReplacestrStartsWithstrSubstringstrSubstringStartstrToLowerCasestrToUpperCasestrTrimsymDifferencetantoDegreestoRadianstouchestoWKTunionUniqueIntervalwithin';