Select to view content in your preferred language

Interactive data table for GraphicsLayers

1691
13
Jump to solution
01-30-2012 01:15 PM
JianChen
Regular Contributor
The ESRI sample (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid) shows a way to create an interactive data table for GraphicLayer (click the map, associated feature will highlight in the FeatureDataGrid, Vice versa). The core part is the FeatureLayer_MouseLeftDown function as below:

private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)         {             args.Graphic.Selected = !args.Graphic.Selected;             if (args.Graphic.Selected)                 MyDataGrid.ScrollIntoView(args.Graphic, null);         }


XAML code from Sample:

<esri:FeatureLayer ID="California" Renderer="{StaticResource SelectRenderer}"      Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer/8"      OutFields="*" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown" /> ... <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"     Map="{Binding ElementName=MyMap}"     GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[California]}" />
  The map user click actually is a feature layer and the featureDataGrid is binding to a GraphicsLayer (the same feature layer anyway). I make some changes from the sample for my application. If I get rid of the feature layer and the GraphicsLayer is returned from a query and I worte a similar GraphicsLayer_MouseLeftButton Down function, if you click the map, the entry in the FeatureDataGrid can be highlighted, but when I click a row in the FeatureDataGrid, the feature on the map doesn't highlight. What do I miss here?  
 private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)         {             e.Graphic.Selected = !e.Graphic.Selected;             if (e.Graphic.Selected)                 MyDataGrid.ScrollIntoView(e.Graphic, null);         }


The XAML from my code:

<esri:GraphicsLayer ID="MyGraphicsLayer" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown" /> .... <esri:FeatureDataGrid x:Name="MyDataGrid" Background="White"     Map="{Binding ElementName=MyMap}"     GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MyGraphicsLayer]}" >                           </esri:FeatureDataGrid>
0 Kudos
13 Replies
JianChen
Regular Contributor
No idea.
Can you share a piece of code allowing to reproduce the issue?

Thanks Dominique! Below is part of the XAML & C# code:

 <Grid.Resources>
    <esri:SimpleFillSymbol x:Key="DefaultFillSymbol"  />
   <esri:SimpleMarkerSymbol x:Key="MyMarkerSymbol" Color="Blue"/>
</Grid.Resources>

<esri:Map x:Name="MyMap" WrapAround="true" Background="White" Extent="-130, 20, -65, 55"> <!--"{StaticResource BaseColor}" >-->
                <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" 
            Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" />
                <esri:GraphicsLayer ID="MyGraphicsLayer" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown">
                    <esri:GraphicsLayer.MapTip>
                        <Border esri:GraphicsLayer.MapTipHideDelay="00:00:0.5" BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15" >
                            <Border.Effect>
                                <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
                            </Border.Effect>
                            <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="4" BorderBrush="#77FF0000" Name="MapTipBorder">
                                <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10">
                                    <StackPanel>
                                        <HyperlinkButton TargetName="_blank" Content="{Binding Path=[Organization_Name]}" HorizontalAlignment="Center" Foreground="RED" NavigateUri="{Binding [Link]}" />
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </Border>
                    </esri:GraphicsLayer.MapTip>
                </esri:GraphicsLayer>
            </esri:Map>

            <esri:FeatureDataGrid x:Name="MyDataGrid" Background="White"
    Map="{Binding ElementName=MyMap}"
    GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MyGraphicsLayer]}" >              
            </esri:FeatureDataGrid>


public partial class MainPage : UserControl
    {
        private string strUrl = null;
        private QueryTask queryTask;

        public MainPage()
        {
            InitializeComponent();
            MyMap.Layers.LayersInitialized += Layers_LayersInitialized;
        }

        void Layers_LayersInitialized(object sender, EventArgs args)
        {
            bool? flag = PPP_States.IsChecked;

            if (!flag.HasValue)
            {
                flag = false;
            }
            if ((bool)flag)
            {
                strUrl = "http://130.70.253.91/ArcGIS/rest/services/PPP/PP/MapServer/5";
                ExcuteQuery(strUrl);
            }
        }

        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                foreach (Graphic feature in featureSet.Features)
                {                    
                    if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
                    {
                        feature.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol;
                    }
                    else
                    {
                        feature.Symbol = LayoutRoot.Resources["MyMarkerSymbol"] as Symbol;
                    }
                    
                    graphicsLayer.Graphics.Add(feature);
                }
            }
        }

        // Notify when query fails.
        private void QueryTask_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Query failed: " + args.Error);
        }


        private void ExcuteQuery(string Url)
        {
            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.Geometry = MyMap.Extent;
            query.ReturnGeometry = true;
            query.OutFields.Add("*");
            
            if (Url != null)
            {
                queryTask = new QueryTask(strUrl);
            }
            else
            {
                queryTask = new QueryTask("http://130.70.3.72/ArcGIS/rest/services/STATES/MapServer");
            }

            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            queryTask.Failed += QueryTask_Failed;
            queryTask.ExecuteAsync(query);
        }



        private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
        {
            args.Graphic.Selected = !args.Graphic.Selected;
            if (args.Graphic.Selected)
                MyDataGrid.ScrollIntoView(args.Graphic, null);
        }

        private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
        {
            args.Graphic.Selected = !args.Graphic.Selected;
            if (args.Graphic.Selected)
                MyDataGrid.ScrollIntoView(args.Graphic, null);
        }  
    }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I think I got your issue.

It's not tied to your feature datagrid. Your selection by mouse click is not working either.

I think it's related to your symbol that is not managing the 'Selected' state. So your feature is selected but there is no visual effect.

You can either create your own custom symbol or use the feature service symbol.

In your XAML, add this line: xmlns:symbols="clr-namespace:ESRI.ArcGIS.Client.FeatureService.Symbols;assembly=ESRI.ArcGIS.Client"

and define your fill symbol this way:

<symbols:SimpleFillSymbol x:Key="DefaultFillSymbol" SelectionColor="Cyan" />

That should do the trick.



0 Kudos
JianChen
Regular Contributor
I think I got your issue.

It's not tied to your feature datagrid. Your selection by mouse click is not working either.

I think it's related to your symbol that is not managing the 'Selected' state. So your feature is selected but there is no visual effect.

You can either create your own custom symbol or use the feature service symbol.

In your XAML, add this line: xmlns:symbols="clr-namespace:ESRI.ArcGIS.Client.FeatureService.Symbols;assembly=ESRI.ArcGIS.Client"

and define your fill symbol this way:

<symbols:SimpleFillSymbol x:Key="DefaultFillSymbol" SelectionColor="Cyan" />

That should do the trick.




Thanks so much Dominique! You got the trick! I think your code is much clear than that of in the Sample (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid). I didn't pay much attention about the sample's description about symbol's selected state. Plus the associated XAML code about the symbol is not as straight forward as yours. Hope our experience here can help others as well.
0 Kudos
JianChen
Regular Contributor
Hi Dominique, can you help on another FeatureDataGrid question in this forum�?Thanks.

http://forums.arcgis.com/threads/48903-How-to-bind-selected-columns-to-a-FeatureDataGrid-from-a-Grap...
0 Kudos