change Ajax.js's loadURL() function to take directly function references instead of strings to be dereferenced through a 'handlers' variable. Update code in Tile.WFS... only place it is used.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@487 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-06-01 01:15:23 +00:00
parent c5fc30cf97
commit 60eba3e782
2 changed files with 17 additions and 31 deletions

View File

@@ -5,21 +5,23 @@ OpenLayers.ProxyHost = "/viewer/Crossbrowser/blindproxy.py?url=";
/**
* Ajax reader for OpenLayers
*
* Pay close attention to how this works:
*
*@uri url to do remote XML http get
*@param 'get' format params (x=y&a=b...)
*@who object which is providing a specific callbacks for this request
*@complete the name of the function which must be defined in the callers.handler[] array
*@failure the name of the function which must be defined in the callers.handler[] array
*@who object to handle callbacks for this request
*@complete the function to be called on success
*@failure the function to be called on failure
*
* example usage from a caller:
*
* this.handlers["caps"] = function(request){..}
* OpenLayers.loadURL(url,params,this,"caps");
* caps: function(request) {
* -blah-
* },
*
* OpenLayers.loadURL(url,params,this,caps);
*
* Notice the above example does not provide an error handler; a default empty
* handler is provided which merely logs the error if a failure handler is not supplied
* handler is provided which merely logs the error if a failure handler is not
* supplied
*
*/
@@ -55,31 +57,18 @@ OpenLayers.loadURL = function(uri, params, caller,
// ol.Log.debug("loadURL [" + uri + "]");
var successx;
var failurex;
var bind1 = null;
var bind2 = null;
var success = (onComplete) ? onComplete.bind(caller)
: OpenLayers.nullHandler;
if (onComplete) {
successx = caller.handlers[onComplete];
bind1 = caller;
} else {
successx = OpenLayers.nullHandler;
}
if (onFailure) {
failurex = caller.handlers[onFailure];
bind2=caller;
} else {
failurex = OpenLayers.nullHandler;
}
var failure = (onFailure) ? onFailure.bind(caller)
: OpenLayers.nullHandler;
// from prototype.js
new Ajax.Request(uri,
{ method: 'get',
parameters: params,
onComplete: successx.bind(bind1),
onFailure: failurex.bind(bind2)
onComplete: success,
onFailure: failure
}
);
};

View File

@@ -26,16 +26,13 @@ OpenLayers.Tile.WFS.prototype =
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
this.features = new Array();
this.handlers = new Array();
this.handlers["requestSuccess"] = this.requestSuccess;
},
/**
*/
draw:function() {
OpenLayers.Tile.prototype.draw.apply(this, arguments);
this.loadFeaturesForRegion("requestSuccess");
this.loadFeaturesForRegion(this.requestSuccess);
},