Read the metadata of a FeatureCollection
This commit is contained in:
@@ -146,9 +146,8 @@ ol.format.GML.FEATURE_COLLECTION_PARSERS = {
|
|||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
* @return {ol.geom.Geometry|undefined} Geometry.
|
* @return {ol.geom.Geometry|undefined} Geometry.
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ol.format.GML.readGeometry_ = function(node, objectStack) {
|
ol.format.GML.readGeometry = function(node, objectStack) {
|
||||||
var context = objectStack[0];
|
var context = objectStack[0];
|
||||||
goog.asserts.assert(goog.isObject(context));
|
goog.asserts.assert(goog.isObject(context));
|
||||||
goog.object.set(context, 'srsName',
|
goog.object.set(context, 'srsName',
|
||||||
@@ -188,7 +187,7 @@ ol.format.GML.readFeature_ = function(node, objectStack) {
|
|||||||
values[ol.xml.getLocalName(n)] = value;
|
values[ol.xml.getLocalName(n)] = value;
|
||||||
} else {
|
} else {
|
||||||
geometryName = ol.xml.getLocalName(n);
|
geometryName = ol.xml.getLocalName(n);
|
||||||
values[geometryName] = ol.format.GML.readGeometry_(n, objectStack);
|
values[geometryName] = ol.format.GML.readGeometry(n, objectStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var feature = new ol.Feature(values);
|
var feature = new ol.Feature(values);
|
||||||
@@ -1016,7 +1015,7 @@ ol.format.GML.RING_PARSERS_ = {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
||||||
var geometry = ol.format.GML.readGeometry_(node, [{}]);
|
var geometry = ol.format.GML.readGeometry(node, [{}]);
|
||||||
return (goog.isDef(geometry)) ? geometry : null;
|
return (goog.isDef(geometry)) ? geometry : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,72 @@ ol.format.WFS.prototype.readTransactionResponse = function(source) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @return {Object|undefined} FeatureCollection metadata.
|
||||||
|
*/
|
||||||
|
ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) {
|
||||||
|
if (ol.xml.isDocument(source)) {
|
||||||
|
return this.readFeatureCollectionMetadataFromDocument(
|
||||||
|
/** @type {Document} */ (source));
|
||||||
|
} else if (ol.xml.isNode(source)) {
|
||||||
|
return this.readFeatureCollectionMetadataFromNode(
|
||||||
|
/** @type {Node} */ (source));
|
||||||
|
} else if (goog.isString(source)) {
|
||||||
|
var doc = ol.xml.load(source);
|
||||||
|
return this.readFeatureCollectionMetadataFromDocument(doc);
|
||||||
|
} else {
|
||||||
|
goog.asserts.fail();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Document} doc Document.
|
||||||
|
* @return {Object|undefined} FeatureCollection metadata.
|
||||||
|
*/
|
||||||
|
ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument =
|
||||||
|
function(doc) {
|
||||||
|
goog.asserts.assert(doc.nodeType == goog.dom.NodeType.DOCUMENT);
|
||||||
|
for (var n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
|
||||||
|
if (n.nodeType == goog.dom.NodeType.ELEMENT) {
|
||||||
|
return this.readFeatureCollectionMetadataFromNode(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = {
|
||||||
|
'http://www.opengis.net/gml': {
|
||||||
|
'boundedBy': ol.xml.makeObjectPropertySetter(
|
||||||
|
ol.format.GML.readGeometry, 'bounds')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @return {Object|undefined} FeatureCollection metadata.
|
||||||
|
*/
|
||||||
|
ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
|
||||||
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
|
goog.asserts.assert(node.localName == 'FeatureCollection');
|
||||||
|
var result = {};
|
||||||
|
var value = ol.format.XSD.readNonNegativeIntegerString(
|
||||||
|
node.getAttribute('numberOfFeatures'));
|
||||||
|
goog.object.set(result, 'numberOfFeatures', value);
|
||||||
|
return ol.xml.pushParseAndPop(
|
||||||
|
result, ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
|||||||
@@ -33,6 +33,43 @@ describe('ol.format.WFS', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when parsing FeatureCollection', function() {
|
||||||
|
var response;
|
||||||
|
before(function(done) {
|
||||||
|
afterLoadText('spec/ol/format/wfs/NumberOfFeatures.xml',
|
||||||
|
function(xml) {
|
||||||
|
try {
|
||||||
|
response = new ol.format.WFS().readFeatureCollectionMetadata(xml);
|
||||||
|
} catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('returns the correct number of features', function() {
|
||||||
|
expect(response.numberOfFeatures).to.equal(625);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when parsing FeatureCollection', function() {
|
||||||
|
var response;
|
||||||
|
before(function(done) {
|
||||||
|
afterLoadText('spec/ol/format/wfs/boundedBy.xml',
|
||||||
|
function(xml) {
|
||||||
|
try {
|
||||||
|
response = new ol.format.WFS().readFeatureCollectionMetadata(xml);
|
||||||
|
} catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('returns the correct bounds', function() {
|
||||||
|
expect(response.bounds).to.eql([3197.88, 306457.313,
|
||||||
|
280339.156, 613850.438]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when parsing TransactionResponse', function() {
|
describe('when parsing TransactionResponse', function() {
|
||||||
var response;
|
var response;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user