AnsweredAssumed Answered

onClick select features from multiple layers/popup issue

Question asked by rcsellman on Mar 5, 2015
Latest reply on Mar 5, 2015 by rcsellman

Hello,

 

I am trying to set up an app that gives the user the ability to choose which layers they want to identify.  I have multiple feature layers added to the map each in selection mode and each has an assigned infoTemplate.  I have an onClick event that fires all selections.  I want the results of the multiple queries to be shown in a popup.  The queries all execute just fine, but popups are showing for only one of the layers being selected.  Here is a a quick example of the code I am trying to implement:

 

var soiltemplate = new PopupTemplate({
          title: "Soil"
        });
   
  var soils = "http://summitmaps.summitoh.net/arcgis/rest/services/Environmental_Mercator/MapServer/2";
         soilsFeatureLayer = new esri.layers.FeatureLayer(soils, {
             mode: esri.layers.FeatureLayer.MODE_SELECTION,
             visible: true,
             outFields: ["*"],
  infoTemplate: soiltemplate
         });
         var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100, 100, 100]), 2), new dojo.Color([0, 0, 255, 0.20]));
         soilsFeatureLayer.setSelectionSymbol(symbol);
         
  var canopytemplate = new InfoTemplate({
          title: "Canopy"
        });

  var canopy = "http://summitmaps.summitoh.net/arcgis/rest/services/Environmental_Mercator/MapServer/5";
         canopyFeatureLayer = new esri.layers.FeatureLayer(canopy, {
             mode: esri.layers.FeatureLayer.MODE_SELECTION,
             visible: true,
             outFields: ["*"],
  infoTemplate: canopytemplate
         });
         var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100, 100, 100]), 2), new dojo.Color([0, 0, 255, 0.20]));
         canopyFeatureLayer.setSelectionSymbol(symbol);

var clickEvent = connect.connect(map, "onClick", selectFeatures);

  function selectFeatures(evt){

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



  var query = new esri.tasks.Query();
  query.geometry = pointToExtent(map, evt.mapPoint, 2);



  var deferredCanopy = canopyFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW); 
  map.infoWindow.setFeatures([deferredCanopy ]);
  map.infoWindow.show(evt.mapPoint);


  var deferredSoil = soilsFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW); 
  map.infoWindow.setFeatures([deferredSoil]);
  map.infoWindow.show(evt.mapPoint);
   
  }

 

Using the above snippet of code, the popup for the soilsFeatureLayer is shown, not the canopyFeatureLayer.  I have to be missing something stupid, or maybe this is a bad approach all together?

 

Thanks for any help in advance!

Outcomes