Send selected item's attribute to form items

559
1
12-18-2012 11:56 AM
KellyNitzman
New Contributor II
I am building a javascript webapp with the ability to identify a point & send the info through the form provided in the left-pane.
I am trying to find a way to automatically send the attributes of the selected point on my map to the form fields in my left-pane and then change when I select a different point.
Any thoughts welcome, and thanks ahead of time!
0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor
Hi Kelly,

Here is an example I was able to get to work with the dojox.grid.DataGrid:

//create Identify and Clear buttons to start/stop identifying features
function createButtons(){
    toolBar = new esri.toolbars.Draw(map);
    button1 = new dijit.form.Button({
        id: "identifyButton",
        showLabel: true,
        checked: false,
        label: "Identify",
        onClick: function(){
                toolBar.activate(esri.toolbars.Draw.POINT);
                dojo.connect(featureLayer, "onClick", populateGrid)
            },
    }).placeAt(dojo.byId("buttons"));
    
    button2 = new dijit.form.Button({
        id: "clearButton",
        showLabel: true,
        checked: false,
        label: "Clear",
        onClick: function(){
                clear();
        },
    }).placeAt(dojo.byId("buttons"));
}

//populate grid in left pane
function populateGrid(evt){  
  var query = new esri.tasks.Query();
  query.geometry = pointToExtent(map, evt.mapPoint, 4);
  
  //select features based on map click
  featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW, function(features, selectionMethod){
      var items = dojo.map(features,function(feature){
          return feature.attributes;
      });

      var data = {
        identifier:"objectid",
        items:items};
      
      //add attributes to grid
      store = new dojo.data.ItemFileReadStore({data:data});
      var grid = dijit.byId("grid");
      grid.setStore(store);   
   });
} 

//retrieve extent of map click
function pointToExtent(map, point, toleranceInPixel) {
       var pixelWidth = map.extent.getWidth() / map.width;
       var toleraceInMapCoords = toleranceInPixel * pixelWidth;
       return new esri.geometry.Extent( point.x - toleraceInMapCoords,
                    point.y - toleraceInMapCoords,
                    point.x + toleraceInMapCoords,
                    point.y + toleraceInMapCoords,
                    map.spatialReference );                           
}

//clear grid
function clear(){
    toolBar.deactivate();
    featureLayer.clearSelection()
    var items = "";
    var data = {
        identifier:"",
        items:items}
    
    store = new dojo.data.ItemFileReadStore({data:data});
    var grid = dijit.byId('grid');
    grid.setStore(store);
}
0 Kudos