I am trying to add a tool to my app where the user can perform a selection on multiple layers and have the results from all layers return to one datagrid. I feel like I am close but I am missing something. I am using an IdentifyTask to do the selection. Identifying the features is working fine-at the end of drawing my selection, graphics are drawn and the extent zooms to the selection area. Getting data into the grid is my problem. Because I am selecting from multiple layers, I am trying to push the selected feature's layerName and value. Can anyone see whjat I am missing? Here is the JS:
selectFeaturesTask = new IdentifyTask("http://summitmaps.summitoh.net/arcgis/rest/services/CountyEngineer_MercatorPublic/MapServer/");
selectFeaturesParams = new IdentifyParameters();
selectFeaturesParams.tolerance = 3;
selectFeaturesParams.returnGeometry = true;
selectFeaturesParams.layerIds = [0, 1, 2, 3, 4, 5, 6, 7, 8];
selectFeaturesParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
selectFeaturesParams.width = map.width;
selectFeaturesParams.height = map.height;
selectToolbar = new esri.toolbars.Draw(map);
dojo.connect(selectToolbar, "onDrawEnd", onSelectEnd);
function onSelectEnd(extent) {
selectToolbar.deactivate();
executeFeatureSelection(extent);
}
function executeFeatureSelection(geom) {
map.graphics.clear();
selectFeaturesParams.geometry = geom;
selectFeaturesParams.mapExtent = map.extent;
selectFeaturesTask.execute(selectFeaturesParams, showSelectionResults)
}
function showSelectionResults(results) {
console.log('Features found: ', results);
map.graphics.clear();
var dataForGrid = [];
var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
var markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
arrayUtils.map(results, function(result) {
var graphic = result.feature;
switch (graphic.geometry.type) {
case "point":
graphic.setSymbol(markerSymbol);
break;
case "polyline":
graphic.setSymbol(lineSymbol);
break;
case "polygon":
graphic.setSymbol(polygonSymbol);
break;
}
map.graphics.add(graphic);
return result.feature.attributes;
var layer = result.layerName;
var value = result.value;
dataForGrid.push([layer, value]);
graphic.setSymbol(graphic);
map.graphics.add(graphic);
return result.feature.attributes;
});
var selectData = {
items: dataForGrid
};
var selectStore = new ItemFileReadStore({
data: selectData
});
selectGrid.setStore(selectStore);
selectGrid.on("rowclick", onRowClickHandler);
var graExtent = esri.graphicsExtent(map.graphics.graphics);
map.setExtent(graExtent, true);
}
And the HTML showing the grid:
<div data-dojo-type="dijit/layout/ContentPane" title="Select From Multiple Layers">
Select from multiple layers:
<button dojoType="dijit.form.Button" onClick="selectToolbar.activate(esri.toolbars.Draw.EXTENT);">Select</button>
<table data-dojo-type="dojox.grid.DataGrid" jsid="selectGrid" id="selectGrid">
<thead>
<tr>
<th field="0">Layer</th>
<th field="1">Value</th>
</tr>
</thead>
</table>
</div>