Add ReadOptions and WriteOptions for XML formats

This commit is contained in:
Andreas Hocevar
2014-07-30 14:22:51 +02:00
parent b8a834b437
commit da0988f5f4
+36 -22
View File
@@ -35,14 +35,15 @@ ol.format.XMLFeature.prototype.getType = function() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.format.XMLFeature.prototype.readFeature = function(source) { ol.format.XMLFeature.prototype.readFeature = function(source, opt_options) {
if (ol.xml.isDocument(source)) { if (ol.xml.isDocument(source)) {
return this.readFeatureFromDocument(/** @type {Document} */ (source)); return this.readFeatureFromDocument(
/** @type {Document} */ (source), opt_options);
} else if (ol.xml.isNode(source)) { } else if (ol.xml.isNode(source)) {
return this.readFeatureFromNode(/** @type {Node} */ (source)); return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
} else if (goog.isString(source)) { } else if (goog.isString(source)) {
var doc = ol.xml.load(source); var doc = ol.xml.load(source);
return this.readFeatureFromDocument(doc); return this.readFeatureFromDocument(doc, opt_options);
} else { } else {
goog.asserts.fail(); goog.asserts.fail();
return null; return null;
@@ -52,10 +53,12 @@ ol.format.XMLFeature.prototype.readFeature = function(source) {
/** /**
* @param {Document} doc Document. * @param {Document} doc Document.
* @param {olx.format.ReadOptions=} opt_options Options.
* @return {ol.Feature} Feature. * @return {ol.Feature} Feature.
*/ */
ol.format.XMLFeature.prototype.readFeatureFromDocument = function(doc) { ol.format.XMLFeature.prototype.readFeatureFromDocument = function(
var features = this.readFeaturesFromDocument(doc); doc, opt_options) {
var features = this.readFeaturesFromDocument(doc, opt_options);
if (features.length > 0) { if (features.length > 0) {
return features[0]; return features[0];
} else { } else {
@@ -66,6 +69,7 @@ ol.format.XMLFeature.prototype.readFeatureFromDocument = function(doc) {
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {olx.format.ReadOptions=} opt_options Options.
* @return {ol.Feature} Feature. * @return {ol.Feature} Feature.
*/ */
ol.format.XMLFeature.prototype.readFeatureFromNode = goog.abstractMethod; ol.format.XMLFeature.prototype.readFeatureFromNode = goog.abstractMethod;
@@ -74,14 +78,15 @@ ol.format.XMLFeature.prototype.readFeatureFromNode = goog.abstractMethod;
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.format.XMLFeature.prototype.readFeatures = function(source) { ol.format.XMLFeature.prototype.readFeatures = function(source, opt_options) {
if (ol.xml.isDocument(source)) { if (ol.xml.isDocument(source)) {
return this.readFeaturesFromDocument(/** @type {Document} */ (source)); return this.readFeaturesFromDocument(
/** @type {Document} */ (source), opt_options);
} else if (ol.xml.isNode(source)) { } else if (ol.xml.isNode(source)) {
return this.readFeaturesFromNode(/** @type {Node} */ (source)); return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
} else if (goog.isString(source)) { } else if (goog.isString(source)) {
var doc = ol.xml.load(source); var doc = ol.xml.load(source);
return this.readFeaturesFromDocument(doc); return this.readFeaturesFromDocument(doc, opt_options);
} else { } else {
goog.asserts.fail(); goog.asserts.fail();
return []; return [];
@@ -91,16 +96,18 @@ ol.format.XMLFeature.prototype.readFeatures = function(source) {
/** /**
* @param {Document} doc Document. * @param {Document} doc Document.
* @param {olx.format.ReadOptions=} opt_options Options.
* @protected * @protected
* @return {Array.<ol.Feature>} Features. * @return {Array.<ol.Feature>} Features.
*/ */
ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(doc) { ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(
doc, opt_options) {
/** @type {Array.<ol.Feature>} */ /** @type {Array.<ol.Feature>} */
var features = []; var features = [];
var n; var n;
for (n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) { for (n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
if (n.nodeType == goog.dom.NodeType.ELEMENT) { if (n.nodeType == goog.dom.NodeType.ELEMENT) {
goog.array.extend(features, this.readFeaturesFromNode(n)); goog.array.extend(features, this.readFeaturesFromNode(n, opt_options));
} }
} }
return features; return features;
@@ -109,6 +116,7 @@ ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(doc) {
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {olx.format.ReadOptions=} opt_options Options.
* @protected * @protected
* @return {Array.<ol.Feature>} Features. * @return {Array.<ol.Feature>} Features.
*/ */
@@ -118,14 +126,15 @@ ol.format.XMLFeature.prototype.readFeaturesFromNode = goog.abstractMethod;
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.format.XMLFeature.prototype.readGeometry = function(source) { ol.format.XMLFeature.prototype.readGeometry = function(source, opt_options) {
if (ol.xml.isDocument(source)) { if (ol.xml.isDocument(source)) {
return this.readGeometryFromDocument(/** @type {Document} */ (source)); return this.readGeometryFromDocument(
/** @type {Document} */ (source), opt_options);
} else if (ol.xml.isNode(source)) { } else if (ol.xml.isNode(source)) {
return this.readGeometryFromNode(/** @type {Node} */ (source)); return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
} else if (goog.isString(source)) { } else if (goog.isString(source)) {
var doc = ol.xml.load(source); var doc = ol.xml.load(source);
return this.readGeometryFromDocument(doc); return this.readGeometryFromDocument(doc, opt_options);
} else { } else {
goog.asserts.fail(); goog.asserts.fail();
return null; return null;
@@ -135,6 +144,7 @@ ol.format.XMLFeature.prototype.readGeometry = function(source) {
/** /**
* @param {Document} doc Document. * @param {Document} doc Document.
* @param {olx.format.ReadOptions=} opt_options Options.
* @protected * @protected
* @return {ol.geom.Geometry} Geometry. * @return {ol.geom.Geometry} Geometry.
*/ */
@@ -143,6 +153,7 @@ ol.format.XMLFeature.prototype.readGeometryFromDocument = goog.abstractMethod;
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {olx.format.ReadOptions=} opt_options Options.
* @protected * @protected
* @return {ol.geom.Geometry} Geometry. * @return {ol.geom.Geometry} Geometry.
*/ */
@@ -186,13 +197,14 @@ ol.format.XMLFeature.prototype.readProjectionFromNode = goog.abstractMethod;
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.format.XMLFeature.prototype.writeFeature = function(feature) { ol.format.XMLFeature.prototype.writeFeature = function(feature, opt_options) {
return this.writeFeatureNode(feature); return this.writeFeatureNode(feature, opt_options);
}; };
/** /**
* @param {ol.Feature} feature Feature. * @param {ol.Feature} feature Feature.
* @param {olx.format.WriteOptions=} opt_options Options.
* @protected * @protected
* @return {Node} Node. * @return {Node} Node.
*/ */
@@ -202,13 +214,14 @@ ol.format.XMLFeature.prototype.writeFeatureNode = goog.abstractMethod;
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.format.XMLFeature.prototype.writeFeatures = function(features) { ol.format.XMLFeature.prototype.writeFeatures = function(features, opt_options) {
return this.writeFeaturesNode(features); return this.writeFeaturesNode(features, opt_options);
}; };
/** /**
* @param {Array.<ol.Feature>} features Features. * @param {Array.<ol.Feature>} features Features.
* @param {olx.format.WriteOptions=} opt_options Options.
* @protected * @protected
* @return {Node} Node. * @return {Node} Node.
*/ */
@@ -218,13 +231,14 @@ ol.format.XMLFeature.prototype.writeFeaturesNode = goog.abstractMethod;
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.format.XMLFeature.prototype.writeGeometry = function(geometry) { ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
return this.writeGeometryNode(geometry); return this.writeGeometryNode(geometry, opt_options);
}; };
/** /**
* @param {ol.geom.Geometry} geometry Geometry. * @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Options.
* @protected * @protected
* @return {Node} Node. * @return {Node} Node.
*/ */