Option for loading utfgrid via jsonp
This commit is contained in:
@@ -82,6 +82,20 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
*/
|
||||
serverResolutions: null,
|
||||
|
||||
/**
|
||||
* APIProperty: useJSONP
|
||||
* Should we use a JSONP script approach instead of a standard AJAX call?
|
||||
*
|
||||
* Set to true for using utfgrids from another server.
|
||||
* Avoids same-domain policy restrictions.
|
||||
* Note that this only works if the server accepts
|
||||
* the callback GET parameter and dynamically
|
||||
* wraps the returned json in a function call.
|
||||
*
|
||||
* {Boolean} Default is false
|
||||
*/
|
||||
useJSONP: false,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Layer.UTFGrid
|
||||
*
|
||||
|
||||
@@ -107,28 +107,27 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
|
||||
}
|
||||
this.url = this.layer.getURL(this.bounds);
|
||||
|
||||
var resp = new OpenLayers.Protocol.Response({requestType: "read"});
|
||||
resp.priv = OpenLayers.Request.GET({
|
||||
url: this.url,
|
||||
callback: this.parseData,
|
||||
scope: this
|
||||
});
|
||||
|
||||
/*
|
||||
* MP TODO Investigate JSONP method to avoid xbrowser polucy
|
||||
*
|
||||
grid = function(e) {
|
||||
console.log(e);
|
||||
};
|
||||
|
||||
var ols = new OpenLayers.Protocol.Script({
|
||||
url: "http://tiles/world_utfgrid/2/2/1.json",
|
||||
callback: grid,
|
||||
scope: this
|
||||
});
|
||||
var res = ols.read();
|
||||
console.log(res.priv);
|
||||
*/
|
||||
if (this.layer.useJSONP) {
|
||||
// Use JSONP method to avoid xbrowser polucy
|
||||
var that = this;
|
||||
var cback = function(resp) {
|
||||
that.json = resp.data;
|
||||
};
|
||||
var ols = new OpenLayers.Protocol.Script({
|
||||
url: this.url,
|
||||
callback: cback,
|
||||
scope: this
|
||||
});
|
||||
var res = ols.read();
|
||||
} else {
|
||||
// Use standard AJAX call
|
||||
var resp = new OpenLayers.Protocol.Response({requestType: "read"});
|
||||
resp.priv = OpenLayers.Request.GET({
|
||||
url: this.url,
|
||||
callback: this.parseData,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
|
||||
this.positionTile();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user