Merge pull request #3516 from tschaub/unbinary

Remove ol.format.BinaryFeature.
This commit is contained in:
Tim Schaub
2015-04-19 10:04:53 -06:00
26 changed files with 44 additions and 439 deletions

View File

@@ -1,177 +0,0 @@
// FIXME Test on Internet Explorer with VBArray
goog.provide('ol.binary.Buffer');
goog.provide('ol.binary.IReader');
goog.require('goog.asserts');
goog.require('goog.userAgent');
goog.require('ol.has');
/**
* @constructor
* @param {ArrayBuffer|string} data Data.
*/
ol.binary.Buffer = function(data) {
/**
* @private
* @type {ArrayBuffer|string}
*/
this.data_ = data;
};
/**
* @return {ol.binary.IReader} Reader.
*/
ol.binary.Buffer.prototype.getReader = function() {
var data = this.data_;
if (ol.has.ARRAY_BUFFER) {
var arrayBuffer;
if (data instanceof ArrayBuffer) {
arrayBuffer = data;
} else if (goog.isString(data)) {
// FIXME check what happens with Unicode
arrayBuffer = new ArrayBuffer(data.length);
var uint8View = new Uint8Array(arrayBuffer);
var i, ii;
for (i = 0, ii = data.length; i < ii; ++i) {
uint8View[i] = data.charCodeAt(i);
}
} else {
goog.asserts.fail('Unknown data type, should be string or ArrayBuffer');
return null;
}
return new ol.binary.ArrayBufferReader(arrayBuffer);
} else {
goog.asserts.assert(goog.isString(data), 'Data should be a string');
goog.asserts.assert(
goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('10.0'),
'In IE10 and above ArrayBuffer should be used instead');
return new ol.binary.ArrayReader(new VBArray(data).toArray());
}
};
/**
* @interface
*/
ol.binary.IReader = function() {};
/**
* @return {boolean} At EOF.
*/
ol.binary.IReader.prototype.atEOF = function() {};
/**
* @return {number} Byte.
*/
ol.binary.IReader.prototype.readByte = function() {};
/**
* @constructor
* @param {ArrayBuffer} arrayBuffer Array buffer.
* @implements {ol.binary.IReader}
*/
ol.binary.ArrayBufferReader = function(arrayBuffer) {
/**
* @private
* @type {Uint8Array}
*/
this.uint8View_ = new Uint8Array(arrayBuffer);
/**
* @private
* @type {number}
*/
this.length_ = this.uint8View_.length;
/**
* @private
* @type {number}
*/
this.offset_ = 0;
};
/**
* @inheritDoc
*/
ol.binary.ArrayBufferReader.prototype.atEOF = function() {
return this.offset_ == this.length_;
};
/**
* @inheritDoc
*/
ol.binary.ArrayBufferReader.prototype.readByte = function() {
if (this.offset_ < this.length_) {
return this.uint8View_[this.offset_++];
} else {
goog.asserts.fail(
'readByte fails because offset is larger than or equal to length');
return 0;
}
};
/**
* @constructor
* @implements {ol.binary.IReader}
* @param {Array.<number>} array Array.
*/
ol.binary.ArrayReader = function(array) {
/**
* @private
* @type {Array.<number>}
*/
this.array_ = array;
/**
* @private
* @type {number}
*/
this.length_ = array.length;
/**
* @private
* @type {number}
*/
this.offset_ = 0;
};
/**
* @inheritDoc
*/
ol.binary.ArrayReader.prototype.atEOF = function() {
return this.offset_ == this.length_;
};
/**
* @inheritDoc
*/
ol.binary.ArrayReader.prototype.readByte = function() {
if (this.offset_ < this.length_) {
return this.array_[this.offset_++];
} else {
goog.asserts.fail(
'readByte fails because offset is larger than or equal to length');
return 0;
}
};

View File

