Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have scenario in which I have to select features drawing a polygon and and get the attribute values in to a tables or lists.The features on the map consist of polygon, line,point at the same time so when he selects the features according to layer name I have to bind to separate tables.Is there any example tackling this scenario.

share|improve this question
up vote 4 down vote accepted

Adapted from some code I have -- untested here -- the key is using the dojo DeferredList so that you know when all the queries to the seperate layers have returned.

When building the table I would reccomend the DataTables jquery based library -- works well for me, lots of features.

function selectFeaturesFromPolygon() {
    drawToolbarDrawEndEvent = dojo.connect(drawToolbar, 'onDrawEnd', function (geom) {
        var aDeferreds = [],
            query = new esri.tasks.Query();

        query.geometry = geom;
        query.returnGeometry = true;
        query.outFields = ["*"];

        if (geom) {
            queryTask = new esri.tasks.QueryTask(FeatureServiceName1);
            //push multiple queries into this array

            queryTask = new esri.tasks.QueryTask(FeatureServiceName2);
            //push multiple queries into this array

            queryTask = new esri.tasks.QueryTask(FeatureServiceName3);
            //push multiple queries into this array

            // create a deferred list to aggregate the state for all identify queries
            deferredList = new dojo.DeferredList(aDeferreds);
            deferredList.then(function (aQueryResults) {
                //returns when all queries have finished
                //"aQueryResults" is 2D array of results
                //array[n][0] boolean true or false, success or failure of individual call
                //array[n][1] is the array of identity results returned
            }, function (err) {
                console.log("Error Occurred: " + err);

//datatable usage would be like this -- this is just a sample, you need to parse aQueryResults
//and put the values into cols, rows and data
//add some html somewhere <table id="tableSearchResults" cellpadding="0" cellspacing="0" border="0"   style="color: black;"></table>
function buildTableFromMultipleResults(aQueryResults) {

    var cols = [],
        row = [],
        data = [];

    //create columns
    $.each(results.fields, function (index, value) {
        cols.push({ 'sTitle': });

    //create rows and push into data
    $.each(results.features, function (index, value) {
        row = [];
        $.each(value.attributes, function (index2, value2) {

    oTable = $('#tableSearchResults').dataTable({
        "aaData": data,
        "aoColumns": cols,
        "aoColumnDefs": [{ "bSortable": false, "aTargets": [0, 1] },
        { "bSearchable": false, "aTargets": [0, 1] },
        { "bVisible": false, "aTargets": currentSearchResults.hiddenFields },
        { "fnRender": function (o, val) {
            if (val !== null) {
                return Math.round(val * 1000) / 1000;
            else {
                return "";
        }, "aTargets": currentSearchResults.rounded
        "aaSorting": [[5, 'asc']],
        "iDisplayLength": 25,
        "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        "bDestroy": true,
        "sDom": 'liT<"clear">tp'    
share|improve this answer

I don't think there is one sample doing what you need, but you should have a look at these two samples:

You will see in the second sample, that we need to pass a geometry to the query task. In your case, the geometry will come from the user drawn geometry.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.