Option for loading utfgrid via jsonp

This commit is contained in:
Matthew Perry
2012-02-13 16:56:35 -08:00
parent 5857af5fec
commit 867080a074
2 changed files with 35 additions and 22 deletions

View File

@@ -82,6 +82,20 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
*/ */
serverResolutions: null, 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 * Constructor: OpenLayers.Layer.UTFGrid
* *

View File

@@ -107,28 +107,27 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
} }
this.url = this.layer.getURL(this.bounds); this.url = this.layer.getURL(this.bounds);
var resp = new OpenLayers.Protocol.Response({requestType: "read"}); if (this.layer.useJSONP) {
resp.priv = OpenLayers.Request.GET({ // Use JSONP method to avoid xbrowser polucy
url: this.url, var that = this;
callback: this.parseData, var cback = function(resp) {
scope: this that.json = resp.data;
}); };
var ols = new OpenLayers.Protocol.Script({
/* url: this.url,
* MP TODO Investigate JSONP method to avoid xbrowser polucy callback: cback,
* scope: this
grid = function(e) { });
console.log(e); var res = ols.read();
}; } else {
// Use standard AJAX call
var ols = new OpenLayers.Protocol.Script({ var resp = new OpenLayers.Protocol.Response({requestType: "read"});
url: "http://tiles/world_utfgrid/2/2/1.json", resp.priv = OpenLayers.Request.GET({
callback: grid, url: this.url,
scope: this callback: this.parseData,
}); scope: this
var res = ols.read(); });
console.log(res.priv); }
*/
this.positionTile(); this.positionTile();
} else { } else {