I want to be able to use the point of an address as the input geometry to my IdentifyTask. I'm having a scope problem. I can see that my identify task is finding the county, but I'm not calling/returning that name properly. I'm sure I'm not using lang.hitch properly, but I can tell that select-result was completing before runIdentify ever started.
searchTool is my Search widget.
on(searchTool,'select-result', function (evt){
var addr = evt.result.name;
app.addrExt = evt.result.extent;
myIdentify.runIdentify().then(lang.hitch(this,function(response){
runQueries(app.countyName);
})
)
})
myIdentify.js
define ([ "dojo/on", "esri/tasks/IdentifyTask","esri/tasks/IdentifyParameters",
"esri/geometry/Point","esri/geometry/Extent","esri/geometry/webMercatorUtils"
], function ( on,IdentifyTask,IdentifyParameters,Point,Extent,webMercatorUtils
) {
return {
initIdentify: function(url){
app.idTask = new IdentifyTask(url);
app.idParams = new IdentifyParameters();
},
runIdentify: function(){
var webPt = webMercatorUtils.lngLatToXY(app.addrExt.xmin, app.addrExt.ymin);
var point = new Point(webPt[0], webPt[1], app.spatialReference);
app.idParams.geometry = point;
var pxWidth = app.map.extent.getWidth() / app.map.width;
var padding = 3 * pxWidth;
var qGeom = new Extent({
"xmin": point.x - padding,
"ymin": point.y - padding,
"xmax": point.x + padding,
"ymax": point.y + padding,
"spatialReference": app.spatialReference
});
app.idParams.geometry = point;
app.idParams.mapExtent = qGeom;
app.idParams.tolerance = 1;
app.idParams.returnGeometry = true;
app.idTask.execute(app.idParams).then(function(results){
app.countyName = results[0].value; // the identify is finding the county name here, I'm just not returning it properly
});
return app.countyName;
}
}
});