infoTemplate setContent function used also for datagrid click?

1489
2
Jump to solution
02-27-2013 07:51 AM
TracySchloss
Frequent Contributor
I have an infoTemplate that is using a function to format the content of the infoWindow:
parcelInfoContent = parcelInfoTemplate.setContent(parcelSetWindowContent);


A lot of my fields don't have any data, so in my function I'm checking to see if there is data before I put the information for that field:
function parcelSetWindowContent(graphic) {     var addressTest = graphic.attributes.SITEADDRES;     var legalTest = graphic.attributes.LEGAL1;     var twpRangeSecString = "Township:" + graphic.attributes.TOWNSHIP + "  Range:" + graphic.attributes.RANGE + "  Section: " + graphic.attributes.SECTION_ + "<br>" +"Legal Description:<br>" + graphic.attributes.LEGAL1;     var initString = "";     if (addressTest.length > 1) {         initString = initString + "Site Address:  :" + addressTest ;     }      if (legalTest) {         initString = initString + "<br>" + twpRangeSecString;     }     return initString; }    


I am also populating a datagrid of these parcels and I also need to have an onclick which zooms to the parcel and opens the same infoWindow.  I'd like to use the same function to format, but I'm not sure how to get there.  I thought maybe there was a function for 'getInfoContent' on the featurelayer I'm using this for.  I can't quite figure this out.  I thought maybe I could set a variable parcelInfoContent when I set the definition initially, but that didn't do the trick.

function onRowClickHandler(evt){          map.graphics.clear();         map.infoWindow.hide();         var OID = grid.getItem(evt.rowIndex).OBJECTID;          var selectedParcel;          var query = new esri.tasks.Query();         query.objectIds = [OID];        // query.where = "PID= '" + parcelId + "'";         parcelFeatureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW, function (features) {            var parcelExtent = esri.graphicsExtent(features);            parcelExtent.expand(2);            map.setExtent(parcelExtent);                  var feature = features[0];                                 var centerPt = parcelExtent.getCenter();                 feature.setInfoTemplate(parcelInfoTemplate);                                 map.infoWindow.setTitle(feature.attributes.PID);                 var content = esri.substitute(feature.attributes, parcelInfoContent);                 map.infoWindow.setContent(content);               //   map.infoWindow.setFeatures([feature]);                  var labelPt = new esri.geometry.Point(centerPt, spatialReference);                 map.infoWindow.show(labelPt);         });                    } 
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
If you've defined an info template for the layer you could use the features getContent() method to get the info window content and display that.
          map.infoWindow.setContent(features[0].getContent()); 


Here's a fiddle that shows this in action:

http://jsfiddle.net/dddYq/

View solution in original post

0 Kudos
2 Replies
KellyHutchins
Esri Frequent Contributor
If you've defined an info template for the layer you could use the features getContent() method to get the info window content and display that.
          map.infoWindow.setContent(features[0].getContent()); 


Here's a fiddle that shows this in action:

http://jsfiddle.net/dddYq/
0 Kudos
TracySchloss
Frequent Contributor
Thanks Kelly.  I was not looking in the right place to find "getContent".
0 Kudos