i have passed the variable to javascript but am unable to see how to pass the variable to the map to zoom to the feature(QueryTask?)
i can't seem to find a simple example of passing a variable to the query task to pan and zoom
//Define a new Query and QueryTask queryTask = new esri.tasks.QueryTask(UrlToYourLayer); query = new esri.tasks.Query(); query.returnGeometry = true; query.outFields = ["field1","field2"]; //The query's where clause will be attribute query to find the feature query.where = "'OBJECTID = 123'"; //Run the query. Its results are returned in the function showResults queryTask.execute(query,showResults); //results is an array of any found features. Assuming you only want the first feature: function showResults(results) { var result = results[0]; var extent = result.geometry.getExtent().expand(5.0); map.setExtent(extent); }
function showResults(results) { var result = results.features[0]; var extent = result.geometry.getExtent().expand(5.0); map.setExtent(esri.geometry.geographicToWebMercator(extent)); }
I need to zoom to ALL the features returned, not just the 1st feature. I tried to modify your sample but was not getting anywhere.
function showResults(results) { //This function is run when the query has finished. //It zooms the map to the extent of the first feature returned by the query. var result = results.features[0]; var extent = result.geometry.getExtent().expand(5.0);
var fullExtent; for each result in results: thisExtent = result.geometry.getExtent(); fullExtent.union(fullExtent);