Monday, November 10, 2008

Web ADF JavaScript: How to determine event argument contents

As many Web ADF developers already know, the 9.3 release contains a new public JavaScript library built on the Microsoft AJAX library. A host of ADF client controls and components (e.g. Map, Toolbar, etc.) maintain event handlers which enable ADF developers to listen for and interact with actions solely on the client (browser). Unfortunately the ADF JavaScript library reference does not contain the event argument types for event handlers. While this will be rectified at some point in the future, there is another option. You can determine the event argument types by looking in ADF JavaScript debug files installed in two locations:

  • <IIS Root>\aspnet_client\ESRI\WebADF\JavaScript
  • <ArcGIS Install>\DotNet\VirtualRootDir\aspnet_client\ESRI\WebADF\JavaScript
Search for references to this._raiseEvent in all debug JavaScript (*.debug.js) files. The first parameter to the _raiseEvent function is the type of event (e.g. 'click'). Any subsequent parameter is included as an event argument to any handler. You can look at the code to determine what the event argument contains.

For example, in the ESRI.ADF.UI.Map.debug.js file you’ll notice the click event is raised in the _onMouseUp function (shortened for the example):

_onMouseUp : function(evt) {
var e = this._makeMouseEventRelativeToMap(evt,true);
. . .

The browser event is modified in the _makeMouseEventRelativeToMap function to set its coordinate property to a new ESRI.ADF.Geometries.Point as the location of the user click on the map client control. In this case, the _raiseEvent function for 'click' indicates that an event argument is included, is modified, and the type is not an array. In other cases, no event argument is passed (e.g. map's extentChanging event) or the event argument contains an array with many objects (e.g. map’s extentChanged event).

The first parameter to an event handler is the sender, which is the client component on which the event was raised. Any subsequent argument, if defined, matches the event argument in the call to _raiseEvent.

No comments: