Merge pull request #1717 from twpayne/binary-format

Add ol.format.Binary
This commit is contained in:
Tom Payne
2014-02-21 12:27:13 +01:00
14 changed files with 395 additions and 23 deletions
+107
View File
@@ -0,0 +1,107 @@
goog.provide('ol.format.Binary');
goog.require('goog.asserts');
goog.require('ol.BrowserFeature');
goog.require('ol.binary.Buffer');
goog.require('ol.format.Format');
goog.require('ol.format.FormatType');
goog.require('ol.proj');
/**
* @constructor
* @extends {ol.format.Format}
*/
ol.format.Binary = function() {
goog.base(this);
};
goog.inherits(ol.format.Binary, ol.format.Format);
/**
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @private
* @return {ol.binary.Buffer} Buffer.
*/
ol.format.Binary.getBuffer_ = function(source) {
if (ol.BrowserFeature.HAS_ARRAY_BUFFER && source instanceof ArrayBuffer) {
return new ol.binary.Buffer(source);
} else if (goog.isString(source)) {
return new ol.binary.Buffer(source);
} else {
goog.asserts.fail();
return null;
}
};
/**
* @inheritDoc
*/
ol.format.Binary.prototype.getType = function() {
return ol.format.FormatType.BINARY;
};
/**
* @inheritDoc
*/
ol.format.Binary.prototype.readFeature = function(source) {
return this.readFeatureFromBuffer(ol.format.Binary.getBuffer_(source));
};
/**
* @inheritDoc
*/
ol.format.Binary.prototype.readFeatures = function(source) {
return this.readFeaturesFromBuffer(ol.format.Binary.getBuffer_(source));
};
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @protected
* @return {ol.Feature} Feature.
*/
ol.format.Binary.prototype.readFeatureFromBuffer = goog.abstractMethod;
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @protected
* @return {Array.<ol.Feature>} Feature.
*/
ol.format.Binary.prototype.readFeaturesFromBuffer = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.format.Binary.prototype.readGeometry = function(source) {
return this.readGeometryFromBuffer(ol.format.Binary.getBuffer_(source));
};
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @protected
* @return {ol.geom.Geometry} Geometry.
*/
ol.format.Binary.prototype.readGeometryFromBuffer = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.format.Binary.prototype.readProjection = function(source) {
return this.readProjectionFromBuffer(ol.format.Binary.getBuffer_(source));
};
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @return {ol.proj.Projection} Projection.
*/
ol.format.Binary.prototype.readProjectionFromBuffer = goog.abstractMethod;
+7 -7
View File
@@ -36,28 +36,28 @@ ol.format.Format.prototype.getType = goog.abstractMethod;
/**
* @param {Document|Node|Object|string} source Source.
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @return {ol.Feature} Feature.
*/
ol.format.Format.prototype.readFeature = goog.abstractMethod;
/**
* @param {Document|Node|Object|string} source Source.
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @return {Array.<ol.Feature>} Features.
*/
ol.format.Format.prototype.readFeatures = goog.abstractMethod;
/**
* @param {Document|Node|Object|string} source Source.
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @return {ol.geom.Geometry} Geometry.
*/
ol.format.Format.prototype.readGeometry = goog.abstractMethod;
/**
* @param {Document|Node|Object|string} source Source.
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
*/
ol.format.Format.prototype.readProjection = goog.abstractMethod;
@@ -65,20 +65,20 @@ ol.format.Format.prototype.readProjection = goog.abstractMethod;
/**
* @param {ol.Feature} feature Feature.
* @return {Node|Object|string} Result.
* @return {ArrayBuffer|Node|Object|string} Result.
*/
ol.format.Format.prototype.writeFeature = goog.abstractMethod;
/**
* @param {Array.<ol.Feature>} features Features.
* @return {Node|Object|string} Result.
* @return {ArrayBuffer|Node|Object|string} Result.
*/
ol.format.Format.prototype.writeFeatures = goog.abstractMethod;
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @return {Node|Object|string} Node.
* @return {ArrayBuffer|Node|Object|string} Node.
*/
ol.format.Format.prototype.writeGeometry = goog.abstractMethod;