Implement read/write transforms for ol.format.GPX

This commit is contained in:
tsauerwein
2014-08-08 15:05:35 +02:00
parent e446738491
commit 31dbbc6a8c
7 changed files with 154 additions and 11 deletions
+34
View File
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
goog.require('ol.format.Feature');
goog.require('ol.format.FormatType');
goog.require('ol.proj');
goog.require('ol.xml');
@@ -243,3 +244,36 @@ ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
* @return {Node} Node.
*/
ol.format.XMLFeature.prototype.writeGeometryNode = goog.abstractMethod;
/**
* @param {Array.<ol.Feature>} features Features.
* @param {boolean} write Set to true for writing, false for reading. For
* writing, the features will be cloned before transforming.
* @param {(olx.format.WriteOptions|olx.format.ReadOptions)=} opt_options
* Options.
* @protected
* @return {Array.<ol.Feature>} Features.
*/
ol.format.XMLFeature.transformFeaturesWithOptions = function(
features, write, opt_options) {
var featureProjection = goog.isDef(opt_options) ?
ol.proj.get(opt_options.featureProjection) : null;
var dataProjection = goog.isDef(opt_options) ?
ol.proj.get(opt_options.dataProjection) : null;
if (!goog.isNull(featureProjection) && !goog.isNull(dataProjection) &&
!ol.proj.equivalent(featureProjection, dataProjection)) {
if (write) {
features = goog.array.map(features, function(feature) {
return feature.clone();
});
}
goog.array.forEach(features, function(feature) {
feature.setGeometry(ol.format.Feature.transformWithOptions(
feature.getGeometry(), write, false, opt_options));
});
}
return features;
};