Add Link or Button to InfoTemplate For Only One Feature Layer

3710
3
11-05-2015 12:29 PM
chuckfrank
Occasional Contributor

Hi All,

I have been following this sample: Geoprocessing tool link in popup | ArcGIS API for JavaScript

The problem I'm having is that it applies to every feature layer on the map where I've set an infoTemplate and I only want the the extra functionality for one of the layers.  I've been trying to set the content for the infoTemplate and add the link in the setContent function but it's not working.  It prevents the attribute values from displaying and also doesn't doesn't show the link.  I'm puzzled by it because I am able to create a ContentPane.  Why is constructing an anchor any different?  I'm not sure how to solve this problem.

Here is some of my code:

// infoTemplate for Pour Points

            var wbd10PourPointsInfoTemplate = new InfoTemplate({

                title: "<strong>${CWUAS_NAME}</strong>",

            });

            wbd10PourPointsInfoTemplate.setContent(getWbd10PourPointInfoTemplateContent);

            function getWbd10PourPointInfoTemplateContent(graphic) {

                var content = "<strong>HUC10</strong>: " + graphic.attributes.HUC_10 + " </br>" +

                         "<strong>Square Miles</strong>: " + graphic.attributes.SQM + " </br>" +

                         "<strong>Type</strong>: " + graphic.attributes.PRPT_TYPE + " </br>" ;

                // Make a tab container.

                var cp = new ContentPane({

                    content: content

                }, domConstruct.create("div"));

          // THIS IS THE SECTION OF CODE THAT PREVENTS ANY VALUES FROM DISPLAYING IN THE CONTENT.  IF THIS IS COMMENTED OUT THEN ALL OF THE ATTRIBUTE VALUES DISPLAY.  IF I MOVER IT OUT OF THIS BLOCK THEN ALL OF THE VALUES DISPLAY AND I ALSO GET THE FUNCTIONAL LINK, BUT THEN IT ALSO SHOWS ON INFO TEMPLATES WHERE I DO NOT WANT TO DISPLAY THE LINK

            var link = domConstruct.create("a", {

                "class": "action",

                "id": "statsLink",

                "innerHTML": "Display Watershed", //text that appears in the popup for the link

                "href": "javascript: void(0);"

            }, query(".actionList", window.map.infoWindow.domNode)[0]);

            on(link, "click", displayWatershed);

                return cp.domNode;

            }

0 Kudos
3 Replies
chuckfrank
Occasional Contributor

I handled this issue by simply hiding and displaying the link in the feature layer click event.  If the feature layer where I want to display the link is clicked then I show it.  For all other feature layer clicks I hide it.  This way i can run with the code provided in the sample that adds it at the top level. 

Code Example:

     myFeatureLayer.on("click", function (evt) {

                // show the link

                $("#statsLink").show()

     });

      otherFeatureLayer.on("click", function (evt) {

                // hide the anchor

                $("#statsLink").hide();

       });

0 Kudos
MarkEastwood
Occasional Contributor II

Has anyone else found a way to achieve this. I would like my link to only appear for one feature. Is there a way to hide the link in all features and only expose it to one? I am working in the PopupManager.js ....

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

M E,

   Since you mention PopupManager.js that means you are talking about WAB so you should start a new question in the WAB space or the Custom Widgets group.

0 Kudos