Merge pull request #3003 from bartvde/writefeatures

The writeFeatures method should always return a string (r=@elemoine)
This commit is contained in:
Bart van den Eijnden
2014-12-05 15:05:25 +01:00
13 changed files with 174 additions and 102 deletions

View File

@@ -128,7 +128,7 @@ ol.format.Feature.prototype.readProjection = goog.abstractMethod;
*
* @param {ol.Feature} feature Feature.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @return {ArrayBuffer|Node|Object|string} Result.
* @return {string} Result.
*/
ol.format.Feature.prototype.writeFeature = goog.abstractMethod;
@@ -138,7 +138,7 @@ ol.format.Feature.prototype.writeFeature = goog.abstractMethod;
*
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @return {ArrayBuffer|Node|Object|string} Result.
* @return {string} Result.
*/
ol.format.Feature.prototype.writeFeatures = goog.abstractMethod;
@@ -148,7 +148,7 @@ ol.format.Feature.prototype.writeFeatures = goog.abstractMethod;
*
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @return {ArrayBuffer|Node|Object|string} Node.
* @return {string} Result.
*/
ol.format.Feature.prototype.writeGeometry = goog.abstractMethod;

View File

@@ -478,22 +478,28 @@ ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
/**
* Encode a feature as a GeoJSON Feature object.
* Encode a feature as a GeoJSON Feature string.
*
* @function
* @param {ol.Feature} feature Feature.
* @param {olx.format.WriteOptions} options Write options.
* @return {GeoJSONFeature} GeoJSON.
* @return {string} GeoJSON.
* @api stable
*/
ol.format.GeoJSON.prototype.writeFeature;
/**
* @inheritDoc
* Encode a feature as a GeoJSON Feature object.
*
* @param {ol.Feature} feature Feature.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @api
* @return {Object} Object.
*/
ol.format.GeoJSON.prototype.writeFeatureObject = function(
feature, opt_options) {
opt_options = this.adaptOptions(opt_options);
var object = {
'type': 'Feature'
};
@@ -522,17 +528,23 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function(
* @function
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions} options Write options.
* @return {GeoJSONObject} GeoJSON.
* @return {string} GeoJSON.
* @api stable
*/
ol.format.GeoJSON.prototype.writeFeatures;
/**
* @inheritDoc
* Encode an array of features as a GeoJSON object.
*
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @return {Object} GeoJSON Object.
* @api
*/
ol.format.GeoJSON.prototype.writeFeaturesObject =
function(features, opt_options) {
opt_options = this.adaptOptions(opt_options);
var objects = [];
var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) {
@@ -546,19 +558,27 @@ ol.format.GeoJSON.prototype.writeFeaturesObject =
/**
* Encode a geometry as GeoJSON.
* Encode a geometry as a GeoJSON string.
*
* @function
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions} options Write options.
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON.
* @return {string} GeoJSON.
* @api stable
*/
ol.format.GeoJSON.prototype.writeGeometry;
/**
* @inheritDoc
* Encode a geometry as a GeoJSON object.
*
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object.
* @api
*/
ol.format.GeoJSON.prototype.writeGeometryObject =
ol.format.GeoJSON.writeGeometry_;
ol.format.GeoJSON.prototype.writeGeometryObject = function(geometry,
opt_options) {
return ol.format.GeoJSON.writeGeometry_(geometry,
this.adaptOptions(opt_options));
};

View File

@@ -1247,9 +1247,15 @@ ol.format.GML3.prototype.GEOMETRY_NODE_FACTORY_ =
/**
* @inheritDoc
* Encode a geometry in GML 3.1.1 Simple Features.
*
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Node.
* @api
*/
ol.format.GML3.prototype.writeGeometryNode = function(geometry, opt_options) {
opt_options = this.adaptOptions(opt_options);
var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
var context = {node: geom, srsName: this.srsName,
curve: this.curve_, surface: this.surface_,
@@ -1268,16 +1274,22 @@ ol.format.GML3.prototype.writeGeometryNode = function(geometry, opt_options) {
* @function
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Result.
* @return {string} Result.
* @api stable
*/
ol.format.GML3.prototype.writeFeatures;
/**
* @inheritDoc
* Encode an array of features in the GML 3.1.1 format as an XML node.
*
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Node.
* @api
*/
ol.format.GML3.prototype.writeFeaturesNode = function(features, opt_options) {
opt_options = this.adaptOptions(opt_options);
var node = ol.xml.createElementNS('http://www.opengis.net/gml',
'featureMembers');
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
@@ -1321,7 +1333,19 @@ ol.format.GML = ol.format.GML3;
* @function
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Result.
* @return {string} Result.
* @api stable
*/
ol.format.GML.prototype.writeFeatures;
/**
* Encode an array of features in the GML 3.1.1 format as an XML node.
*
* @function
* @param {ol.Feature} feature Feature.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Node.
* @api
*/
ol.format.GML.prototype.writeFeaturesNode;

View File

@@ -876,9 +876,15 @@ ol.format.GPX.prototype.writeFeatures;
/**
* @inheritDoc
* Encode an array of features in the GPX format as an XML node.
*
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Node.
* @api
*/
ol.format.GPX.prototype.writeFeaturesNode = function(features, opt_options) {
opt_options = this.adaptOptions(opt_options);
//FIXME Serialize metadata
var gpx = ol.xml.createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');

View File

@@ -122,14 +122,13 @@ ol.format.JSONFeature.prototype.readProjectionFromObject = goog.abstractMethod;
* @inheritDoc
*/
ol.format.JSONFeature.prototype.writeFeature = function(feature, opt_options) {
return this.writeFeatureObject(feature, this.adaptOptions(opt_options));
return goog.json.serialize(this.writeFeatureObject(feature, opt_options));
};
/**
* @param {ol.Feature} feature Feature.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @protected
* @return {Object} Object.
*/
ol.format.JSONFeature.prototype.writeFeatureObject = goog.abstractMethod;
@@ -140,14 +139,13 @@ ol.format.JSONFeature.prototype.writeFeatureObject = goog.abstractMethod;
*/
ol.format.JSONFeature.prototype.writeFeatures = function(
features, opt_options) {
return this.writeFeaturesObject(features, this.adaptOptions(opt_options));
return goog.json.serialize(this.writeFeaturesObject(features, opt_options));
};
/**
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @protected
* @return {Object} Object.
*/
ol.format.JSONFeature.prototype.writeFeaturesObject = goog.abstractMethod;
@@ -158,14 +156,13 @@ ol.format.JSONFeature.prototype.writeFeaturesObject = goog.abstractMethod;
*/
ol.format.JSONFeature.prototype.writeGeometry = function(
geometry, opt_options) {
return this.writeGeometryObject(geometry, this.adaptOptions(opt_options));
return goog.json.serialize(this.writeGeometryObject(geometry, opt_options));
};
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @protected
* @return {Object} Object.
*/
ol.format.JSONFeature.prototype.writeGeometryObject = goog.abstractMethod;

View File

@@ -2581,16 +2581,22 @@ ol.format.KML.OUTER_BOUNDARY_NODE_FACTORY_ =
* @function
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Result.
* @return {string} Result.
* @api stable
*/
ol.format.KML.prototype.writeFeatures;
/**
* @inheritDoc
* Encode an array of features in the KML format as an XML node.
*
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @return {Node} Node.
* @api
*/
ol.format.KML.prototype.writeFeaturesNode = function(features, opt_options) {
opt_options = this.adaptOptions(opt_options);
var kml = ol.xml.createElementNS(ol.format.KML.NAMESPACE_URIS_[4], 'kml');
var xmlnsUri = 'http://www.w3.org/2000/xmlns/';
var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance';

View File

@@ -3,6 +3,7 @@ goog.provide('ol.format.XMLFeature');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
goog.require('goog.dom.xml');
goog.require('ol.format.Feature');
goog.require('ol.format.FormatType');
goog.require('ol.proj');
@@ -199,7 +200,9 @@ ol.format.XMLFeature.prototype.readProjectionFromNode = goog.abstractMethod;
* @inheritDoc
*/
ol.format.XMLFeature.prototype.writeFeature = function(feature, opt_options) {
return this.writeFeatureNode(feature, this.adaptOptions(opt_options));
var node = this.writeFeatureNode(feature, opt_options);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
return goog.dom.xml.serialize(/** @type {Element} */(node));
};
@@ -216,14 +219,15 @@ ol.format.XMLFeature.prototype.writeFeatureNode = goog.abstractMethod;
* @inheritDoc
*/
ol.format.XMLFeature.prototype.writeFeatures = function(features, opt_options) {
return this.writeFeaturesNode(features, this.adaptOptions(opt_options));
var node = this.writeFeaturesNode(features, opt_options);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
return goog.dom.xml.serialize(/** @type {Element} */(node));
};
/**
* @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @protected
* @return {Node} Node.
*/
ol.format.XMLFeature.prototype.writeFeaturesNode = goog.abstractMethod;
@@ -233,14 +237,15 @@ ol.format.XMLFeature.prototype.writeFeaturesNode = goog.abstractMethod;
* @inheritDoc
*/
ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
return this.writeGeometryNode(geometry, this.adaptOptions(opt_options));
var node = this.writeGeometryNode(geometry, opt_options);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
return goog.dom.xml.serialize(/** @type {Element} */(node));
};
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Options.
* @protected
* @return {Node} Node.
*/
ol.format.XMLFeature.prototype.writeGeometryNode = goog.abstractMethod;