Combine Feature Layer Selection and Layer Toggle

581
0
05-17-2012 06:30 PM
JohnWall
Occasional Contributor
I am trying to combine the code that is found within the Feature Layer Selection and Layer Toggle examples, but I have been having some serious issues doing this. I think I have narrowed down the issue to this bit of code:

[INDENT]featureLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map...", {
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          "imageParameters": imageParameters,
          infoTemplate: infoTemplate,
          outFields: ["*"]
        });
[/INDENT]

What I would like to be able to do is turn on and off multiple layers along with selecting the features within those layers. I would like to be able to select individual and multiple features within a given layer as one can see within the Feature Layer Selection example. Can anyone give me some hints and/or suggestions? Thanks in advance!

Here is more of my code in context:
[INDENT]function init() {
               
        map = new esri.Map("map");
        dojo.connect(map, 'onLoad', function(map) {
          //resize the map when the browser resizes
          dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
        });

        //BaseMap ============================================================
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
        map.addLayer(basemap);
       
        //Image Parameters ============================================================ Working On
        var imageParameters = new esri.layers.ImageParameters();
        imageParameters.layerIds = [2];
        imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
        //can also be: LAYER_OPTION_EXCLUDE, LAYER_OPTION_HIDE, LAYER_OPTION_INCLUDE
       
        //Feature Selection ============================================================ Working On
        dojo.connect(map, 'onLoad', initSelectToolbar);
        var fieldsSelectionSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255,0,0]));
        //fieldsSelectionSymbol.setOutline(new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2));
      
        var content = "<b>City</b>: ${CITY_NAME}";
        var infoTemplate = new esri.InfoTemplate("${FIELD_NAME}", content);

        featureLayer = new esri.layers.FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map...",{
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          imageParameters: imageParameters,
          infoTemplate: infoTemplate,
          outFields: ["*"]
        });

        featureLayer.setSelectionSymbol(fieldsSelectionSymbol);

        dojo.connect(featureLayer, "onSelectionComplete");

        dojo.connect(featureLayer, "onSelectionClear", function(features) {
          dojo.byId('messages').innerHTML = "<i>No Selected Fields</i>";
        });
       
        map.addLayer(featureLayer);
//FUNCTION: Feature Selection ============================================================ Working On
      function initSelectToolbar(map) {
        selectionToolbar = new esri.toolbars.Draw(map);
        var selectQuery = new esri.tasks.Query();
       
        dojo.connect(selectionToolbar, "onDrawEnd", function(geometry) {
          selectionToolbar.deactivate();
          selectQuery.geometry = geometry;
          featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
        });
       
      }
     
      //FUNCTIONS: Layer List ============================================================
      function updateLayerVisibility() {
        var inputs = dojo.query(".list_item"), input;
        //in this application layer 2 is always on.
        visible = [2];
        for (var i=0, il=inputs.length; i<il; i++) {
          if (inputs.checked) {
            visible.push(inputs.id);
          }
        }
         //if there aren't any layers visible set the array value to = -1
        if(visible.length === 0){
          visible.push(-1);
        }

        featureLayer.setVisibleLayers(visible);
      }
     
      dojo.addOnLoad(init);
[/INDENT]
Here is the relevant the HTML
[INDENT]<!--Layer List-->
          <br />
          Layer List : <span id="layer_list">
            <input type='checkbox' class='list_item' id='0' value=0 onclick='updateLayerVisibility();'/>Cities  
            <input type='checkbox' class='list_item' id='1' value=1 onclick='updateLayerVisibility();'/>Rivers  
          </span><br />
          <br />
     
          <!--Feature Selection-->
          <button dojoType="dijit.form.Button" onClick="selectionToolbar.activate(esri.toolbars.Draw.EXTENT);">Select Features</button>
          <button dojoType="dijit.form.Button" onClick="featureLayer.clearSelection();">Clear Selection</button><br>
          <span id="messages"></span>[/INDENT]
0 Kudos
0 Replies