Select to view content in your preferred language

Related Records to display multiple selection symbols

780
0
08-03-2011 10:46 AM
deleted-user-K_IRAXrpGKsG
Deactivated User
Hello,

I'm currently using the related records query on my map and it is working fine. However, I would like the results of the related records to show up as selected symbols on the map rather than results in a table just like running a standard query and setting a graphic over the results.

Here is the code I'm using for the related query. If anyone has any ideas I would greatly appreciate it!

function findRelatedRecords(features) {
  console.log('finding related records', features, features.length);
  var relatedTopsQuery = new esri.tasks.RelationshipQuery();
  relatedTopsQuery.outFields = ["*"];
  relatedTopsQuery.relationshipId = 0;
  // Create array of objectIds
  var ids = dojo.map(features, function (f) {
    return f.attributes.ObjectID;
  });

  console.log('ids: ', ids);
  relatedTopsQuery.objectIds = ids;
  relatedEventsLayer.queryRelatedFeatures(relatedTopsQuery, function (recs) {
    console.log('related: ', recs);
    // Build an array for the grid
    var items = [];
    // Recs is an object where each property is the objectid for a feautre
    // with related records
    for (id in recs) {
        
  // For each related record, create an item which will correspond to
      // a row in the data grid
      dojo.forEach(recs[id].features, function (feat) {
     var graphic = feat;
    graphic.setSymbol(selectionSymbol);
  //Set the infoTemplate.
  graphic.setInfoTemplate(infoTemplate);
  //Add graphic to the map graphics layer.
  map.graphics.add(graphic);

    items.push(feat.attributes);
      });
    }

    //Create data object to be used in store
    var data = {
      // Identifier and label are case-sensitive
      identifier: "OBJECTID",
      //This field needs to have unique values
      label: "OBJECTID",
      items: items
    };

    //Create data store and bind to grid.
    store = new dojo.data.ItemFileReadStore({
      data: data
    });
    grid.setStore(store);
    grid.setQuery({
      OBJECTID: '*'
    });
  });
}

//Runs the reltaed table query and displays results
function findRelatedEvents(evt) {
        grid.setStore(null);
        var selectionQuery = new esri.tasks.Query();
        var tol = map.extent.getWidth()/map.width * 5;
        var x = evt.mapPoint.x;
        var y = evt.mapPoint.y;
        var queryExtent = new esri.geometry.Extent(x-tol,y-tol,x+tol,y+tol,evt.mapPoint.spatialReference);
        selectionQuery.geometry = queryExtent;
  
        relatedEventsLayer.selectFeatures(selectionQuery,esri.layers.FeatureLayer.SELECTION_NEW);
  relatedEventsLayer.setSelectionSymbol(selectionSymbol);
      } 


Thanks!
Patrick
0 Kudos
0 Replies