Is there a way in .NET that I can use a QueryTask to executeForExtent as in the JavaScript API?
Looking at the API documentation, I don't see it as a listed method:
That being said, though, I wonder if you could get the extent from the query FeatureSet...
I didn't see an extent property, however, so you may need some code to get the extent.
Hi Mark -
You can achieve the same result with a few extra lines of code. The example below will loop thru the results of a query and union the extents of all features to build the overall extent:
Envelope resultExtent = null;
var filter = new Query("areaname LIKE '%red%'");
var queryTask = new QueryTask(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"));
var results = await queryTask.ExecuteAsync(filter);
var resultCount = results.FeatureSet.Features.Count;
foreach (var f in results.FeatureSet.Features)
{
var ext = f.Geometry.Extent;
if (resultExtent == null)
{
resultExtent = ext;
}
else
{
resultExtent = resultExtent.Union(ext);
}
}
MyMapView.SetViewAsync(resultExtent);
Cool, I was thinking we may need to do something like this!
I'm trying to avoid unnecessary network traffic. It turns out, however, that in the REST API the returnExtentOnly option is only available on feature service layers. Hopefully that will change in the next version of Server.