Updating the TopoJSON parser to return a ReadFeaturesResult

This commit is contained in:
ahocevar
2013-08-04 14:16:28 +02:00
parent 9578da0cfb
commit cc29ea912b
2 changed files with 10 additions and 8 deletions

View File

@@ -74,7 +74,7 @@ ol.parser.TopoJSON.prototype.concatenateArcs_ = function(indices, arcs) {
*/
ol.parser.TopoJSON.prototype.read = function(str) {
var topology = /** @type {TopoJSONTopology} */ (JSON.parse(str));
return this.readFeaturesFromObject(topology);
return this.readFeaturesFromObject(topology).features;
};
@@ -83,7 +83,7 @@ ol.parser.TopoJSON.prototype.read = function(str) {
*
* @param {string} str TopoJSON topology string.
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
* @return {Array.<ol.Feature>} Array of features.
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
*/
ol.parser.TopoJSON.prototype.readFeaturesFromString =
function(str, opt_options) {
@@ -91,7 +91,8 @@ ol.parser.TopoJSON.prototype.readFeaturesFromString =
if (topology.type !== 'Topology') {
throw new Error('Not a "Topology" type object');
}
return this.readFeaturesFromTopology_(topology, opt_options);
return {features: this.readFeaturesFromTopology_(topology, opt_options),
metadata: {projection: 'EPSG:4326'}};
};
@@ -100,14 +101,15 @@ ol.parser.TopoJSON.prototype.readFeaturesFromString =
*
* @param {TopoJSONTopology} topology TopoJSON topology object.
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
* @return {Array.<ol.Feature>} Array of features.
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
*/
ol.parser.TopoJSON.prototype.readFeaturesFromObject =
function(topology, opt_options) {
if (topology.type !== 'Topology') {
throw new Error('Not a "Topology" type object');
}
return this.readFeaturesFromTopology_(topology, opt_options);
return {features: this.readFeaturesFromTopology_(topology, opt_options),
metadata: {projection: 'EPSG:4326'}};
};

View File

@@ -79,13 +79,13 @@ describe('ol.parser.TopoJSON', function() {
};
var result = parser.readFeaturesFromString(text, {callback: callback});
expect(result.length).to.be(178);
expect(result.features.length).to.be(178);
expect(pointVertices.coordinates.length).to.be(0);
expect(lineVertices.coordinates.length).to.be(0);
expect(polygonVertices.coordinates.length).to.be(31400);
var first = result[0];
var first = result.features[0];
expect(first).to.be.a(ol.Feature);
var firstGeom = first.getGeometry();
expect(firstGeom).to.be.a(ol.geom.MultiPolygon);
@@ -93,7 +93,7 @@ describe('ol.parser.TopoJSON', function() {
-180, 180, -85.60903777459777, 83.64513000000002
]);
var last = result[177];
var last = result.features[177];
expect(last).to.be.a(ol.Feature);
var lastGeom = last.getGeometry();
expect(lastGeom).to.be.a(ol.geom.Polygon);