diff --git a/lib/OpenLayers/Format/WMSGetFeatureInfo.js b/lib/OpenLayers/Format/WMSGetFeatureInfo.js index fa420e0483..5ecf5f2258 100644 --- a/lib/OpenLayers/Format/WMSGetFeatureInfo.js +++ b/lib/OpenLayers/Format/WMSGetFeatureInfo.js @@ -40,6 +40,13 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { trimComma: (/\s*,\s*/g) }, + /** + * Property: gmlFormat + * {} internal GML format for parsing geometries + * in msGMLOutput + */ + gmlFormat: null, + /** * Constructor: OpenLayers.Format.WMSGetFeatureInfo * Create a new parser for WMS GetFeatureInfo responses @@ -110,7 +117,7 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { if (featureNodes) { for (var j = 0; j < featureNodes.length; j++) { var featureNode = featureNodes[j]; - var geom = null; + var geom = this.parseGeometry(featureNode); var attributes = this.parseAttributes(featureNode); var feature = new OpenLayers.Feature.Vector(geom, attributes, null); @@ -239,6 +246,31 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { return attributes; }, + /** + * Method: parseGeometry + * Parse the geometry out of the node using Format.GML + * + * Parameters: + * node - {} + * + * Returns: + * {} the geometry object + */ + parseGeometry: function(node) { + // we need to use the old Format.GML parser since we do not know the + // geometry name + if (!this.gmlFormat) { + this.gmlFormat = new OpenLayers.Format.GML(); + } + var feature = this.gmlFormat.parseFeature(node); + var geometry = null; + if (feature && feature.geometry) { + geometry = feature.geometry.clone(); + feature.destroy(); + } + return geometry; + }, + CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo" }); diff --git a/tests/Format/WMSGetFeatureInfo.html b/tests/Format/WMSGetFeatureInfo.html index 8ea1346f90..07ea1716b3 100644 --- a/tests/Format/WMSGetFeatureInfo.html +++ b/tests/Format/WMSGetFeatureInfo.html @@ -52,7 +52,7 @@ } function test_read_msGMLOutput(t) { - t.plan(6); + t.plan(7); var parser = new OpenLayers.Format.WMSGetFeatureInfo(); @@ -163,6 +163,38 @@ t.eq((features[0].type == features[1].type), false, "The layer name differs for the two features"); + text = + '' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 105002.943000,490037.863000 105271.523000,490262.208000' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 105270.164000,490262.208000 105098.274000,490258.040000 105028.045000,490089.576000 105002.943000,490048.851000 105049.666000,490037.863000 105271.523000,490064.957000 ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 203327' + + ' ' + + ' ' + + ''; + + features = parser.read(text); + + t.eq((features[0].geometry instanceof OpenLayers.Geometry.MultiLineString), true, + "Parsed geometry is of type multi line string"); + } function test_read_GMLFeatureInfoResponse(t) {