Using single argument for callback and string for projection

This makes the asynchronous and synchronous versions of
readFeatures work with the same data structures, and leaves
projection handling outside the parsers.
This commit is contained in:
ahocevar
2013-07-24 22:19:21 +02:00
parent a4ceb41938
commit 109ec71877
6 changed files with 48 additions and 55 deletions
+5 -6
View File
@@ -423,8 +423,6 @@ ol.layer.Vector.prototype.groupFeaturesBySymbolizerLiteral =
* one projection.
*/
ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
var features;
var lookup = {};
lookup[ol.geom.GeometryType.POINT] = this.pointVertices_;
lookup[ol.geom.GeometryType.LINESTRING] = this.lineVertices_;
@@ -437,10 +435,11 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
return lookup[type];
};
var addFeatures = function(features, metadata) {
var addFeatures = function(data) {
var features = data.features;
var sourceProjection = this.getSource().getProjection();
if (goog.isNull(sourceProjection)) {
sourceProjection = metadata.projection;
sourceProjection = data.metadata.projection;
}
var transform = ol.proj.getTransform(sourceProjection, projection);
@@ -472,7 +471,7 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
goog.isFunction(parser.readFeaturesWithMetadataFromString),
'Expected parser with a readFeaturesWithMetadataFromString method.');
result = parser.readFeaturesWithMetadataFromString(data, options);
addFeatures.call(this, result.features, result.metadata);
addFeatures.call(this, result);
}
} else if (goog.isObject(data)) {
if (goog.isFunction(parser.readFeaturesFromObjectAsync)) {
@@ -483,7 +482,7 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
goog.isFunction(parser.readFeaturesWithMetadataFromObject),
'Expected parser with a readFeaturesWithMetadataFromObject method.');
result = parser.readFeaturesWithMetadataFromObject(data, options);
addFeatures.call(this, result.features, result.metadata);
addFeatures.call(this, result);
}
} else {
// TODO: parse more data types