I am using the ArcGIS API for Javascript 4.3 and want to zoom to features that correspond to a definition expression. It was suggested by @RobErt Scheitlin that I use queryTask.executeForExtent to accomplish this. Although, this may be correct, I am still unsure how to incorporate this into my code.
function selectionDefExpression(selectionArray) {
routeNameStr = selectionArray.join("', '");
var definitionExpression = corridorLayer.definitionExpression = "BOTH_ROUTE_NAME IN ('" + routeNameStr + "')";
return definitionExpression;
}
function deselectionDefExpression() {
return corridorLayer.definitionExpression = "BOTH_ROUTE_NAME IN ('" + "" + "')";
}
var routeName;
var routeNameStr;
var selectedRows = [];
grid.on('dgrid-select', function (event) {
routeName = event.rows[0].data.routeName;
var rows = event.rows;
for (i = 0; i < rows.length; i++) {
selectedRows.push(routeName);
selection = document.getElementById("selectedRoutes");
selection.innerHTML += "<li>" + routeName + "<a href='#'> Remove</a></li>";
}
selectionDefExpression(selectedRows);
if (!corridorURL.visible) {
corridorLayer.visible = true;
}
}, function (error) {
console.log(error)
});
});
grid.on('dgrid-deselect', function (event) {
//var x = [].slice.call(document.querySelectorAll("#selectedRoutes li"));
//x.filter(function(e){
// return e.firstChild.checked
//}).forEach(function (e) {
// e.remove();
//})
deselectionDefExpression();
});
I could also use some assistance on adjusting my definitionExpression based on what is deselected. The act of selection and deselection should make the extend of my features change, thus re-positioning the map as well.
Any suggestions or samples would be greatly appreciated.
Thanks!
Just an update. I was able to get my definition query to adjust dynamically when an item is either selected or deselected.
Jacob,
So are you good to go now?
Unfortunately not. I am still unsure how to apply the queryTask.executeForExtent
Jacob,
So you need a sample of how to do a query for extent then?