Port over more test cases
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.dom');
|
goog.require('goog.dom');
|
||||||
goog.require('goog.dom.NodeType');
|
goog.require('goog.dom.NodeType');
|
||||||
goog.require('goog.dom.TagName');
|
goog.require('goog.dom.TagName');
|
||||||
|
goog.require('goog.string');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.format.XML');
|
goog.require('ol.format.XML');
|
||||||
@@ -145,7 +146,11 @@ ol.format.GML.prototype.readFeature_ = function(node, objectStack) {
|
|||||||
if (n.childNodes.length === 0 ||
|
if (n.childNodes.length === 0 ||
|
||||||
(n.childNodes.length === 1 &&
|
(n.childNodes.length === 1 &&
|
||||||
n.firstChild.nodeType === 3)) {
|
n.firstChild.nodeType === 3)) {
|
||||||
values[ol.xml.getLocalName(n)] = ol.xml.getAllTextContent(n, false);
|
var value = ol.xml.getAllTextContent(n, false);
|
||||||
|
if (goog.string.isEmpty(value)) {
|
||||||
|
value = undefined;
|
||||||
|
}
|
||||||
|
values[ol.xml.getLocalName(n)] = value;
|
||||||
} else {
|
} else {
|
||||||
geometryName = ol.xml.getLocalName(n);
|
geometryName = ol.xml.getLocalName(n);
|
||||||
values[geometryName] = this.readGeometryFromNode(n);
|
values[geometryName] = this.readGeometryFromNode(n);
|
||||||
|
|||||||
@@ -543,6 +543,35 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when parsing empty attribute', function() {
|
||||||
|
it('generates undefined value', function() {
|
||||||
|
var text =
|
||||||
|
'<gml:featureMembers xmlns:gml="http://www.opengis.net/gml">' +
|
||||||
|
' <topp:gnis_pop gml:id="gnis_pop.148604" xmlns:topp="' +
|
||||||
|
'http://www.openplans.org/topp">' +
|
||||||
|
' <gml:name>Aflu</gml:name>' +
|
||||||
|
' <topp:the_geom>' +
|
||||||
|
' <gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">' +
|
||||||
|
' <gml:pos>34.12 2.09</gml:pos>' +
|
||||||
|
' </gml:Point>' +
|
||||||
|
' </topp:the_geom>' +
|
||||||
|
' <topp:population>84683</topp:population>' +
|
||||||
|
' <topp:country>Algeria</topp:country>' +
|
||||||
|
' <topp:type>place</topp:type>' +
|
||||||
|
' <topp:name>Aflu</topp:name>' +
|
||||||
|
' <topp:empty></topp:empty>' +
|
||||||
|
' </topp:gnis_pop>' +
|
||||||
|
'</gml:featureMembers>';
|
||||||
|
var config = {
|
||||||
|
'featureNS': 'http://www.openplans.org/topp',
|
||||||
|
'featureType': 'gnis_pop'
|
||||||
|
};
|
||||||
|
var features = new ol.format.GML(config).readFeatures(text);
|
||||||
|
var feature = features[0];
|
||||||
|
expect(feature.get('empty')).to.be(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when parsing TOPP states GML', function() {
|
describe('when parsing TOPP states GML', function() {
|
||||||
|
|
||||||
var features;
|
var features;
|
||||||
@@ -597,6 +626,57 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when parsing more than one geometry', function() {
|
||||||
|
|
||||||
|
var features, feature;
|
||||||
|
before(function(done) {
|
||||||
|
afterLoadText('spec/ol/format/gml/more-geoms.xml', function(xml) {
|
||||||
|
try {
|
||||||
|
var config = {
|
||||||
|
'featureNS': 'http://opengeo.org/#medford',
|
||||||
|
'featureType': 'zoning'
|
||||||
|
};
|
||||||
|
features = new ol.format.GML(config).readFeatures(xml);
|
||||||
|
} catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates 2 geometries', function() {
|
||||||
|
var feature = features[0];
|
||||||
|
expect(feature.get('center')).to.be.a(ol.geom.Point);
|
||||||
|
expect(feature.get('the_geom')).to.be.a(ol.geom.MultiPolygon);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when parsing an attribute name equal to featureType', function() {
|
||||||
|
|
||||||
|
var features, feature;
|
||||||
|
before(function(done) {
|
||||||
|
afterLoadText('spec/ol/format/gml/repeated-name.xml', function(xml) {
|
||||||
|
try {
|
||||||
|
var config = {
|
||||||
|
'featureNS': 'http://opengeo.org/#medford',
|
||||||
|
'featureType': 'zoning'
|
||||||
|
};
|
||||||
|
features = new ol.format.GML(config).readFeatures(xml);
|
||||||
|
} catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates the correct attribute value', function() {
|
||||||
|
var feature = features[0];
|
||||||
|
expect(feature.get('zoning')).to.equal('I-L');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user