Select to view content in your preferred language

How can I point popup to my own featureLayer?

741
2
08-02-2012 10:33 AM
BarryGuidry
Regular Contributor
I am new to using the Javascript API, and trying to add the sample popup info window to my web application. What I found to easiest is to first add my dynamic data source to the sample code first until I get it to function properly, and changing the initial extent to my map area, and then try to migrate the sample tool to my web application. In the "Popup" sample (above link), I was able to change the initial extent, and add my own data as the new esri.layers.FeatureLayer link. This all functions properly. As is, I even get a popup when selecting my data (polygons) and able to use the "Zoom to" function in the popup window, but cannot figure out how to change the sample source data to display my attribute data in the popup window. Everything I have tried did not work, basically modifying this portion of code:
function getTextContent(graphic) { 
        var attr = graphic.attributes.qSpecies.replace('"',"").split("::"); 
        var content; 
        var scientificName = attr[0]; 
        //display the common name if it exists - otherwise just the scientific 
        if(attr[1]){ 
          content = "<b>" + dojo.string.trim(attr[1].replace('"',"")) + "</b><br/><i>" + scientificName + "</i>"; 
        } 
        else{ 
          content = "<i>" + scientificName + "</i>" 
        } 
        return  content + "<br>" + graphic.attributes.qAddress
      } 
       
     function pointToExtent(map, point, toleranceInPixel) { 
       var pixelWidth = map.extent.getWidth() / map.width; 
       var toleraceInMapCoords = toleranceInPixel * pixelWidth; 
       return new esri.geometry.Extent( point.x - toleraceInMapCoords, 
                    point.y - toleraceInMapCoords, 
                    point.x + toleraceInMapCoords, 
                    point.y + toleraceInMapCoords, 
                    map.spatialReference );                            
      } 
Can anyone help, maybe simply by letting me know how to generally connect a featureLayer data source to a popup? Sorry, but I cannot display my own code here due to the nature of our business.
0 Kudos
2 Replies
KellyHutchins
Esri Notable Contributor
In the getTextContent function you can access the attributes for the currently selected feature using the following:

graphic.attributes

So if your feature layer had a field called ParcelId you'd access it as follows

var parcelid = graphic.attributes.ParcelId;
0 Kudos
BarryGuidry
Regular Contributor
Thanks, Kelly. Got it.
0 Kudos