<UserControl x:Class="ArcGISSilverlightSDK.RoutingDirections" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit= "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" xmlns:esri="http://schemas.esri.com/arcgis/client/2009"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <esri:SimpleMarkerSymbol x:Key="FromSymbol" Size="15" Style="Circle" Color="#9900FF00" /> <esri:SimpleMarkerSymbol x:Key="ToSymbol" Size="15" Style="Circle" Color="#99FF0000" /> <esri:SimpleLineSymbol x:Key="RouteSymbol" Color="#990000FF" Width="5"/> <esri:SimpleLineSymbol x:Key="SegmentSymbol" Color="#99FF0000" Width="8"/> </Grid.Resources> <Grid.RowDefinitions> <!--<RowDefinition Height="30" />--> <RowDefinition Height="75" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <toolkit:BusyIndicator x:Name="busy" IsBusy="False"> <StackPanel Orientation="Horizontal" > <Button x:Name="btnTest" Content="pop cbox" Click="btnTest_Click" Width="75" Height="50" /> <ComboBox x:Name="cbxValues" Grid.Column="2" Grid.Row="1" Width="100" Height="50" /> </StackPanel> </toolkit:BusyIndicator> </Grid> </UserControl>
using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Tasks; namespace ArcGISSilverlightSDK { public partial class RoutingDirections : UserControl { public RoutingDirections() { InitializeComponent(); } private int _featcount; private int _featcomplete; private List<string> uniquevalues; private void btnTest_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Debug.WriteLine("start " + System.DateTime.Now); busy.IsBusy = true; uniquevalues = new List<string>(); QueryTask qt = new QueryTask("http://myserver/ArcGIS/rest/services/MyService/MapServer/0"); qt.ExecuteCompleted += qt_ExecuteCompleted; qt.Failed += qt_Failed; Query qry = new Query(); qry.ReturnIdsOnly = true; qry.Where = "1=1"; //get them all... ReturnIDsonly is not limited to the max #features set for a sevice qt.ExecuteAsync(qry, qt.Url); } void qt_Failed(object sender, TaskFailedEventArgs e) { MessageBox.Show(e.Error.Message); } void qt_ExecuteCompleted(object sender, QueryEventArgs e) { _featcount += e.FeatureSet.ObjectIDs.Count(); if (_featcount == 0) { return; } int[] oids; QueryTask qt = new QueryTask("http://myserver/ArcGIS/rest/services/MyService/MapServer/0"); Query qry = new Query(); //assuming max # features returned is stilll the v10.0 default of 1000 here.... for (int i = 0; i <= Math.Floor(_featcount / 1000); i++) { oids = e.FeatureSet.ObjectIDs.Skip(i * 1000).Take(1000).Select(x => int.Parse(x.ToString())).ToArray(); qt = new QueryTask("http://myserver/ArcGIS/rest/services/MyService/MapServer/0"); qt.ExecuteCompleted += fullqt_ExecuteCompleted; qt.Failed += qt_Failed; qry = new Query(); OutFields ofld = new OutFields(); ofld.Add("COUNTYNAME"); ofld.Add("STATE"); qry.OutFields = ofld; qry.ObjectIDs = oids; qt.ExecuteAsync(qry); } } void fullqt_ExecuteCompleted(object sender, QueryEventArgs e) { foreach (Graphic g in e.FeatureSet) { _featcomplete += 1; if (!uniquevalues.Contains(g.Attributes["COUNTYNAME"].ToString() + ", " + g.Attributes["STATE"].ToString())) { uniquevalues.Add(g.Attributes["COUNTYNAME"].ToString() + ", " + g.Attributes["STATE"].ToString()); } } if (_featcomplete == _featcount) { cbxValues.ItemsSource = uniquevalues; System.Diagnostics.Debug.WriteLine("done " + System.DateTime.Now); busy.IsBusy = false; cbxValues.IsDropDownOpen = true; } } } }
foreach (Graphic graphic in args.FeatureSet.Features) { //Set Distinct QueryComboBox.ItemsSource = (from g in args.FeatureSet.Features orderby g.Attributes["STATE_NAME"].ToString() select g.Attributes["STATE_NAME"]).Distinct(); }
var states = (from g in args.FeatureSet.Features select g.Attributes["STATE_NAME"]).Distinct().OrderBy(s => s); QueryComboBox.ItemsSource = states;
string[] states = args.FeatureSet.Features.Select(s => s.Attributes["STATE_NAME"].ToString()).Distinct().OrderBy(t => t).ToArray(); QueryComboBox.ItemsSource = states;
You might also have to add the ref to your app. Right click Reference folder Click add referenceClick the .Net TabFind System.Xml.Linq Add. Hope that works.
esrijay is right. you will need to use a linq query to filter out your redundant states and populate your combobox with unique entries..
foreach (Graphic graphic in args.FeatureSet.Features) { QueryComboBox.Items.Add(graphic.Attributes["STATE_NAME"].ToString()); }
foreach (Graphic graphic in args.FeatureSet.Features) { //Set Distinct QueryComboBox.Items.Add = (from g in args.FeatureSet.Features orderby g.Attributes["STATE_NAME"].ToString() select g.Attributes["STATE_NAME"]).Distinct(); } QueryComboBox.SelectedIndex = 0; return;
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.