Select to view content in your preferred language

Creating a hyperlink result from query function.

1268
8
05-15-2012 08:01 AM
JaredWhite
Regular Contributor
Hi,
I'm needing to write a function where my app not only brings up query results, but also pulls a hyperlink from my map (the data tables on my map service have web addresses under the Path "path"). I used the identify query function (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify) from the api samples. How would I set it up so that the hyperlink also recieves the info from the map.

Xaml would be something like this

    <Grid>       
    <TextBlock Text="Query Results" />
    <Grid x:Name="IdentifyResultsPanel"
        <ComboBox x:Name="IdentifyComboBox" SelectionChanged="cb_SelectionChanged" />
        <HyperlinkButton x:Name="HyperlinkButton" />
        <ScrollViewer VerticalScrollBarVisibility="Auto" >
            <slData:DataGrid x:Name="IdentifyDetailsDataGrid" >
                <slData:DataGrid.Columns>
                    <slData:DataGridTextColumn Binding="{Binding Path=Key}" />
                    <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
                </slData:DataGrid.Columns>
            </slData:DataGrid>
        </ScrollViewer>
    </Grid>

Code Behind

        #region Query Results

        private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;
            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
                Geometry = clickPoint,
                MapExtent = TabletMap.Extent,
                Width = (int)TabletMap.ActualWidth,
                Height = (int)TabletMap.ActualHeight,
                LayerOption = LayerOption.visible,
                SpatialReference = TabletMap.SpatialReference
            };
            IdentifyTask identifyTask = new IdentifyTask("http://XXXXXXXXXXXXXXXXXXX");
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);
            GraphicsLayer graphicsLayer = TabletMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = clickPoint,
                Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            graphicsLayer.Graphics.Add(graphic);
        }
        public void ShowFeatures(List<IdentifyResult> results)
        {
            _dataItems = new List<DataItem>();

            if (results != null && results.Count > 0)
            {
                IdentifyComboBox.Items.Clear();
                foreach (IdentifyResult result in results)
                {
                    Graphic feature = result.Feature;
                    string title = result.Value.ToString() + " (" + result.LayerName + ")";
                    _dataItems.Add(new DataItem()
                    {
                        Title = title,
                        Data = feature.Attributes
                    });
                    IdentifyComboBox.Items.Add(title);
                }
                IdentifyComboBox.SelectedIndex = 0;
            }
            QueryPanel.IsExpanded = true;
        }
        void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = IdentifyComboBox.SelectedIndex;
            if (index > -1)
                IdentifyDetailsDataGrid.ItemsSource = _dataItems[index].Data;
        }
        private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            IdentifyDetailsDataGrid.ItemsSource = null;

            if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
            {
                IdentifyResultsPanel.Visibility = Visibility.Visible;

                ShowFeatures(args.IdentifyResults);
            }
            else
            {
                IdentifyComboBox.Items.Clear();
                IdentifyComboBox.UpdateLayout();

                IdentifyResultsPanel.Visibility = Visibility.Collapsed;
            }           
        }
        public class DataItem
        {
            public string Title { get; set; }
            public IDictionary<string, object> Data { get; set; }
        }
        void IdentifyTask_Failed(object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show("Identify failed. Error: " + e.Error);
        }

        #endregion


