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);
});
}
}
});
}
Solved! Go to Solution.
Andrew,
This is where if you look at existing esri widgets you will see the use of lang.hitch(this, function() { format all the time. The use of dojo lang hitch is for keeping the function in scope and then "this" will be the widget and not the event.
Andrew,
This is where if you look at existing esri widgets you will see the use of lang.hitch(this, function() { format all the time. The use of dojo lang hitch is for keeping the function in scope and then "this" will be the widget and not the event.
Thanks, Robert. I'll check that out.