Select to view content in your preferred language

Get attribute value from popup and pass to tool?

1524
1
06-02-2014 03:10 AM
KarenEllett
Regular Contributor
I'm wondering if there's anyway to get a value from a particular feature via the popup, and pass it along to a tool.  I'm envisioning a tool that is in the popup, and when you click on that feature, then click the tool in the popup window, it grabs the attribute from that particular feature.  (Say, a unique identifier.)  Then I can use that attribute in the tool to run a query against an entirely different table and return the results.  Is there a way to do this? 

Thanks!
0 Kudos
1 Reply
BrianLeroux
Frequent Contributor
Yes that is possible. I use the following code to place a button on the pop up window. It only displays when there is a certain attribute as seen in the CanExecute section. When the user clicks the button it adds the attribute value to a url and launches a new webpage. Once you have your bvalue you can do whatever you want with it.

public class ecfTool : ICommand
    {
        private string ecfUrl = "http://mywebsite/ExternalLink.do?auto=1&linkName=ByNumber&Number=";
        private Graphic inputFeat;            

        #region ICommand members
        public void Execute(object parameter)
        {
            // Get input feature and layer
            OnClickPopupInfo popupInfo = parameter as OnClickPopupInfo;
            inputFeat = popupInfo.PopupItem.Graphic;
            System.Windows.Browser.HtmlPage.Window.Navigate(
                new Uri(ecfUrl + inputFeat.Attributes["FILE_NO"].ToString()),
                "_blank", "top=0,left=0,location=1,menubar=1,toolbar=1, resizable=1");
        }

        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            // Return true so that the command can always be executed
            //return true;

            // Check that the parameter contains pop-up information and 
            // that the current feature shown in the pop-up is a point
            OnClickPopupInfo puInfo = parameter as OnClickPopupInfo;

            return puInfo != null
                && puInfo.PopupItem != null
                && puInfo.PopupItem.Graphic != null
                && puInfo.PopupItem.Graphic.Geometry is MapPoint
                && puInfo.PopupItem.Graphic.Attributes.ContainsKey("FILE_NO");
        }



        #endregion
    }
0 Kudos