@@ -37,15 +37,7 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success) {
function(extent, resolution, projection) {
var xhrIo = new goog.net.XhrIo();
var type = format.getType();
var responseType;
// FIXME maybe use ResponseType.DOCUMENT?
if (type == ol.format.FormatType.BINARY &&
ol.has.ARRAY_BUFFER) {
responseType = goog.net.XhrIo.ResponseType.ARRAY_BUFFER;
} else {
responseType = goog.net.XhrIo.ResponseType.TEXT;
}
xhrIo.setResponseType(responseType);
xhrIo.setResponseType(goog.net.XhrIo.ResponseType.TEXT);
goog.events.listen(xhrIo, goog.net.EventType.COMPLETE,
/**
* @param {Event} event Event.
@@ -58,14 +50,9 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success) {
'event.target/xhrIo is an instance of goog.net.XhrIo');
if (xhrIo.isSuccess()) {
var type = format.getType();
/** @type {ArrayBuffer|Document|Node|Object|string|undefined} */
/** @type {Document|Node|Object|string|undefined} */
var source;
if (type == ol.format.FormatType.BINARY &&
ol.has.ARRAY_BUFFER) {
source = xhrIo.getResponse();
goog.asserts.assertInstanceof(source, ArrayBuffer,
'source is an instance of ArrayBuffer');
} else if (type == ol.format.FormatType.JSON) {
if (type == ol.format.FormatType.JSON) {
source = xhrIo.getResponseText();
} else if (type == ol.format.FormatType.TEXT) {
source = xhrIo.getResponseText();

View File

@@ -1,111 +0,0 @@
goog.provide('ol.format.BinaryFeature');
goog.require('goog.asserts');
goog.require('ol.binary.Buffer');
goog.require('ol.format.Feature');
goog.require('ol.format.FormatType');
goog.require('ol.has');
goog.require('ol.proj');
/**
* @constructor
* @extends {ol.format.Feature}
*/
ol.format.BinaryFeature = function() {
goog.base(this);
};
goog.inherits(ol.format.BinaryFeature, ol.format.Feature);
/**
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @private
* @return {ol.binary.Buffer} Buffer.
*/
ol.format.BinaryFeature.getBuffer_ = function(source) {
if (ol.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.BinaryFeature.prototype.getType = function() {
return ol.format.FormatType.BINARY;
};
/**
* @inheritDoc
*/
ol.format.BinaryFeature.prototype.readFeature = function(source) {
return this.readFeatureFromBuffer(ol.format.BinaryFeature.getBuffer_(source));
};
/**
* @inheritDoc
*/
ol.format.BinaryFeature.prototype.readFeatures = function(source) {
return this.readFeaturesFromBuffer(
ol.format.BinaryFeature.getBuffer_(source));
};
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @protected
* @return {ol.Feature} Feature.
*/
ol.format.BinaryFeature.prototype.readFeatureFromBuffer = goog.abstractMethod;
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @protected
* @return {Array.<ol.Feature>} Feature.
*/
ol.format.BinaryFeature.prototype.readFeaturesFromBuffer = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.format.BinaryFeature.prototype.readGeometry = function(source) {
return this.readGeometryFromBuffer(
ol.format.BinaryFeature.getBuffer_(source));
};
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @protected
* @return {ol.geom.Geometry} Geometry.
*/
ol.format.BinaryFeature.prototype.readGeometryFromBuffer = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.format.BinaryFeature.prototype.readProjection = function(source) {
return this.readProjectionFromBuffer(
ol.format.BinaryFeature.getBuffer_(source));
};
/**
* @param {ol.binary.Buffer} buffer Buffer.
* @return {ol.proj.Projection} Projection.
*/
ol.format.BinaryFeature.prototype.readProjectionFromBuffer =
goog.abstractMethod;

View File

@@ -85,7 +85,7 @@ ol.format.Feature.prototype.getType = goog.abstractMethod;
/**
* Read a single feature from a source.
*
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
*/
@@ -95,7 +95,7 @@ ol.format.Feature.prototype.readFeature = goog.abstractMethod;
/**
* Read all features from a source.
*
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
*/
@@ -105,7 +105,7 @@ ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
/**
* Read a single geometry from a source.
*
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.geom.Geometry} Geometry.
*/
@@ -115,7 +115,7 @@ ol.format.Feature.prototype.readGeometry = goog.abstractMethod;
/**
* Read the projection from a source.
*
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
*/
ol.format.Feature.prototype.readProjection = goog.abstractMethod;

View File

@@ -5,7 +5,6 @@ goog.provide('ol.format.FormatType');
* @enum {string}
*/
ol.format.FormatType = {
BINARY: 'binary',
JSON: 'json',
TEXT: 'text',
XML: 'xml'

View File

@@ -376,7 +376,7 @@ ol.format.GeoJSON.prototype.getExtensions = function() {
* use `readFeatures` to read FeatureCollection source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @api stable
@@ -389,7 +389,7 @@ ol.format.GeoJSON.prototype.readFeature;
* FeatureCollection sources.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -453,7 +453,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
* Read a geometry from a GeoJSON source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.geom.Geometry} Geometry.
* @api stable
@@ -475,7 +475,7 @@ ol.format.GeoJSON.prototype.readGeometryFromObject = function(
* Read the projection from a GeoJSON source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -590,7 +590,7 @@ ol.format.GMLBase.prototype.readGeometryFromNode =
* Read all features from a GML FeatureCollection.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Options.
* @return {Array.<ol.Feature>} Features.
* @api stable

View File

@@ -438,7 +438,7 @@ ol.format.GPX.prototype.handleReadExtensions_ = function(features) {
* Read the first feature from a GPX source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @api stable
@@ -472,7 +472,7 @@ ol.format.GPX.prototype.readFeatureFromNode = function(node, opt_options) {
* Read all features from a GPX source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -508,7 +508,7 @@ ol.format.GPX.prototype.readFeaturesFromNode = function(node, opt_options) {
* Read the projection from a GPX source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -101,7 +101,7 @@ ol.format.IGC.prototype.getExtensions = function() {
* Read the feature from the IGC source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @api
@@ -189,7 +189,7 @@ ol.format.IGC.prototype.readFeatureFromText = function(text, opt_options) {
* feature, this will return the feature in an array.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api
@@ -214,7 +214,7 @@ ol.format.IGC.prototype.readFeaturesFromText = function(text, opt_options) {
* Read the projection from the IGC source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
* @api
*/

View File

@@ -1736,7 +1736,7 @@ ol.format.KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
* Read the first feature from a KML source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @api stable
@@ -1769,7 +1769,7 @@ ol.format.KML.prototype.readFeatureFromNode = function(node, opt_options) {
* Read all features from a KML source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -1957,7 +1957,7 @@ ol.format.KML.prototype.readNetworkLinksFromNode = function(node) {
* Read the projection from a KML source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -203,7 +203,7 @@ ol.format.OSMXML.NODE_PARSERS_ = ol.xml.makeParsersNS(
* Read all features from an OSM source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -235,7 +235,7 @@ ol.format.OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) {
* Read the projection from an OSM source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -268,7 +268,7 @@ ol.format.Polyline.encodeUnsignedInteger = function(num) {
* in two dimensions and in latitude, longitude order.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @api stable
@@ -290,7 +290,7 @@ ol.format.Polyline.prototype.readFeatureFromText = function(text, opt_options) {
* feature, this will return the feature in an array.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -312,7 +312,7 @@ ol.format.Polyline.prototype.readFeaturesFromText =
* Read the geometry from the source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.geom.Geometry} Geometry.
* @api stable
@@ -344,7 +344,7 @@ ol.format.Polyline.prototype.readGeometryFromText =
* Read the projection from a Polyline source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -275,7 +275,7 @@ ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
* Read all features from a TopoJSON source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {Array.<ol.Feature>} Features.
* @api stable
*/
@@ -386,7 +386,7 @@ ol.format.TopoJSON.transformVertex_ = function(vertex, scale, translate) {
* Read the projection from a TopoJSON source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} object Source.
* @param {Document|Node|Object|string} object Source.
* @return {ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -106,7 +106,7 @@ ol.format.WFS.SCHEMA_LOCATION = 'http://www.opengis.net/wfs ' +
* Read all features from a WFS FeatureCollection.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -139,7 +139,7 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
/**
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.format.WFS.TransactionResponse|undefined} Transaction response.
* @api stable
*/
@@ -160,7 +160,7 @@ ol.format.WFS.prototype.readTransactionResponse = function(source) {
/**
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {ol.format.WFS.FeatureCollectionMetadata|undefined}
* FeatureCollection metadata.
* @api stable
@@ -730,7 +730,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
* Read the projection from a WFS source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @return {?ol.proj.Projection} Projection.
* @api stable
*/

View File

@@ -209,7 +209,7 @@ ol.format.WKT.prototype.parse_ = function(wkt) {
* Read a feature from a WKT source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.Feature} Feature.
* @api stable
@@ -235,7 +235,7 @@ ol.format.WKT.prototype.readFeatureFromText = function(text, opt_options) {
* Read all features from a WKT source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {Array.<ol.Feature>} Features.
* @api stable
@@ -270,7 +270,7 @@ ol.format.WKT.prototype.readFeaturesFromText = function(text, opt_options) {
* Read a single geometry from a WKT source.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @return {ol.geom.Geometry} Geometry.
* @api stable

View File

@@ -124,7 +124,7 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ =
* Read all features from a WMSGetFeatureInfo response.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Options.
* @return {Array.<ol.Feature>} Features.
* @api stable

View File

@@ -17,14 +17,6 @@ goog.require('ol.webgl');
ol.has.DEVICE_PIXEL_RATIO = goog.global.devicePixelRatio || 1;
/**
* True if the browser supports ArrayBuffers.
* @const
* @type {boolean}
*/
ol.has.ARRAY_BUFFER = 'ArrayBuffer' in goog.global;
/**
* True if the browser's Canvas implementation implements {get,set}LineDash.
* @type {boolean}