Add option to load TileJSON via XHR

This commit is contained in:
Petr Sloup
2016-01-05 13:10:50 +01:00
parent d9b89a8ebe
commit ffd9ace84e
2 changed files with 25 additions and 3 deletions
+9
View File
@@ -5179,6 +5179,7 @@ olx.source.TileArcGISRestOptions.prototype.urls;
* reprojectionErrorThreshold: (number|undefined), * reprojectionErrorThreshold: (number|undefined),
* tileLoadFunction: (ol.TileLoadFunctionType|undefined), * tileLoadFunction: (ol.TileLoadFunctionType|undefined),
* url: string, * url: string,
* useXhr: (boolean|undefined),
* wrapX: (boolean|undefined)}} * wrapX: (boolean|undefined)}}
* @api * @api
*/ */
@@ -5232,6 +5233,14 @@ olx.source.TileJSONOptions.prototype.tileLoadFunction;
olx.source.TileJSONOptions.prototype.url; 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`. * Whether to wrap the world horizontally. Default is `true`.
* @type {boolean|undefined} * @type {boolean|undefined}
+16 -3
View File
@@ -9,6 +9,7 @@ goog.provide('ol.tilejson');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.net.Jsonp'); goog.require('goog.net.Jsonp');
goog.require('goog.net.XhrIo');
goog.require('ol.Attribution'); goog.require('ol.Attribution');
goog.require('ol.TileRange'); goog.require('ol.TileRange');
goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunction');
@@ -40,9 +41,21 @@ ol.source.TileJSON = function(options) {
wrapX: options.wrapX !== undefined ? options.wrapX : true wrapX: options.wrapX !== undefined ? options.wrapX : true
}); });
var request = new goog.net.Jsonp(options.url); if (options.useXhr) {
request.send(undefined, goog.bind(this.handleTileJSONResponse, this), goog.net.XhrIo.send(options.url, goog.bind(function(e) {
goog.bind(this.handleTileJSONError, this)); 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); goog.inherits(ol.source.TileJSON, ol.source.TileImage);