Select to view content in your preferred language

Hyperlink inside IdentifyTask using esri.InfoTemplate

1523
5
06-07-2011 11:36 AM
JanBenson
Deactivated User
I have modified the sample Identify features on a map (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/find_popup.html) to work with my data.  One of my fields is an address to the website (URL).  How do I make this active such that a user can click on it and get to the new page?  Here is the code that brings up the identify results.  It lists the URL, but it is not active.  My two fields are Content and URL.

   function executeIdentifyTask(evt) {
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
       
        var deferred = identifyTask.execute(identifyParams);

        deferred.addCallback(function(response) {     
          // response is an array of identify result objects    
          // Let's return an array of features.
          return dojo.map(response, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if(result.layerName === 'EcoFOCIGOALarval'){
//              console.log(feature.attributes.Content);
              var template = new esri.InfoTemplate("", "${Content} <br/>Link: : ${URL}"); 
              feature.setInfoTemplate(template);
            }
             else if (result.layerName === 'AITrawl'){
              var template = new esri.InfoTemplate("", "${Content} <br/> Link: : ${URL}");  
              feature.setInfoTemplate(template);
             }
            else if (result.layerName === 'CTDSections'){
              var template = new esri.InfoTemplate("", "${Content} <br/> Link: : ${URL}");  
              feature.setInfoTemplate(template);
            }    
            else if (result.layerName === 'EBSSurveyGridDis'){
              var template = new esri.InfoTemplate("", "${Content} <br/> Link: : ${URL}");  
              feature.setInfoTemplate(template);                
            }           
            else if (result.layerName === 'SSL2010BiOpZones1'){
              var template = new esri.InfoTemplate("", "${Content} <br/> Link: : ${URL}");  
              feature.setInfoTemplate(template);
            }
            return feature;
          });
        });

If there is an easier way, I'm open.  This is a very simple application.

Thanks,
Jan
0 Kudos
5 Replies
JaclynGorman
Emerging Contributor
This is a snip of code I used based on that example.  You will need to change the names I used from my shapefile fields.  The "reports" field in the shapefile is a url.

[HTML]
function layerTabContent(layerResults, layerName) {
        var content = "";
        switch (layerName) {
  case "layer1results":
            content += "<table border='1'><tr><th>School Attending:</th><th>Date:</th><th>General Location:</th><th>Report (Will open in new window)</th></tr>";
            for (var i=0, il=layerResults.features.length; i<il; i++) {
              content+="<tr><td>"+layerResults.features.attributes['HmSchool']+"</td>";
     content+="<td>"+layerResults.features.attributes['DateText']+"</td>";
     content+="<td>"+layerResults.features.attributes['Location']+"</td>";
     content+="<td>"+" <a href=" + layerResults.features.attributes['Reports'] + " target=_blank ;'>Click for Report!</a></td>";

            }
            content+="</tr></table>";
            break;
[/HTML]

Hope this helps.

Jaclyn
0 Kudos
JanBenson
Deactivated User
Jacyn,
  I'm new at this so pardon the confusion.  I don't understand how your function layerTabContent(layerResults, layerName) replaces my code or how to implement.  Am I using a different example and/or just confused?

Thanks.
Jan
0 Kudos
JaclynGorman
Emerging Contributor
so for your var template:

var template = new esri.InfoTemplate("", "${CONTENT_FIELD} <br/> <a href= ${URL_Field} target=_blank ;'>Click for Report!</a>");


CONTENT_FIELD = static information field
URL_Field = field with URL

You can change "Click for Report!" to anything
0 Kudos
JanBenson
Deactivated User
Jaclyn,

  Thanks.  I'm up and running.  I had tried  an <a href, but I had the syntax wrong.  In addition Aptana confused me as I got a warning message about '<' + '/' + letter not allowed here.  Anyway, thanks for you help.  It is appreciated.

Jan
0 Kudos
JaclynGorman
Emerging Contributor
No problem.  Sorry my original post was confusing.  I didn't realize they updated the samples with a new identify example.
0 Kudos