Popup content on multiple features

2406
2
Jump to solution
03-16-2012 06:00 AM
ChadWilcomb
New Contributor III
I have a popup that is called in an onclick event on the map. The click selects features from a feature layer within 20 pixels of the click, so the results can contain multiple features. I have the popup showing mutliple features but I cannot set the content of the popup to show the features' information. I have attached an image of the popup. I can set the content when using InfoWindow on the feature layer, but then I only get one feature (the one on top). Any suggestions?

Thanks,
Chad

Here is my code...

function init() {      lowerMHExtent_SP = new esri.geometry.Extent({ "xmin": 975650, "ymin": 194070, "xmax": 991760, "ymax": 203000, "spatialReference": { "wkid": 2263} });      //Define the Popup for InfoWindow     var popup = new esri.dijit.Popup(null, dojo.create("div"));     popup.setContent("<b>Permit Number</b>: ${PermitNumber}");       map = new esri.Map("map", {         extent: lowerMHExtent_SP,         width: 800,         infoWindow: popup,         height: 600,         logo: false     });       var basemap_gray = "http://myserver/ArcGIS/rest/services/basemap_gray/MapServer";     var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemap_gray);     map.addLayer(basemap);      dojo.connect(map, "onClick", function (evt) {         var query = new esri.tasks.Query();         //Query within 20 pixels of click point         query.geometry = pointToExtent(map, evt.mapPoint, 20);                  //flPermits is a feature layer that has had setDefinitionExpression applied to show only select features         var deferred = flPermits.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);                      popup.setFeatures([deferred]);         popup.show(evt.mapPoint);      }); }


[ATTACH=CONFIG]12761[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
ChadWilcomb
New Contributor III

Thanks Ken, that wasn't exactly what I was trying to do but taking another look at the IdentifyTask example helped me to get where I needed to go. I actually have two feature layers that I want to get results from (Segments and Intersections). I was able to used the deferred.addCallback and the dojo.map methods from the IdentifyTask example to combine the results and get the content into the popup. In case anyone is interested, here is what I came up with...

dojo.connect(map, "onClick", function (evt) {
    var query = new esri.tasks.Query();
    //Query within 20 pixels of click point
    query.geometry = pointToExtent(map, evt.mapPoint, 20);
    //I have two feature layers with setDefinitionExpression applied (intersections, segments)
    var deferred = featureLayerSeg.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
    deferred.addCallback(function (responseSeg) {
      var response;
      var deferInt = featureLayerInt.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
      deferInt.addCallback(function (responseInt) {
        //Concatenate the arrays of selected features from the two feature layers
        response = responseSeg.concat(responseInt);
      });
      return dojo.map(response, function (result) {
        var content = getPopupContent();
        var template = new esri.InfoTemplate("", content);
        result.setInfoTemplate(template);
        return result;
      });
    });
    popup.setFeatures([deferred]);
    popup.show(evt.mapPoint);
  });

  function getPopupContent() {
    var viewPermitLink = "<a href=\"javascript:ExecuteViewPermit('${PermitNumber}');\">View Details</a>";
    var streetViewLink = "<a href=\"javascript:showMapInDialog('${PermitNumber}');\">Street View</a>";
    var content = "<b>Permit Number</b>: ${PermitNumber}" + "<br><b>On Street</b>: ${OnStreetName}" + "<br><b>From Street</b>: ${FromStreetName}" + "<br><b>To Street</b>: ${ToStreetName}" + "<br>" + viewPermitLink + "  " + streetViewLink;
    return content;
  }

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
Take a look at Derek Swingley's post in this thread over on GIS.StackExchange.com
0 Kudos
ChadWilcomb
New Contributor III

Thanks Ken, that wasn't exactly what I was trying to do but taking another look at the IdentifyTask example helped me to get where I needed to go. I actually have two feature layers that I want to get results from (Segments and Intersections). I was able to used the deferred.addCallback and the dojo.map methods from the IdentifyTask example to combine the results and get the content into the popup. In case anyone is interested, here is what I came up with...

dojo.connect(map, "onClick", function (evt) {
    var query = new esri.tasks.Query();
    //Query within 20 pixels of click point
    query.geometry = pointToExtent(map, evt.mapPoint, 20);
    //I have two feature layers with setDefinitionExpression applied (intersections, segments)
    var deferred = featureLayerSeg.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
    deferred.addCallback(function (responseSeg) {
      var response;
      var deferInt = featureLayerInt.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
      deferInt.addCallback(function (responseInt) {
        //Concatenate the arrays of selected features from the two feature layers
        response = responseSeg.concat(responseInt);
      });
      return dojo.map(response, function (result) {
        var content = getPopupContent();
        var template = new esri.InfoTemplate("", content);
        result.setInfoTemplate(template);
        return result;
      });
    });
    popup.setFeatures([deferred]);
    popup.show(evt.mapPoint);
  });

  function getPopupContent() {
    var viewPermitLink = "<a href=\"javascript:ExecuteViewPermit('${PermitNumber}');\">View Details</a>";
    var streetViewLink = "<a href=\"javascript:showMapInDialog('${PermitNumber}');\">Street View</a>";
    var content = "<b>Permit Number</b>: ${PermitNumber}" + "<br><b>On Street</b>: ${OnStreetName}" + "<br><b>From Street</b>: ${FromStreetName}" + "<br><b>To Street</b>: ${ToStreetName}" + "<br>" + viewPermitLink + "  " + streetViewLink;
    return content;
  }

0 Kudos