AnsweredAssumed Answered

How to correctly reference widget in event handlers and callbacks?

Question asked by alterwiel on Sep 30, 2015
Latest reply on Sep 30, 2015 by alterwiel

Say I have an event handler in my custom widget that handles a map click and executes an identify task. Within the event handler function and also the callback function for the identify.execute function I would like to reference the widget. Using the "this" keyword doesn't give the widget, it gives the event object or the window  object. The code below shows how I'm doing this, but I think this is not the right way.

 

_handleMapClick: function (event) {

var identifyTask = new IdentifyTask(url);

                    var identifyParams = new IdentifyParameters();

                    var layerQuery = new Query();

                    identifyParams.tolerance = 3;

                    identifyParams.returnGeometry = true;

                    identifyParams.layerIds = [159];

                    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;

                    identifyParams.width = landIdWidget.map.width;

                    identifyParams.height = landIdWidget.map.height;

                    identifyParams.geometry = event.mapPoint;

                    identifyParams.mapExtent = landIdWidget.map.extent;

 

                    identifyTask.execute(identifyParams, function (response) {

                                layerQuery.where = "ID = " + parId;

                                deferred = landIdWidget.that._myFeatureLayer.selectFeatures(layerQuery,

                                    FeatureLayer.SELECTION_NEW, function (selected) {

                                        landIdWidget.that._showParcelInfo(selected);

                                    });

                            }

                        }

                    });

}

Outcomes