diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc
index 11f6a596df..6478b67102 100644
--- a/src/objectliterals.jsdoc
+++ b/src/objectliterals.jsdoc
@@ -860,6 +860,7 @@
/**
* @typedef {Object} olx.source.VectorFileOptions
+ * @property {ArrayBuffer|undefined} arrayBuffer Array buffer.
* @property {Array.
|undefined} attributions Attributions.
* @property {Document|undefined} doc Document.
* @property {ol.Extent|undefined} extent Extent.
diff --git a/src/ol/source/vectorfilesource.js b/src/ol/source/vectorfilesource.js
index c2fd85339a..11ef6a65f7 100644
--- a/src/ol/source/vectorfilesource.js
+++ b/src/ol/source/vectorfilesource.js
@@ -4,8 +4,13 @@
goog.provide('ol.source.VectorFile');
goog.require('goog.asserts');
+goog.require('goog.dispose');
+goog.require('goog.events');
+goog.require('goog.net.EventType');
goog.require('goog.net.XhrIo');
+goog.require('goog.net.XhrIo.ResponseType');
goog.require('goog.userAgent');
+goog.require('ol.BrowserFeature');
goog.require('ol.format.FormatType');
goog.require('ol.proj');
goog.require('ol.source.State');
@@ -53,17 +58,38 @@ ol.source.VectorFile = function(opt_options) {
this.readFeatures_(options.text);
}
+ if (goog.isDef(options.arrayBuffer)) {
+ this.readFeatures_(options.arrayBuffer);
+ }
+
if (goog.isDef(options.url) || goog.isDef(options.urls)) {
this.setState(ol.source.State.LOADING);
- var handleXhrIo = goog.bind(this.handleXhrIo_, this);
+
+ var type = this.format.getType();
+ var responseType;
+ if (type == ol.format.FormatType.BINARY &&
+ ol.BrowserFeature.HAS_ARRAY_BUFFER) {
+ responseType = goog.net.XhrIo.ResponseType.ARRAY_BUFFER;
+ } else {
+ responseType = goog.net.XhrIo.ResponseType.TEXT;
+ }
+ var xhrIo;
if (goog.isDef(options.url)) {
- goog.net.XhrIo.send(options.url, handleXhrIo);
+ xhrIo = new goog.net.XhrIo();
+ xhrIo.setResponseType(responseType);
+ goog.events.listen(xhrIo, goog.net.EventType.COMPLETE,
+ goog.bind(this.handleXhrIo_, this));
+ xhrIo.send(options.url);
}
if (goog.isDef(options.urls)) {
var urls = options.urls;
var i, ii;
for (i = 0, ii = urls.length; i < ii; ++i) {
- goog.net.XhrIo.send(urls[i], handleXhrIo);
+ xhrIo = new goog.net.XhrIo();
+ xhrIo.setResponseType(responseType);
+ goog.events.listen(xhrIo, goog.net.EventType.COMPLETE,
+ goog.bind(this.handleXhrIo_, this));
+ xhrIo.send(urls[i]);
}
}
}
@@ -77,13 +103,16 @@ goog.inherits(ol.source.VectorFile, ol.source.Vector);
* @private
*/
ol.source.VectorFile.prototype.handleXhrIo_ = function(event) {
- var xhrIo = /** @type {goog.net.XhrIo} */ (event.target);
+ var xhrIo = event.target;
+ goog.asserts.assertInstanceof(xhrIo, goog.net.XhrIo);
if (xhrIo.isSuccess()) {
var type = this.format.getType();
- /** @type {Document|Node|Object|string|undefined} */
+ /** @type {ArrayBuffer|Document|Node|Object|string|undefined} */
var source;
- if (type == ol.format.FormatType.BINARY) {
- // FIXME
+ if (type == ol.format.FormatType.BINARY &&
+ ol.BrowserFeature.HAS_ARRAY_BUFFER) {
+ source = xhrIo.getResponse();
+ goog.asserts.assertInstanceof(source, ArrayBuffer);
} else if (type == ol.format.FormatType.JSON) {
source = xhrIo.getResponseJson();
} else if (type == ol.format.FormatType.TEXT) {
@@ -98,6 +127,7 @@ ol.source.VectorFile.prototype.handleXhrIo_ = function(event) {
} else {
goog.asserts.fail();
}
+ goog.dispose(xhrIo);
if (goog.isDef(source)) {
this.readFeatures_(source);
} else {
@@ -111,7 +141,7 @@ ol.source.VectorFile.prototype.handleXhrIo_ = function(event) {
/**
- * @param {Document|Node|Object|string} source Source.
+ * @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @private
*/
ol.source.VectorFile.prototype.readFeatures_ = function(source) {