Add preliminary read support for features

This commit is contained in:
Bart van den Eijnden committed 2014-02-24 15:25:53 +01:00
1 parent 54426133ab
commit 796e7be623
5 files changed
+1201 -3

No files matched your search

@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<gml:featureMembers xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.openplans.org/topp http://demo.opengeo.org/geoserver/wfs?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typeName=topp:states http://www.opengis.net/gml http://schemas.opengis.net/gml/3.2.1/gml.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><feature:states xmlns:feature="http://www.openplans.org/topp" fid="states.1" xmlns="http://www.opengis.net/gml"><feature:the_geom><gml:MultiSurface srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>37.5101 -88.0711 37.5831 -88.1341 37.6281 -88.1571 37.6601 -88.1591 37.7001 -88.1331 37.7351 -88.0721 37.8051 -88.0351 37.8171 -88.0861 37.8311 -88.0891 37.8271 -88.0421 37.8431 -88.0341 37.8671 -88.0751 37.8951 -88.1011 37.9061 -88.1001 37.8961 -88.0441 37.9051 -88.0261 37.9171 -88.0301 37.9231 -88.084 37.944 -88.0781 37.9291 -88.0641 37.9341 -88.0411 37.9561 -88.0421 37.9751 -88.0211 38.0081 -88.0291 38.0331 -88.0211 38.0381 -88.0411 38.0451 -88.0431 38.0541 -88.0341 38.0731 -87.9751 38.0961 -87.9641 38.0921 -88.0121 38.1031 -88.0181 38.1311 -87.9731 38.1361 -87.9501 38.1571 -87.9311 38.1711 -87.9321 38.2001 -87.9771 38.2341 -87.9861 38.2411 -87.9801 38.3041 -87.9251 38.3021 -87.9131 38.2811 -87.9141 38.3001 -87.8881 38.3151 -87.8831 38.3161 -87.8741 38.2851 -87.8631 38.2861 -87.8501 38.3521 -87.8341 38.3781 -87.7841 38.4171 -87.7481 38.4451 -87.7381 38.4571 -87.7581 38.4661 -87.7561 38.4811 -87.6921 38.5041 -87.6791 38.5001 -87.6531 38.5151 -87.6511 38.5471 -87.6721 38.5731 -87.6521 38.5931 -87.6401 38.5991 -87.6191 38.6221 -87.6281 38.6421 -87.6251 38.6721 -87.5881 38.6851 -87.5431 38.7361 -87.5081 38.7691 -87.5081 38.7761 -87.5191 38.7951 -87.5071 38.8571 -87.5501 38.8691 -87.5591 38.9041 -87.5391 38.9311 -87.5301 38.9631 -87.5331 38.9771 -87.5471 38.9941 -87.5911 38.9951 -87.5811 39.0621 -87.5851 39.0841 -87.6121 39.0881 -87.6301 39.1031 -87.6311 39.1131 -87.6621 39.1301 -87.6591 39.1461 -87.6701 39.1681 -87.6441 39.1961 -87.6071 39.1981 -87.5941 39.2081 -87.5881 39.2481 -87.5841 39.2581 -87.6061 39.2811 -87.6151 39.2971 -87.6101 39.3071 -87.6251 39.3381 -87.5971 39.3501 -87.5401 39.4771 -87.5381 39.6091 -87.5351 39.8871 -87.5351 40.1661 -87.5351 40.4831 -87.5351 40.4941 -87.5371 40.7451 -87.5321 41.0091 -87.5321 41.1731 -87.5311 41.3011 -87.5321 41.4691 -87.5321 41.7231 -87.5291 41.8471 -87.6121 42.0591 -87.6701 42.1561 -87.7601 42.3141 -87.8361 42.4891 -87.7971 42.4891 -88.1941 42.4911 -88.2971 42.4891 -88.7061 42.4901 -88.7641 42.4901 -88.9391 42.4971 -89.3591 42.4971 -89.4001 42.5031 -89.8341 42.5041 -89.9231 42.5081 -90.4191 42.5091 -90.6381 42.4941 -90.6511 42.4751 -90.6481 42.4601 -90.6051 42.4211 -90.5631 42.3881 -90.4911 42.3601 -90.4411 42.3401 -90.4271 42.2631 -90.4171 42.2421 -90.4071 42.2101 -90.3671 42.1971 -90.3231 42.1591 -90.2301 42.1221 -90.1911 42.1201 -90.1761 42.1031 -90.1661 42.0611 -90.1681 42.0331 -90.1501 41.9831 -90.1421 41.9301 -90.1541 41.8061 -90.1951 41.7811 -90.2551 41.7561 -90.3041 41.7221 -90.3261 41.6491 -90.3411 41.6021 -90.3391 41.5861 -90.3481 41.5671 -90.4231 41.5431 -90.4341 41.5271 -90.4541 41.5251 -90.5401 41.5091 -90.6001 41.4621 -90.6581 41.4501 -90.7081 41.4491 -90.7791 41.4441 -90.8441 41.4211 -90.9491 41.4311 -91.0001 41.4231 -91.0271 41.4011 -91.0551 41.3341 -91.0731 41.2671 -91.1021 41.2311 -91.1011 41.1761 -91.0561 41.1651 -91.0181 41.1441 -90.9901 41.1041 -90.9571 41.0701 -90.9541 40.9501 -90.9601 40.9231 -90.9831 40.8791 -91.0491 40.8331 -91.0881 40.7611 -91.0921 40.7051 -91.1191 40.6821 -91.1291 40.6561 -91.1621 40.6431 -91.2141 40.6391 -91.2621 40.6031 -91.3751 40.5721 -91.4111 40.5471 -91.4121 40.5281 -91.3821 40.5031 -91.3741 40.4471 -91.3851 40.4021 -91.3721 40.3921 -91.3851 40.3861 -91.4181 40.3711 -91.4481 40.3091 -91.4861 40.2511 -91.4981 40.2001 -91.5061 40.1341 -91.5161 40.0661 -91.5041 40.0051 -91.4871 39.9461 -91.4471 39.9211 -91.4301 39.9011 -91.4341 39.8851 -91.4501 39.8631 -91.4491 39.8031 -91.3811 39.7611 -91.3731 39.7241 -91.3671 39.6851 -91.3171 39.6001 -91.2031 39.5521 -91.1561 39.5281 -91.0931 39.4731 -91.0641 39.4441 -91.0361 39.4001 -90.9471 39.3501 -90.8501 39.2961 -90.7791 39.2471 -90.7381 39.2241 -90.7321 39.1951 -90.7181 39.1441 -90.7161 39.0931 -90.6901 39.0581 -90.7071 39.0371 -90.7061 38.9351 -90.6681 38.8801 -90.6271 38.8711 -90.5701 38.8911 -90.5301 38.9591 -90.4691 38.9621 -90.4131 38.9241 -90.3191 38.9241 -90.2781 38.9141 -90.2431 38.8531 -90.1321 38.8301 -90.1131 38.8001 -90.1211 38.7851 -90.1351 38.7731 -90.1631 38.7231 -90.1961 38.7001 -90.2021 38.6581 -90.1831 38.6101 -90.1831 38.5621 -90.2401 38.5321 -90.2611 38.5181 -90.2651 38.4271 -90.3011 38.3901 -90.3391 38.3651 -90.3581 38.3231 -90.3691 38.2341 -90.3641 38.1881 -90.3361 38.1661 -90.2891 38.1221 -90.2541 38.0881 -90.2071 38.0531 -90.1341 38.0321 -90.1191 37.9931 -90.0411 37.9691 -90.0101 37.9631 -89.9581 37.9111 -89.9781 37.8781 -89.9371 37.8751 -8Line truncated
+6
View File
@@ -304,6 +304,12 @@
* default style is the same as Google Earth.
*/
/**
* @typedef {Object} olx.format.GMLOptions
* @property {string} featureNS Feature namespace.
* @property {string} featureType Feature type to parse.
*/
/**
* @typedef {Object} olx.interaction.DoubleClickZoomOptions
* @property {number|undefined} duration Animation duration in milliseconds. Default is `250`.
+74 -1
View File
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.dom.TagName');
goog.require('ol.Feature');
goog.require('ol.extent');
goog.require('ol.format.XML');
goog.require('ol.geom.GeometryCollection');
@@ -20,10 +21,16 @@ goog.require('ol.xml');
/**
* @constructor
* @param {olx.format.GMLOptions=} opt_options
* Optional configuration object.
* @extends {ol.format.XML}
* @todo stability experimental
*/
ol.format.GML = function() {
ol.format.GML = function(opt_options) {
var options = /** @type {olx.format.GMLOptions} */
(goog.isDef(opt_options) ? opt_options : {});
this.featureType_ = options.featureType;
this.featureNS_ = options.featureNS;
goog.base(this);
};
goog.inherits(ol.format.GML, ol.format.XML);
@@ -39,6 +46,45 @@ ol.format.GML.NAMESPACE_URIS_ = [
];
/**
* @inheritDoc
*/
ol.format.GML.prototype.readFeaturesFromNode = function(node) {
if (goog.array.indexOf(ol.format.GML.NAMESPACE_URIS_,
this.featureNS_) === -1) {
ol.format.GML.NAMESPACE_URIS_.push(this.featureNS_);
}
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
if (goog.array.indexOf(ol.format.GML.NAMESPACE_URIS_, node.namespaceURI) ==
-1) {
return [];
}
var features;
var localName = ol.xml.getLocalName(node);
if (localName === this.featureType_) {
var feature = this.readFeature_(node, []);
if (goog.isDef(feature)) {
return [feature];
} else {
return [];
}
} else if (localName == 'featureMembers') {
features = [];
var n;
for (n = node.firstElementChild; !goog.isNull(n);
n = n.nextElementSibling) {
var fs = this.readFeaturesFromNode(n);
if (goog.isDef(fs)) {
goog.array.extend(features, fs);
}
}
return features;
} else {
return [];
}
};
/**
* @inheritDoc
*/
@@ -73,6 +119,33 @@ ol.format.GML.prototype.readGeometryFromNode = function(node) {
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {ol.Feature} Feature.
*/
ol.format.GML.prototype.readFeature_ = function(node, objectStack) {
var n;
var values = {};
for (n = node.firstElementChild; !goog.isNull(n);
n = n.nextElementSibling) {
// Assume attribute elements have one child node and that the child
// is a text node. Otherwise assume it is a geometry node.
if (n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
n.firstChild.nodeType === 3)) {
values[ol.xml.getLocalName(n)] = ol.xml.getAllTextContent(n, false);
} else {
values[ol.xml.getLocalName(n)] = this.readGeometryFromNode(n);
}
}
var feature = new ol.Feature();
feature.setValues(values);
return feature;
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
File diff suppressed because it is too large. Load diff
+24
View File
@@ -543,6 +543,30 @@ describe('ol.format.GML', function() {
});
describe('when parsing TOPP states GML', function() {
var features;
before(function(done) {
afterLoadText('spec/ol/format/gml/topp-states-gml.xml', function(xml) {
try {
var config = {
'featureNS': 'http://www.openplans.org/topp',
'featureType': 'states'
};
features = new ol.format.GML(config).readFeatures(xml);
} catch (e) {
done(e);
}
done();
});
});
it('creates 10 features', function() {
expect(features).to.have.length(10);
});
});
});