Select to view content in your preferred language

Feature Layer selection not showing on the map

390
0
09-05-2012 11:40 AM
SamirGambhir
Frequent Contributor
Hi,
My application allows users to view State or by District (sub-State) indicators on a map by respective geography. For district-based data, user has the option to view either all districts in the nation or all districts in a selected State. And this is where I have a problem. I have tried to understand the characteristics of feature layer through the description and ESRI's samples for Feature Layer, but when I apply it to my application, it gives me an error. At times it'll display the same set of geographies even if I change the selection of geographies. At other times, it'll not display the new selection and return an 'Uncaught TypeError: Cannot call method '_decRefCount' of null'. I definitely have some error in my code. I have spent way too much time trying to resolve it and I realize I am going around in circles. Please help. My relevant code is below:

My HTML form has a button which runs the function 'viewIndicator' taking selected geography and indicator as input.

JS Code:

...
var stateFeatureLayerM, distFeatureLayerM;
...

function inti() {
...
stateFeatureLayerM = new esri.layers.FeatureLayer("http://myLocation/arcgis/rest/services/State_profile/MapServer/1",{mode: esri.layers.FeatureLayer.MODE_ONDEMAND,outFields: ["*"], maxAllowableOffset: calcOffset(), id:"stateFeatureLayerM", infoTemplate: infoTemplate});
        distFeatureLayerM = new esri.layers.FeatureLayer("http://myLocation/arcgis/rest/services/District_profile/MapServer/1",{mode: esri.layers.FeatureLayer.MODE_ONDEMAND,outFields: ["*"], maxAllowableOffset: calcOffset(), id:"distFeatureLayerM", infoTemplate: infoTemplate});
...
}

function viewIndicator(State) {
       var renderer;
        returnRadioID(); //returns the handle on the selected indicator
        if (!selRadio){
          alert("Please select an indicator to begin mapping");
        }
        else {
          query = new esri.tasks.Query();
          query.outSpatialReference = {"wkid": 102100};
          query.returnGeometry = true;
          query.outFields = ["*"];
          if(State="All India"){
           query.where = "1=1";
          }
          else{
           query.where = "State_name='"+State+"'"; //User selects the name of the State which is used as the input
          }
          var resultContent = "";
       
          if (myElemId==indIdM[indexI][indexJ]){ //refers to a set of arrays that defines the indicators (GrpIdM), respective ids (indIdM) and field names (indField) in the shapefile
           indInfo.innerHTML = " "+GrpIndM[indexI][indexJ];
              resultContent = "<tr>"+GrpIndM[indexI][indexJ]+": <td>${"+indField[indexI][indexJ]+":formatNumber}</td></tr>";
              renderer = new esri.renderer.ClassBreaksRenderer(symbol, indField[indexI][indexJ]);
              if (unitStActiveM===true){ //if user chooses to view the indicators for all of India by States
               infoTemplate.setTitle("<tr>State: <td>${State_name}</tr></td>");
                stateFeatureLayerM.setRenderer(renderer);
              }
              else if (unitDistActiveM===true) { //if user chooses to view the indicators by districts either for All India or by State
                infoTemplate.setTitle("<tr>DISTRICT: <td>${Dist_name}</tr></td><br /><tr>STATE: <td>${State_name}</tr></td>");
                distFeatureLayerM.setRenderer(renderer);
              }
              renderer.addBreak(-Infinity, 19, symbolSet31);
              renderer.addBreak(19,27,symbolSet32);
              renderer.addBreak(27,Infinity,symbolSet33);
             
          }        
          infoTemplate.setContent(resultContent);
          if (unitStActiveM===true){
           mapM.infoWindow.hide();
           if(distFeatureLayerM){
            mapM.removeLayer(distFeatureLayerM);
           }
           if(stateFeatureLayerM){
            mapM.removeLayer(stateFeatureLayerM);
           }
           showLegend();
            mapM.addLayers([stateFeatureLayerM]);
            dojo.connect(stateFeatureLayerM, "onClick", showHighlight); //showHighlight is a function to display infoWindow on mouse click event on the feature layer
           
          }
          else if (unitDistActiveM===true){
           if(distFeatureLayerM){
            distFeatureLayerM.clearSelection();
            mapM.removeLayer(distFeatureLayerM);
           }
           if(stateFeatureLayerM){
            mapM.removeLayer(stateFeatureLayerM);
           }
          distFeatureLayerM.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
          dojo.connect(distFeatureLayerM, "onSelectionComplete", mapM.addLayers(distFeatureLayerM));
          showLegend();
          mapM.addLayers([distFeatureLayerM]);
          dojo.connect(distFeatureLayerM, "onClick", showHighlight);
          }
          show("legendDivHolder");
        }
      }
...
0 Kudos
0 Replies