Merge pull request #2407 from ahocevar/format-projection

Options for feature readers and writers to support transforms
This commit is contained in:
Tobias Sauerwein
2014-08-21 17:58:10 +02:00
29 changed files with 1282 additions and 218 deletions

View File

@@ -3,6 +3,7 @@ goog.provide('ol.format.TopoJSON');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.Feature');
goog.require('ol.format.Feature');
goog.require('ol.format.JSONFeature');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
@@ -30,11 +31,11 @@ ol.format.TopoJSON = function(opt_options) {
goog.base(this);
/**
* @private
* @type {ol.proj.Projection}
* @inheritDoc
*/
this.defaultProjection_ =
ol.proj.get(options.defaultProjection || 'EPSG:4326');
this.defaultDataProjection = ol.proj.get(
goog.isDefAndNotNull(options.defaultDataProjection) ?
options.defaultDataProjection : 'EPSG:4326');
};
goog.inherits(ol.format.TopoJSON, ol.format.JSONFeature);
@@ -217,17 +218,18 @@ ol.format.TopoJSON.prototype.getExtensions = function() {
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
* @param {Array.<number>} scale Scale for each dimension.
* @param {Array.<number>} translate Translation for each dimension.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Array of features.
* @private
*/
ol.format.TopoJSON.readFeaturesFromGeometryCollection_ = function(
collection, arcs, scale, translate) {
collection, arcs, scale, translate, opt_options) {
var geometries = collection.geometries;
var features = [];
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
features[i] = ol.format.TopoJSON.readFeatureFromGeometry_(
geometries[i], arcs, scale, translate);
geometries[i], arcs, scale, translate, opt_options);
}
return features;
};
@@ -240,11 +242,12 @@ ol.format.TopoJSON.readFeaturesFromGeometryCollection_ = function(
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
* @param {Array.<number>} scale Scale for each dimension.
* @param {Array.<number>} translate Translation for each dimension.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @private
*/
ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
scale, translate) {
scale, translate, opt_options) {
var geometry;
var type = object.type;
var geometryReader = ol.format.TopoJSON.GEOMETRY_READERS_[type];
@@ -255,7 +258,8 @@ ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
geometry = geometryReader(object, arcs);
}
var feature = new ol.Feature();
feature.setGeometry(geometry);
feature.setGeometry(/** @type {ol.geom.Geometry} */ (
ol.format.Feature.transformWithOptions(geometry, false, opt_options)));
if (goog.isDef(object.id)) {
feature.setId(object.id);
}
@@ -280,7 +284,8 @@ ol.format.TopoJSON.prototype.readFeatures;
/**
* @inheritDoc
*/
ol.format.TopoJSON.prototype.readFeaturesFromObject = function(object) {
ol.format.TopoJSON.prototype.readFeaturesFromObject = function(
object, opt_options) {
if (object.type == 'Topology') {
var topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
var transform, scale = null, translate = null;
@@ -305,12 +310,12 @@ ol.format.TopoJSON.prototype.readFeaturesFromObject = function(object) {
(topoJSONFeatures[i]);
features.push.apply(features,
ol.format.TopoJSON.readFeaturesFromGeometryCollection_(
feature, arcs, scale, translate));
feature, arcs, scale, translate, opt_options));
} else {
feature = /** @type {TopoJSONGeometry} */
(topoJSONFeatures[i]);
features.push(ol.format.TopoJSON.readFeatureFromGeometry_(
feature, arcs, scale, translate));
feature, arcs, scale, translate, opt_options));
}
}
return features;
@@ -385,7 +390,7 @@ ol.format.TopoJSON.transformVertex_ = function(vertex, scale, translate) {
* @api
*/
ol.format.TopoJSON.prototype.readProjection = function(object) {
return this.defaultProjection_;
return this.defaultDataProjection;
};