Correctly parse feature attributes when the attribute name matches the feature type name. r=bartvde (closes #2435)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10027 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -331,12 +331,17 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
// geometry or attributes.
|
||||
var name;
|
||||
var local = node.localName || node.nodeName.split(":").pop();
|
||||
if (!this.singleFeatureType &&
|
||||
(OpenLayers.Util.indexOf(this.featureType, local) != -1)) {
|
||||
// Since an attribute can have the same name as the feature type
|
||||
// we only want to read the node as a feature if the parent
|
||||
// node can have feature nodes as children. In this case, the
|
||||
// obj.features property is set.
|
||||
if (obj.features) {
|
||||
if (!this.singleFeatureType &&
|
||||
(OpenLayers.Util.indexOf(this.featureType, local) !== -1)) {
|
||||
name = "_typeName";
|
||||
}
|
||||
else if(local == this.featureType) {
|
||||
name = "_typeName";
|
||||
} else if(local === this.featureType) {
|
||||
name = "_typeName";
|
||||
}
|
||||
} else {
|
||||
// Assume attribute elements have one child node and that the child
|
||||
// is a text node. Otherwise assume it is a geometry node.
|
||||
|
||||
@@ -244,6 +244,24 @@
|
||||
t.eq(attr.foo, undefined, "bogus attribute is undefined");
|
||||
t.eq(attr.empty, "", "empty attribute value is empty string");
|
||||
}
|
||||
|
||||
function test_repeatedName(t) {
|
||||
// test that if an attribute name matches the featureType, all goes well
|
||||
t.plan(2);
|
||||
var doc = readXML("v3/repeated-name.xml");
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "zoning",
|
||||
featureNS: "http://opengeo.org/#medford",
|
||||
geometryName: "the_geom",
|
||||
xy: false
|
||||
});
|
||||
var features = format.read(doc.documentElement);
|
||||
|
||||
t.eq(features.length, 1, "read one feature");
|
||||
var atts = features[0].attributes;
|
||||
t.eq(atts.zoning, "I-L", "correct zoning attribute on zoning feature type");
|
||||
|
||||
}
|
||||
|
||||
function test_write(t) {
|
||||
t.plan(1);
|
||||
@@ -724,5 +742,49 @@
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
<div id="v3/repeated-name.xml"><!--
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wfs:FeatureCollection numberOfFeatures="1" timeStamp="2010-01-29T15:10:38.921-07:00"
|
||||
xsi:schemaLocation="http://medford.opengeo.org http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=medford%3Azoning http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd"
|
||||
xmlns:ogc="http://www.opengis.net/ogc"
|
||||
xmlns:wfs="http://www.opengis.net/wfs"
|
||||
xmlns:medford="http://opengeo.org/#medford"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:ows="http://www.opengis.net/ows"
|
||||
xmlns:gml="http://www.opengis.net/gml"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<gml:featureMembers>
|
||||
<medford:zoning gml:id="zoning.1">
|
||||
<medford:the_geom>
|
||||
<gml:MultiSurface srsName="urn:x-ogc:def:crs:EPSG:4326">
|
||||
<gml:surfaceMember>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>42.397027571297585 -122.88465674265922 42.39702893980587 -122.88509730796012 42.397029086785146 -122.88511582432085 42.39702379767053 -122.88528111596624 42.39748517484964 -122.88529300380065 42.39748473847452 -122.88509914138723 42.39748482219041 -122.8849959517568 42.397485082635576 -122.8846741899541 42.3974853307826 -122.88436529392652 42.39702663751206 -122.88435664014142 42.397027571297585 -122.88465674265922</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
</gml:surfaceMember>
|
||||
</gml:MultiSurface>
|
||||
</medford:the_geom>
|
||||
<medford:objectid>1</medford:objectid>
|
||||
<medford:cityzone>YES</medford:cityzone>
|
||||
<medford:zoning>I-L</medford:zoning>
|
||||
<medford:revdate>2004-04-12T00:00:00-06:00</medford:revdate>
|
||||
<medford:finord></medford:finord>
|
||||
<medford:filenum></medford:filenum>
|
||||
<medford:acres>0.95741118624</medford:acres>
|
||||
<medford:misc></medford:misc>
|
||||
<medford:shape_leng>835.705330224</medford:shape_leng>
|
||||
<medford:perimeter>835.705330224</medford:perimeter>
|
||||
<medford:area>41704.8312728</medford:area>
|
||||
<medford:shape_le_1>835.705330224</medford:shape_le_1>
|
||||
<medford:shape_area>41704.8312728</medford:shape_area>
|
||||
<medford:hectares>0.38745056079</medford:hectares>
|
||||
</medford:zoning>
|
||||
</gml:featureMembers>
|
||||
</wfs:FeatureCollection>
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user