Add GML format test, which for the time being only has a constructor and

getFID tests, to test for broken fid parser, patch  provided by Andreas
Hocevar in #679 .


git-svn-id: http://svn.openlayers.org/trunk/openlayers@3096 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-04-26 13:31:46 +00:00
parent fc2ac2a7cf
commit 8f62eab52e
3 changed files with 66 additions and 4 deletions

View File

@@ -84,13 +84,11 @@ OpenLayers.Format.GML.prototype =
var feature = new OpenLayers.Feature.Vector();
if (xmlNode.firstChild.attributes && xmlNode.firstChild.attributes['fid']) {
feature.fid = xmlNode.firstChild.attributes['fid'].nodeValue;
}
// match MultiPolygon
if (OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, this.gmlns, "gml", "MultiPolygon").length != 0) {
var multipolygon = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, this.gmlns, "gml", "MultiPolygon")[0];
feature.fid = multipolygon.parentNode.parentNode.getAttribute('fid');
geom = new OpenLayers.Geometry.MultiPolygon();
var polygons = OpenLayers.Ajax.getElementsByTagNameNS(multipolygon,
this.gmlns, "gml", "Polygon");
@@ -104,6 +102,7 @@ OpenLayers.Format.GML.prototype =
this.gmlns, "gml", "MultiLineString").length != 0) {
var multilinestring = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
this.gmlns, "gml", "MultiLineString")[0];
feature.fid = multilinestring.parentNode.parentNode.getAttribute('fid');
geom = new OpenLayers.Geometry.MultiLineString();
var lineStrings = OpenLayers.Ajax.getElementsByTagNameNS(multilinestring, this.gmlns, "gml", "LineString");
@@ -122,6 +121,7 @@ OpenLayers.Format.GML.prototype =
this.gmlns, "gml", "MultiPoint").length != 0) {
var multiPoint = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
this.gmlns, "gml", "MultiPoint")[0];
feature.fid = multiPoint.parentNode.parentNode.getAttribute('fid');
geom = new OpenLayers.Geometry.MultiPoint();
@@ -138,6 +138,7 @@ OpenLayers.Format.GML.prototype =
this.gmlns, "gml", "Polygon").length != 0) {
var polygon = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
this.gmlns, "gml", "Polygon")[0];
feature.fid = polygon.parentNode.parentNode.getAttribute('fid');
geom = this.parsePolygonNode(polygon);
}
@@ -146,6 +147,8 @@ OpenLayers.Format.GML.prototype =
this.gmlns, "gml", "LineString").length != 0) {
var lineString = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
this.gmlns, "gml", "LineString")[0];
feature.fid = lineString.parentNode.parentNode.getAttribute('fid');
p = this.parseCoords(lineString);
if (p.points) {
geom = new OpenLayers.Geometry.LineString(p.points);
@@ -157,6 +160,7 @@ OpenLayers.Format.GML.prototype =
this.gmlns, "gml", "Point").length != 0) {
var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode,
this.gmlns, "gml", "Point")[0];
feature.fid = point.parentNode.parentNode.getAttribute('fid');
p = this.parseCoords(point);
if (p.points) {

View File

@@ -0,0 +1,57 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var test_content = '<wfs:FeatureCollection' +
' xmlns:fs="http://example.com/featureserver"' +
' xmlns:wfs="http://www.opengis.net/wfs"' +
' xmlns:gml="http://www.opengis.net/gml"' +
' xmlns:ogc="http://www.opengis.net/ogc"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd">' +
' ' +
'' +
' <gml:featureMember>' +
' \n<fs:scribble fid="221">' +
' <fs:geometry>' +
' <gml:Polygon>' +
' ' +
' <gml:outerBoundaryIs><gml:LinearRing>' +
' <gml:coordinates>149.105072021,-35.1816558838 149.100608826,-35.1844024658 149.098892212,-35.1898956299 149.105072021,-35.1816558838</gml:coordinates>' +
' </gml:LinearRing></gml:outerBoundaryIs>' +
' ' +
' </gml:Polygon>' +
' </fs:geometry>' +
' <fs:title>random test features</fs:title>' +
' </fs:scribble>' +
'</gml:featureMember> ' +
' <gml:featureMember><fs:scribble fid="8"> <fs:geometry> <gml:Point><gml:coordinates>-81.38671875,27.0703125</gml:coordinates></gml:Point> </fs:geometry> ' +
' <fs:down>south</fs:down><fs:title>Florida</fs:title> </fs:scribble></gml:featureMember>' +
'</wfs:FeatureCollection>';
function test_Format_GML_constructor(t) {
t.plan(4);
var options = {'foo': 'bar'};
var format = new OpenLayers.Format.GML(options);
t.ok(format instanceof OpenLayers.Format.GML,
"new OpenLayers.Format.GML returns object" );
t.eq(format.foo, "bar", "constructor sets options correctly");
t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function");
}
function test_Format_GML_getFid(t) {
t.plan(2);
var parser = new OpenLayers.Format.GML();
data = parser.read(test_content);
t.eq(data[0].fid, '221', 'fid on polygons set correctly (with whitespace)');
t.eq(data[1].fid, '8', 'fid on linestrings set correctly with whitespace');
}
// -->
</script>
</head>
<body>
</body>
</html>

View File

@@ -17,6 +17,7 @@
<li>Geometry/test_Rectangle.html</li>
<li>Geometry/test_Surface.html</li>
<li>test_Format.html</li>
<li>Format/test_GML.html</li>
<li>Format/test_WKT.html</li>
<li>test_Icon.html</li>
<li>test_Marker.html</li>