diff --git a/lib/OpenLayers/Layer/UTFGrid.js b/lib/OpenLayers/Layer/UTFGrid.js index 6c3e1cd8cf..f3a75bf5ee 100644 --- a/lib/OpenLayers/Layer/UTFGrid.js +++ b/lib/OpenLayers/Layer/UTFGrid.js @@ -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 * diff --git a/lib/OpenLayers/Tile/UTFGrid.js b/lib/OpenLayers/Tile/UTFGrid.js index 4db55b94df..b2150bca65 100644 --- a/lib/OpenLayers/Tile/UTFGrid.js +++ b/lib/OpenLayers/Tile/UTFGrid.js @@ -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 {