the old-but-still-used GML format creates features with geometries of type OpenLayers.Bounds, p=fvanderbiest, r=me (closes #2724)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10614 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2010-08-11 14:24:51 +00:00
parent 602cf46c10
commit 5a8775cd16
3 changed files with 64 additions and 12 deletions

View File

@@ -140,7 +140,9 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
// only accept one geometry per feature - look for highest "order"
var order = ["MultiPolygon", "Polygon",
"MultiLineString", "LineString",
"MultiPoint", "Point", "Envelope", "Box"];
"MultiPoint", "Point", "Envelope"];
// FIXME: In case we parse a feature with no geometry, but boundedBy an Envelope,
// this code creates a geometry derived from the Envelope. This is not correct.
var type, nodeList, geometry, parser;
for(var i=0; i<order.length; ++i) {
type = order[i];
@@ -162,6 +164,21 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
break;
}
}
var bounds;
var boxNodes = this.getElementsByTagNameNS(node, this.gmlns, "Box");
for(i=0; i<boxNodes.length; ++i) {
var boxNode = boxNodes[i];
var box = this.parseGeometry["box"].apply(this, [boxNode]);
var parentNode = boxNode.parentNode;
var parentName = parentNode.localName ||
parentNode.nodeName.split(":").pop();
if(parentName === "boundedBy") {
bounds = box;
} else {
geometry = box.toGeometry();
}
}
// construct feature (optionally with attributes)
var attributes;
@@ -169,6 +186,7 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
attributes = this.parseAttributes(node);
}
var feature = new OpenLayers.Feature.Vector(geometry, attributes);
feature.bounds = bounds;
feature.gml = {
featureType: node.firstChild.nodeName.split(":")[1],
@@ -176,14 +194,6 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
featureNSPrefix: node.firstChild.prefix
};
var boundedByNodes = this.getElementsByTagNameNS(node, this.gmlns, 'boundedBy');
if (boundedByNodes.length === 1) {
parser = this.parseGeometry['box'];
if (parser) {
feature.bounds = parser.apply(this, [boundedByNodes[0]]);
}
}
// assign fid - this can come from a "fid" or "id" attribute
var childNode = node.firstChild;
var fid;