From 8c7ff294705087224cf6ce2c017b134c06dc8551 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 4 Dec 2013 17:18:05 +0100 Subject: [PATCH] Add ol.format.Text --- src/ol/format/textformat.exports | 8 ++ src/ol/format/textformat.js | 154 +++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 src/ol/format/textformat.exports create mode 100644 src/ol/format/textformat.js diff --git a/src/ol/format/textformat.exports b/src/ol/format/textformat.exports new file mode 100644 index 0000000000..21c60b12e2 --- /dev/null +++ b/src/ol/format/textformat.exports @@ -0,0 +1,8 @@ +@exportProperty ol.format.Text.prototype.readFeature +@exportProperty ol.format.Text.prototype.readFeatures +@exportProperty ol.format.Text.prototype.readFeaturesAsync +@exportProperty ol.format.Text.prototype.readGeometry +@exportProperty ol.format.Text.prototype.readProjection +@exportProperty ol.format.Text.prototype.writeFeature +@exportProperty ol.format.Text.prototype.writeFeatures +@exportProperty ol.format.Text.prototype.writeGeometry diff --git a/src/ol/format/textformat.js b/src/ol/format/textformat.js new file mode 100644 index 0000000000..4db799da68 --- /dev/null +++ b/src/ol/format/textformat.js @@ -0,0 +1,154 @@ +goog.provide('ol.format.Text'); + +goog.require('goog.asserts'); +goog.require('ol.format.Format'); +goog.require('ol.format.FormatType'); +goog.require('ol.proj'); + + + +/** + * @constructor + * @extends {ol.format.Format} + */ +ol.format.Text = function() { + goog.base(this); +}; +goog.inherits(ol.format.Text, ol.format.Format); + + +/** + * @param {Document|Node|Object|string} source Source. + * @private + * @return {string} Text. + */ +ol.format.Text.prototype.getText_ = function(source) { + if (goog.isString(source)) { + return source; + } else { + goog.asserts.fail(); + return ''; + } +}; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.getType = function() { + return ol.format.FormatType.TEXT; +}; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.readFeature = function(source) { + return this.readFeatureFromText(this.getText_(source)); +}; + + +/** + * @param {string} text Text. + * @protected + * @return {ol.Feature} Feature. + */ +ol.format.Text.prototype.readFeatureFromText = goog.abstractMethod; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.readFeatures = function(source) { + return this.readFeaturesFromText(this.getText_(source)); +}; + + +/** + * @param {string} text Text. + * @protected + * @return {Array.} Features. + */ +ol.format.Text.prototype.readFeaturesFromText = goog.abstractMethod; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.readGeometry = function(source) { + return this.readGeometryFromText(this.getText_(source)); +}; + + +/** + * @param {string} text Text. + * @protected + * @return {ol.geom.Geometry} Geometry. + */ +ol.format.Text.prototype.readGeometryFromText = goog.abstractMethod; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.readProjection = function(source) { + return this.readProjectionFromText(this.getText_(source)); +}; + + +/** + * @param {string} text Text. + * @protected + * @return {ol.proj.Projection} Projection. + */ +ol.format.Text.prototype.readProjectionFromText = function(text) { + return ol.proj.get('EPSG:4326'); +}; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.writeFeature = function(feature) { + return this.writeFeatureText(feature); +}; + + +/** + * @param {ol.Feature} feature Features. + * @protected + * @return {string} Text. + */ +ol.format.Text.prototype.writeFeatureText = goog.abstractMethod; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.writeFeatures = function(features) { + return this.writeFeaturesText(features); +}; + + +/** + * @param {Array.} features Features. + * @protected + * @return {string} Text. + */ +ol.format.Text.prototype.writeFeaturesText = goog.abstractMethod; + + +/** + * @inheritDoc + */ +ol.format.Text.prototype.writeGeometry = function(geometry) { + return this.writeGeometryText(geometry); +}; + + +/** + * @param {ol.geom.Geometry} geometry Geometry. + * @protected + * @return {string} Text. + */ +ol.format.Text.prototype.writeGeometryText = goog.abstractMethod;