Merge pull request #4619 from klokantech/tilejson-xhr

Add option to load TileJSON via XHR
This commit is contained in:
Petr Sloup
2016-01-05 13:48:23 +01:00
2 changed files with 25 additions and 3 deletions

View File

@@ -5179,6 +5179,7 @@ olx.source.TileArcGISRestOptions.prototype.urls;
* reprojectionErrorThreshold: (number|undefined),
* tileLoadFunction: (ol.TileLoadFunctionType|undefined),
* url: string,
* useXhr: (boolean|undefined),
* wrapX: (boolean|undefined)}}
* @api
*/
@@ -5232,6 +5233,14 @@ olx.source.TileJSONOptions.prototype.tileLoadFunction;
olx.source.TileJSONOptions.prototype.url;
/**
* Use XmlHttpRequest to load the TileJSON. Default is `false`.
* @type {boolean|undefined}
* @api
*/
olx.source.TileJSONOptions.prototype.useXhr;
/**
* Whether to wrap the world horizontally. Default is `true`.
* @type {boolean|undefined}

View File

@@ -9,6 +9,7 @@ goog.provide('ol.tilejson');
goog.require('goog.asserts');
goog.require('goog.net.Jsonp');
goog.require('goog.net.XhrIo');
goog.require('ol.Attribution');
goog.require('ol.TileRange');
goog.require('ol.TileUrlFunction');
@@ -40,9 +41,21 @@ ol.source.TileJSON = function(options) {
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this),
goog.bind(this.handleTileJSONError, this));
if (options.useXhr) {
goog.net.XhrIo.send(options.url, goog.bind(function(e) {
var xhr = /** @type {goog.net.XhrIo} */(e.target);
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));
}
};
goog.inherits(ol.source.TileJSON, ol.source.TileImage);