Use XHR by default to load TileJSON in ol.source.TileJSON

This commit is contained in:
Petr Sloup
2016-01-06 11:01:02 +01:00
parent 4ba443e829
commit bc0d783f50
14 changed files with 48 additions and 45 deletions

View File

@@ -8,6 +8,9 @@ goog.provide('ol.source.TileJSON');
goog.provide('ol.tilejson');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('goog.net.CorsXmlHttpFactory');
goog.require('goog.net.EventType');
goog.require('goog.net.Jsonp');
goog.require('goog.net.XhrIo');
goog.require('ol.Attribution');
@@ -41,20 +44,22 @@ ol.source.TileJSON = function(options) {
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
if (options.useXhr) {
goog.net.XhrIo.send(options.url, goog.bind(function(e) {
var xhr = /** @type {goog.net.XhrIo} */(e.target);
if (options.jsonp) {
var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this),
goog.bind(this.handleTileJSONError, this));
} else {
var xhr = new goog.net.XhrIo(new goog.net.CorsXmlHttpFactory());
goog.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) {
if (xhr.isSuccess()) {
var response = /** @type {TileJSON} */(xhr.getResponseJson());
this.handleTileJSONResponse(response);
} else {
this.handleTileJSONError();
}
}, this));
} else {
var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this),
goog.bind(this.handleTileJSONError, this));
xhr.dispose();
}, false, this);
xhr.send(options.url);
}
};