elove

Does an OnRowClickHandler Event work with Feature Layers?

Discussion created by elove on Feb 6, 2012
Latest reply on Feb 27, 2013 by dcastano
Hi,
I have a Feature Layer that display results in a dojo datagrid. I would like to have the ability to click on the row and zoom to the related feature. I have this functionality working for dynamic layers, but when I try to use the same code for Feature Layers it does not work. Is there a difference in how dynamic layers and feature layers are zoomed to? Thanks for any info!!


function onDrawEnd(extent){
      navToolbar.deactivate();
      //id = "control";
      //select features within the draw extent
      var query = new esri.tasks.Query();
      query.geometry = extent;
      featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW,function(features,selectionMethod){
        //add selected features to the grid
        if (document.getElementById("contSel").checked){
          showPointNameGrid();
       
        } else if(document.getElementById("survSel").checked){
         showSurveysNameGrid();
         

        }
        var items = dojo.map(features,function(feature){
          return feature.attributes;
        });
      if(document.getElementById("contSel").checked){
      searchType="selControl2";
        var data = {identifier:"POINT_NAME", items:items};
        var store = new dojo.data.ItemFileReadStore({data:data});
        var grid = dijit.byId('grid4'); 
        grid.setStore(store);
         

       featureLayer.selectFeatures.clear;
       
      } else if (document.getElementById("survSel").checked){
        var data = {identifier:"OBJECTID", items:items};
        var store = new dojo.data.ItemFileReadStore({data:data});
        var grid = dijit.byId('grid5'); 
        grid.setStore(store);
       featureLayer.selectFeatures.clear;
      }  
      });

   
      function toggleSelect (el) 
  {
   navToolbar.deactivate();
   alert(el.checked);
   if (el.checked)
   {
    switch (el.id)
    {
    case 'survSel': 
        searchType="selSurveys2";
     document.getElementById('contSel').checked = false;
      featureLayerUrl = "http://slcarcgisdev1/SLCOGIS/rest/services/public/SurveyorFS/FeatureServer/2";
         featureLayer = new esri.layers.FeatureLayer(featureLayerUrl,{
           mode:esri.layers.FeatureLayer.MODE_ONDEMAND,
           outFields:["OBJECTID"]
           });
         featureLayer.setSelectionSymbol(new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255,255,0,0.5]))); 
   map.addLayer(featureLayer);
     break;    
    
    case 'contSel': 
         searchType="selControl2";
     document.getElementById('survSel').checked = false;
     featureLayerUrl = "http://slcarcgisdev1/SLCOGIS/rest/services/public/SurveyorFS/FeatureServer/0";
         featureLayer = new esri.layers.FeatureLayer(featureLayerUrl,{
           mode:esri.layers.FeatureLayer.MODE_ONDEMAND,
           outFields:["*"]
         });
         featureLayer.setSelectionSymbol(new esri.symbol.SimpleMarkerSymbol().setSize(8).setColor(new dojo.Color([160,214,238])));
   map.addLayer(featureLayer);
     break;
   }
   } else
   {
       switch (el.id)
    {
    case 'survSel': 
     document.getElementById('contSel').checked = true;
     break;
    case 'contSel': 
     document.getElementById('survSel').checked = true;
     break;
   }
   }
 }


//Zoom to Feature when row is clicked
  function onRowClickHandler(evt){ 
 }  if (searchType == "selControl2") { 
   var clickedTaxLotId = grid4.getItem(evt.rowIndex).POINT_NAME; 
   var selectedTaxLot; 
   dojo.forEach(map.graphics.graphics,function(graphic){ 
     if((graphic.attributes) && graphic.attributes.POINT_NAME === clickedTaxLotId){ 
    selectedTaxLot = graphic; 
    //added this part to build infotemplate
     map.infoWindow.setTitle(graphic.getTitle()); 
     map.infoWindow.setContent(graphic.getContent());
      //
    return; 
     } 
        }); 
  
   if ( selectedTaxLot.geometry.declaredClass == 'esri.geometry.Point' ) {
      map.centerAndZoom(selectedTaxLot.geometry, 11)
   var sp = map.toScreen(selectedTaxLot.geometry);
   map.infoWindow.show(selectedTaxLot.geometry, map.getInfoWindowAnchor(sp));
   } else {
   //alert("Polygon");
   var taxLotExtent = selectedTaxLot.geometry.getExtent(); 
   var screenpoint = map.toScreen(selectedTaxLot.geometry.getExtent().getCenter());
   var mappoint = map.toMap(screenpoint);
   map.centerAndZoom(selectedTaxLot.geometry,15);
   
   map.infoWindow.show(taxLotExtent.getCenter(), map.getInfoWindowAnchor(screenpoint));
   }
 
 }
     
      }



Outcomes