Added geometry parsing for Mapserver output. Thanks bartvde for the
patch. r=elemoine,me (closes #1976) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9178 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -40,6 +40,13 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
trimComma: (/\s*,\s*/g)
|
trimComma: (/\s*,\s*/g)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: gmlFormat
|
||||||
|
* {<OpenLayers.Format.GML>} internal GML format for parsing geometries
|
||||||
|
* in msGMLOutput
|
||||||
|
*/
|
||||||
|
gmlFormat: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Format.WMSGetFeatureInfo
|
* Constructor: OpenLayers.Format.WMSGetFeatureInfo
|
||||||
* Create a new parser for WMS GetFeatureInfo responses
|
* Create a new parser for WMS GetFeatureInfo responses
|
||||||
@@ -110,7 +117,7 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
if (featureNodes) {
|
if (featureNodes) {
|
||||||
for (var j = 0; j < featureNodes.length; j++) {
|
for (var j = 0; j < featureNodes.length; j++) {
|
||||||
var featureNode = featureNodes[j];
|
var featureNode = featureNodes[j];
|
||||||
var geom = null;
|
var geom = this.parseGeometry(featureNode);
|
||||||
var attributes = this.parseAttributes(featureNode);
|
var attributes = this.parseAttributes(featureNode);
|
||||||
var feature = new OpenLayers.Feature.Vector(geom,
|
var feature = new OpenLayers.Feature.Vector(geom,
|
||||||
attributes, null);
|
attributes, null);
|
||||||
@@ -239,6 +246,31 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
return attributes;
|
return attributes;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: parseGeometry
|
||||||
|
* Parse the geometry out of the node using Format.GML
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* node - {<DOMElement>}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {<OpenLayers.Geometry>} 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"
|
CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo"
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_read_msGMLOutput(t) {
|
function test_read_msGMLOutput(t) {
|
||||||
t.plan(6);
|
t.plan(7);
|
||||||
|
|
||||||
var parser = new OpenLayers.Format.WMSGetFeatureInfo();
|
var parser = new OpenLayers.Format.WMSGetFeatureInfo();
|
||||||
|
|
||||||
@@ -163,6 +163,38 @@
|
|||||||
t.eq((features[0].type == features[1].type), false,
|
t.eq((features[0].type == features[1].type), false,
|
||||||
"The layer name differs for the two features");
|
"The layer name differs for the two features");
|
||||||
|
|
||||||
|
text =
|
||||||
|
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
|
||||||
|
'<msGMLOutput ' +
|
||||||
|
' xmlns:gml="http://www.opengis.net/gml"' +
|
||||||
|
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
|
||||||
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||||
|
' <wegbeheerderinfo_layer>' +
|
||||||
|
' <wegbeheerderinfo_feature>' +
|
||||||
|
' <gml:boundedBy>' +
|
||||||
|
' <gml:Box srsName="EPSG:28992">' +
|
||||||
|
' <gml:coordinates>105002.943000,490037.863000 105271.523000,490262.208000</gml:coordinates>' +
|
||||||
|
' </gml:Box>' +
|
||||||
|
' </gml:boundedBy>' +
|
||||||
|
' <geometry>' +
|
||||||
|
' <gml:MultiLineString srsName="EPSG:28992">' +
|
||||||
|
' <gml:lineStringMember>' +
|
||||||
|
' <gml:LineString>' +
|
||||||
|
' <gml:coordinates>105270.164000,490262.208000 105098.274000,490258.040000 105028.045000,490089.576000 105002.943000,490048.851000 105049.666000,490037.863000 105271.523000,490064.957000 </gml:coordinates>' +
|
||||||
|
' </gml:LineString>' +
|
||||||
|
' </gml:lineStringMember>' +
|
||||||
|
' </gml:MultiLineString>' +
|
||||||
|
' </geometry>' +
|
||||||
|
' <OGR_FID>203327</OGR_FID>' +
|
||||||
|
' </wegbeheerderinfo_feature>' +
|
||||||
|
' </wegbeheerderinfo_layer>' +
|
||||||
|
'</msGMLOutput>';
|
||||||
|
|
||||||
|
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) {
|
function test_read_GMLFeatureInfoResponse(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user