From fe202cef14e1ea750d7b26ab922dacbb8b5f74e3 Mon Sep 17 00:00:00 2001 From: fredj Date: Fri, 27 Jan 2012 13:23:08 +0100 Subject: [PATCH 1/3] Change getUrlAsync parameters. Instead of giving the function a bound, a scope, a property to update and a callback, only give the bound and a callback. When the url is retrieved by getUrlAsync, simply call the callback with the url as argument and let the caller manage this. --- lib/OpenLayers/Layer/ArcIMS.js | 11 ++--------- lib/OpenLayers/Tile/Image.js | 13 ++++++------- tests/Tile/Image.html | 5 ++--- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/OpenLayers/Layer/ArcIMS.js b/lib/OpenLayers/Layer/ArcIMS.js index 860cd8d770..ddbb37d383 100644 --- a/lib/OpenLayers/Layer/ArcIMS.js +++ b/lib/OpenLayers/Layer/ArcIMS.js @@ -205,12 +205,9 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, { * Parameters: * bounds - {} A bounds representing the bbox for the * request. - * scope - {Object} The scope of the callback method. - * prop - {String} The name of the property in the scoped object to - * recieve the image url. * callback - {Function} Function to call when image url is retrieved. */ - getURLasync: function(bounds, scope, prop, callback) { + getURLasync: function(bounds, callback) { bounds = this.adjustBounds(bounds); // create an arcxml request to generate the image @@ -239,11 +236,7 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var axlResp = new OpenLayers.Format.ArcXML(); var arcxml = axlResp.read(doc); - scope[prop] = this.getUrlOrImage(arcxml.image.output); - - // call the callback function to recieve the updated property on the - // scoped object - callback.apply(scope); + callback(this.getUrlOrImage(arcxml.image.output)); }, scope: this }); diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index d863d7dece..a24242ba95 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -168,15 +168,14 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { this.layer.div.appendChild(this.getTile()); if (this.layer.async) { // Asynchronous image requests call the asynchronous getURL method - // on the layer to fetch an image that covers 'this.bounds', in the scope of - // 'this', setting the 'url' property of the layer itself, and running - // the callback 'initImage' when the image request returns. - var myId = this.asyncRequestId = (this.asyncRequestId || 0) + 1; - this.layer.getURLasync(this.bounds, this, "url", function() { - if (myId == this.asyncRequestId) { + // on the layer to fetch an image that covers 'this.bounds'. + var id = this.asyncRequestId = (this.asyncRequestId || 0) + 1; + this.layer.getURLasync(this.bounds, OpenLayers.Function.bind(function(url) { + if (id == this.asyncRequestId) { + this.url = url; this.initImage(); } - }); + }, this)); } else { // synchronous image requests get the url immediately. this.url = this.layer.getURL(this.bounds); diff --git a/tests/Tile/Image.html b/tests/Tile/Image.html index 9b00113eea..0d67cf1408 100644 --- a/tests/Tile/Image.html +++ b/tests/Tile/Image.html @@ -85,9 +85,8 @@ var layer = new OpenLayers.Layer.WMS( "Name", "http://labs.metacarta.com/TESTURL?", - {layers: 'basic'}, {async: true, getURLasync: function(bounds, scope, url, callback) { - scope.url = this.getURL(bounds); - callback.call(scope); + {layers: 'basic'}, {async: true, getURLasync: function(bounds, callback) { + callback(this.getURL(bounds)); }} ); map.addLayer(layer); From 40806dbe687f4cf3c8cf3f62ce93430b3506fb74 Mon Sep 17 00:00:00 2001 From: fredj Date: Fri, 27 Jan 2012 14:50:34 +0100 Subject: [PATCH 2/3] Pass the callback scope to getURLasync --- lib/OpenLayers/Layer/ArcIMS.js | 5 +++-- lib/OpenLayers/Tile/Image.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Layer/ArcIMS.js b/lib/OpenLayers/Layer/ArcIMS.js index ddbb37d383..eb7dbc983c 100644 --- a/lib/OpenLayers/Layer/ArcIMS.js +++ b/lib/OpenLayers/Layer/ArcIMS.js @@ -206,8 +206,9 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, { * bounds - {} A bounds representing the bbox for the * request. * callback - {Function} Function to call when image url is retrieved. + * scope - {Object} The scope of the callback method. */ - getURLasync: function(bounds, callback) { + getURLasync: function(bounds, callback, scope) { bounds = this.adjustBounds(bounds); // create an arcxml request to generate the image @@ -236,7 +237,7 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var axlResp = new OpenLayers.Format.ArcXML(); var arcxml = axlResp.read(doc); - callback(this.getUrlOrImage(arcxml.image.output)); + callback.call(scope, this.getUrlOrImage(arcxml.image.output)); }, scope: this }); diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index a24242ba95..23a7c9668a 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -170,12 +170,12 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { // Asynchronous image requests call the asynchronous getURL method // on the layer to fetch an image that covers 'this.bounds'. var id = this.asyncRequestId = (this.asyncRequestId || 0) + 1; - this.layer.getURLasync(this.bounds, OpenLayers.Function.bind(function(url) { + this.layer.getURLasync(this.bounds, function(url) { if (id == this.asyncRequestId) { this.url = url; this.initImage(); } - }, this)); + }, this); } else { // synchronous image requests get the url immediately. this.url = this.layer.getURL(this.bounds); From 1f43df33f8d25890cc4b0391b98177a579f51dce Mon Sep 17 00:00:00 2001 From: fredj Date: Mon, 30 Jan 2012 09:04:41 +0100 Subject: [PATCH 3/3] Add a note into notes/2.12.md about getURLasync changes --- notes/2.12.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notes/2.12.md b/notes/2.12.md index ee5ae8843c..a02c465a7a 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -86,6 +86,10 @@ If you were previously using the `OpenLayers.Layer.SphericalMercator.forwardMerc `OpenLayers.Protocol.HTTP` no longer requires `OpenLayers.Format.QueryStringFilter`. It you need this, make sure it is included in your build config file. +## Changes in getURLasync + +The internal `OpenLayers.Layer.getURLasync` function now take a bound, a callback and a scope. The function no longer needs update the passed property but simply to return to url. + ## Deprecated Components A number of properties, methods, and constructors have been marked as deprecated for multiple releases in the 2.x series. For the 2.12 release this deprecated functionality has been moved to a separate deprecated.js file. If you use any of the constructors or methods below, you will have to explicitly include the deprecated.js file in your build (or add it in a separate `