queryTask.execute(query, function (featureSet) { var resultFeatures = featureSet.features; var myFeatureExtent = esri.graphicsUtils.graphicsExtent(resultFeatures); map.setExtent(myFeatureExtent); var layerDefinitions = []; layerDefinitions[0] = queryString; //siteslayer.setLayerDefinitions(layerDefinitions); });
var extent = featureSet.features[0].geometry.getExtent(); for (var i = 1; i < featureSet.features.length; i++) { extent = extent.union(featureSet.features.geometry.getExtent()); }
var selExtent = graphicsUtils.graphicsExtent(featureSet.features);
For future references... It's 2020 and I'm having the same issue you described using graphicsUtils.graphicsExtent with a point layer. I develop using js api version 3.x. Turns out, that for some reason one feature in the array returned from the REST query is coming with the following geometry:
{
"geometry": {
"x": "NaN",
"y": "NaN",
"spatialReference": ...
},
"attributes": {...
}
}
Our users add points to this layer using Arcmap 10.5 and Arcmap 10.7 and I couldn't find out why sometimes this null geometry happens.
If you query the database to view this bad registry with sqldeveloper, you will find some null data inside shape column:
At least, that was what happened here. I would recomend checking the array for NaN data before using graphicsUtils.graphicsExtent to filter out bad data like this:
//note that NaN here is a string
var goodFeatures = features.filter(f => f.geometry.x === "NaN" || f.geometry.y === "NaN");
var extent = graphicsUtils.graphicsExtent(goodFeatures)
When I set the map with a bad extent, the map simply disapear and breaks the app.