Any help would be great, thanks.
0 Kudos
8 Replies
DominiqueBroux
Esri Frequent Contributor
0 Kudos
JaredWhite
Regular Contributor
Thank you very much, this gives me some badly needed base functionality till I can figure out how to do this properly. I'd still like to use a dedicated hyperlink button though. If you don't have time, tend to people with more pressing problems, but if you don't mind, how would i go about populating a hyperlink button with a particular field of data pulled from an identify query like what i have written?
Thanks in advance.
0 Kudos
JaredWhite
Regular Contributor
Solved. You create a loading row that filters out everything but strings that contain "http", then pipe that value too your button containing a new page command. Thanks for the guidance.

        public string URLlink { get; set; }
        private void IdentifyDetailsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            string value = e.Row.DataContext.ToString();
            if (value.Contains("http"))
            {
                //Hides URLLink data line from Datagrid Results
                SolidColorBrush brush = new SolidColorBrush(Colors.Transparent);
                e.Row.Foreground = brush;                
            }
            else
            {
            }            
            try
            {
                string s = e.Row.DataContext.ToString();
                if (s.Contains("http"))
                {
                    string[] sSplit = s.Split(',');
                    string[] link = sSplit[1].Split(']');
                    URLlink = link[0];                    
                }
                else
                {
                }
            }
            catch
            {
            }
        }
        
        private void DTSButton_Click(object sender, RoutedEventArgs e)
        {
            HtmlPage.Window.Navigate(new Uri(URLlink), "_blank");           
        }


                            <Button x:Name="DTSButton" Click="DTSButton_Click"/>
 <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None" 
                              Background="White" LoadingRow="IdentifyDetailsDataGrid_LoadingRow">
                                    <slData:DataGrid.Columns>
                                        <slData:DataGridTextColumn Binding="{Binding Key}" FontWeight="Bold"/>
                                        <slData:DataGridTextColumn Binding="{Binding Value}" />
                                    </slData:DataGrid.Columns>
                                </slData:DataGrid>
0 Kudos
TanyaOwens
Frequent Contributor
I get an error "The name 'HtmlPage' does not exist in the current context". What am I missing?
0 Kudos
JenniferNery
Esri Regular Contributor
I think you just need to add reference to this .NET Assembly "System.Windows.Browser" and resolve reference to add using statement for this namespace http://msdn.microsoft.com/en-us/library/system.windows.browser.htmlpage%28v=vs.95%29.aspx
0 Kudos
TanyaOwens
Frequent Contributor
I think you just need to add reference to this .NET Assembly "System.Windows.Browser" and resolve reference to add using statement for this namespace http://msdn.microsoft.com/en-us/library/system.windows.browser.htmlpage%28v=vs.95%29.aspx


I got it to work but it oddly took out my field that contained the website from the datagrid. Really I was just looking for other hyperlink methods to try to resolve my issue from my post http://forums.arcgis.com/threads/58727-Field-Hyperlink. If you could provide some assistance on my field hyperlink post I would greatly appreciate it. Right now I am just lost on what to do to get my identify layer selection in three datagrids to each have a hyperlink.

Thanks for your help.
0 Kudos
JaredWhite
Regular Contributor
I got it to work but it oddly took out my field that contained the website from the datagrid. Really I was just looking for other hyperlink methods to try to resolve my issue from my post http://forums.arcgis.com/threads/58727-Field-Hyperlink. If you could provide some assistance on my field hyperlink post I would greatly appreciate it. Right now I am just lost on what to do to get my identify layer selection in three datagrids to each have a hyperlink.

Thanks for your help.


I wrote it that way.  Just change it to this

  public string URLlink { get; set; }
        private void IdentifyDetailsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {                    
            try
            {
                string s = e.Row.DataContext.ToString();
                if (s.Contains("http"))
                {
                    string[] sSplit = s.Split(',');
                    string[] link = sSplit[1].Split(']');
                    URLlink = link[0];                    
                }
                else
                {
                }
            }
            catch
            {
            }
        }
        
        private void DTSButton_Click(object sender, RoutedEventArgs e)
        {
            HtmlPage.Window.Navigate(new Uri(URLlink), "_blank");           
        }

0 Kudos
TanyaOwens
Frequent Contributor
Thanks! That brought the fields back into the datagrid. Have you had any luck with getting a hyperlink to work for three separate data grids. Its seems like it should be a simple task but I just can't seem to work it out. See my original post for more info. http://forums.arcgis.com/threads/58727-Field-Hyperlink
0 Kudos