Select to view content in your preferred language

Info Window result

700
2
03-19-2013 06:57 AM
SamirGambhir
Frequent Contributor
Hello,
In my application, I would like to set infoTemplate so that it can display additional information in the infoWindow (not in the title) based on which feature is clicked e.g. if features in the State 'ABC' are clicked, the info window should show additional text such as "(estimates based on State average)", but should not show this additional text when click on any other feature. How do I accomplish this?
Thanks
Samir
0 Kudos
2 Replies
SteveCole
Honored Contributor
This should be pretty easy. Use a function to actually populate the content of your infoWindow. First, create your infoTemplate:

 var theTemplate = new esri.InfoTemplate();
 theTemplate.setContent(setPopupContent);


Next, set up your dojo.connect for clicks on the features in your layer:

 //Listener event for feature selection and the popup info widow 
 dojo.connect(theFeatureLayer,"onClick",function(evt){
  //Listener event for feature selection and the popup info widow
  var query = new esri.tasks.Query();
  query.geometry = pointToExtent(map,evt.mapPoint,15);

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


Lastly, create the function which will populate your template with the content you want:

 function setPopupContent(graphic) {
 attr = graphic.attributes;
 curState = attr.STATE;
 
        content = 'Create your content here';

        //If The state clicked is ABC, append the special notation
 if (curState == "ABC") {
  content = content + "<br/><br/>(estimates based on State average)";
 }
 
 
 return content;
}


Steve
0 Kudos
SamirGambhir
Frequent Contributor
This should be pretty easy. Use a function to actually populate the content of your infoWindow. First, create your infoTemplate:

 var theTemplate = new esri.InfoTemplate();
 theTemplate.setContent(setPopupContent);


Next, set up your dojo.connect for clicks on the features in your layer:

 //Listener event for feature selection and the popup info widow 
 dojo.connect(theFeatureLayer,"onClick",function(evt){
  //Listener event for feature selection and the popup info widow
  var query = new esri.tasks.Query();
  query.geometry = pointToExtent(map,evt.mapPoint,15);

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


Lastly, create the function which will populate your template with the content you want:

 function setPopupContent(graphic) {
 attr = graphic.attributes;
 curState = attr.STATE;
 
        content = 'Create your content here';

        //If The state clicked is ABC, append the special notation
 if (curState == "ABC") {
  content = content + "<br/><br/>(estimates based on State average)";
 }
 
 
 return content;
}


Steve


Thanks Steve,
My scenario is a bit different. In my app, the user might select multiple geographies (states) at one time, but the infoWindow content should display differently only for the selected (developer-specified) geography.

I tried this code earlier, but this would set the result content for all geographies if the selected geography is part of the subset:
for ( j = 0; j < newGeog.length; j++) {
      if (newGeog == "A" || newGeog == "B" || newGeog == "C") {
            resultContent = "<tr>" + indc + ": <td>${" + indv + ":formatNumber} (State average)</td></tr>";
      } else {
          resultContent = "<tr>" + indc + ": <td>${" + indv + ":formatNumber}</td></tr>";
      }
}
0 Kudos