POST
|
Never mind guys, I figure it out. In the beginning I really had a hard time on understanding the following results returned from the completed event. RelatedRecordsGroup RelatedRecordsGroup.Values RelatedRecordsGroup.Values.ElementAt(0) RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0) In the end I found the differences between them. So I use a List<Graphic> to store the results from related query.
RelationshipResult pr = e.Result;
List<Graphic> gList = new List<Graphic>();
for (int k = 0; k < voteCount; k++) //add the graphics to the graphic list
{
gList.Add(pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(k));
}
Assign this graphic list to the datagrid.itemsource
idDataGrid.ItemsSource = gList;
Add columns.
for (int i = 0; i < pr.Fields.Count(); i++)
{
DataGridTextColumn dataGridTextColumn = new DataGridTextColumn();
Binding binder = new Binding();
binder.Path = new PropertyPath("Attributes[" + pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0).Attributes.ElementAt(i).Key + "]");
dataGridTextColumn.Header = pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0).Attributes.ElementAt(i).Key;
binder.Mode = BindingMode.OneWay;
dataGridTextColumn.Binding = binder;
dataGridTextColumn.IsReadOnly = false;
idDataGrid.Columns.Add(dataGridTextColumn);
}
... View more
06-22-2011
11:29 AM
|
0
|
0
|
139
|
POST
|
Hi everyone, I want to use identify task on one of my map service which include shape files and related table. I tracked some thread in the forum to write codes performing RelationshipQuery. But I run into the difficulty in understand the results and how to display them in a datagrid. Below is my codes. There is one item in the RelatedRecordsGroup and it has 111 keys. I use messagebox to see the key and value(in red words at the bottom) and they are correct. But I don't know why the data cannot be bind to the datagrid. I got results like this [ATTACH]7458[/ATTACH] I really appreciate some thoughts or corrections on my codes. Thanks a lot!!
QueryTask queryRelate = new QueryTask(shapfile.url); //shapefile url is the layer I want to query
queryRelate.ExecuteRelationshipQueryCompleted += queryRelate_ExecuteRelationshipQueryCompleted;
queryRelate.DisableClientCaching = true;
RelationshipParameter relationParameter = new RelationshipParameter();
relationParameter.ObjectIds = new int[] { objectid }; //objectid is received from the identify task on the shape file
relationParameter.OutFields = new string[] { "*" }; //return all the fields in the related table
relationParameter.RelationshipId = 0; //the related table's ID is 0
queryRelate.ExecuteRelationshipQueryAsync(relationParameter,queryRelate);
private void queryRelate_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
{
RelationshipResult pr = e.Result;
int voteCount = 0;
foreach (var item in pr.RelatedRecordsGroup)
{
voteCount = item.Value.Count();
MessageBox.Show(Convert.ToString(voteCount)); //message box says "1"
}
if (count > 0)
{
var idDataGrid = new DataGrid //generate a datagrid
{
Height = (count == 1 ? 70 : 125), //if there is only one graphic in the layer, height = 70, otherwise, height = 125
AutoGenerateColumns = false,
IsReadOnly = false,
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
VerticalScrollBarVisibility = ScrollBarVisibility.Visible,
HeadersVisibility = DataGridHeadersVisibility.Column,
Background = new SolidColorBrush(Colors.White),
RowStyle = (Style)LayoutRoot.Resources["MyCustomRow"],
CanUserSortColumns = true,
//ClipboardCopyMode= DataGridClipboardCopyMode.ExcludeHeader
};
idDataGrid.ItemsSource = pr.RelatedRecordsGroup.Values;
//Binding resultFeaturesBinding = new Binding("LastResult.Features");
//resultFeaturesBinding.Source = pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0).Attributes;
//querytaskPage.QueryDetailsDataGrid.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding);
//idDataGrid.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding);
idDataGrid.Columns.Clear();
foreach (var item in pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0).Attributes)
{
DataGridTextColumn dataGridTextColumn = new DataGridTextColumn();
Binding binder = new Binding();
binder.Path = new PropertyPath(item.Key);
dataGridTextColumn.Header = item.Key;
binder.Mode = BindingMode.OneWay;
dataGridTextColumn.Binding = binder;
dataGridTextColumn.IsReadOnly = false;
idDataGrid.Columns.Add(dataGridTextColumn);
}
MessageBox.Show(pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0).Attributes.ElementAt(0).Key); //message box says "OBJECTID"
MessageBox.Show(pr.RelatedRecordsGroup.Values.ElementAt(0).ElementAt(0).Attributes.ElementAt(0).Value.ToString()); //message box says "66901"
... View more
06-22-2011
10:43 AM
|
0
|
1
|
382
|
POST
|
I was able to do utm from/to geographic using Proj.Net you can do it... let me know if you need a sample... Hi Doc, I really appreciate that you would share a sample 🙂 This task really burns my head... BTW: In the weblink you gave me I download the dll file, but I cannot add this reference to the project reference, I can only add it to project's web reference. Was it normal or just I did some mistake. ..Thank you!
... View more
06-21-2011
08:31 PM
|
0
|
0
|
657
|
POST
|
ProjNet has a Silverlight library too. Just hunt around, it's in there. Hey Daniel, thank you! I found this: Is it the one you mentioned above? http://projnet.codeplex.com
... View more
06-21-2011
08:24 PM
|
0
|
0
|
657
|
POST
|
ESRI.ArcGIS.Client.Bing.Transform does just that Hi Brandon, thank you for your suggestion. I checked this one, but this is only for converting from between webmercator (WKID=102100) and geographic WGS84. And I would like to convert UTM to geographic WGS84.
... View more
06-21-2011
12:53 PM
|
0
|
0
|
657
|
POST
|
Don't know if this will work for you but you can take a look at it... http://projnet.codeplex.com/ Hey Doc, thanks a lot! From the live sample I think that's what I want (convert coordinates from UTM to lat/long). But it looks like there is no readme in it. I can only add the dll file from XX.Web --Add reference. If I try to add it from XX--Add reference, it says:" You cannot add a reference to ProjNet.dll as it was not build against the silverlight runtime. Silverlight projects will only work with silverlight assemblies" Any guessing for that? Thank you:)
... View more
06-21-2011
12:51 PM
|
0
|
0
|
657
|
POST
|
Hi guys, I am using mouse_move event to show the coordinates of the position. Just like this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MouseCoords But the projection of the maps in the map service is Transverse_Mercator and I want to display the coordinates in lat/long. I know geometry service supports projection task and I tied this method in my codes. But since we all move mouse very quickly and frequently and every move needs projection, this method really slows down the response time... I really would like to know whether there is a api or method to do this without projection every mousemove point nor kill the performance. Any thoughts or clues? Thank you!! Below are my codes:
private void MyMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs args)
{
if (MyMap.Extent != null)
{
System.Windows.Point screenPoint = args.GetPosition(MyMap);
ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);
//MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}",
//Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4));
//MapPoint inputMapPoint = new MapPoint(x, y, new SpatialReference(4326));
//use geometryservice's project utility
//GeometryService geometryService = new GeometryService("http://rmms-dev.atlas.illinois.edu/ArcGIS/rest/services/Geometry/GeometryServer");
//geometryService.ProjectCompleted += MouseCoordinate_geometryService_ProjectCompleted;
//geometryService.Failed += GeometryService_Failed;
//geometryService.ProjectAsync(new List<Graphic>() { new Graphic() { Geometry = mapPoint } }, new SpatialReference(4326), mapPoint);
}
}
void MouseCoordinate_geometryService_ProjectCompleted(object sender, GraphicsEventArgs e)
{
Graphic resultGraphic = e.Results[0];
MapPoint resultMapPoint = resultGraphic.Geometry as MapPoint;
MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}",
Math.Round(resultMapPoint.X, 4), Math.Round(resultMapPoint.Y, 4));
}
... View more
06-20-2011
02:55 PM
|
0
|
10
|
3723
|
POST
|
Hey Doc, I encourted another issue with this method. The case is: For the first time, the method works very well. But after the user closes the datagrid, restarts some work and wants to show the datagrid again, I got an exception: An item with the same key has already been added I define this IDictionary in public partial clas IDictionary<string, object> wirtReport = new Dictionary<string, object>(); I tried to clear the IDictionary after the user restarts working wirtReport.Clear(); But I still get the same exception. The red color words are where I get the exception, it seems like it doesn't allow me to add a new item into the IDictionary, but I do clear it before going into this place. I am very frustrated.
for (int i = 0; i < wirtlayerlist.Count; i++)
{
if (wirtlayerlist.ElementAt(i) == 18)
wirtReport.Add(wirtResult[0, 0], new { Prop1 = wirtResult[0, 1], Prop2 = wirtResult[0, 2], Prop3 = wirtResult[0, 3] });
else if (wirtlayerlist.ElementAt(i) == 21)
wirtReport.Add(wirtResult[1, 0], new { Prop1 = wirtResult[1, 1], Prop2 = wirtResult[1, 2], Prop3 = wirtResult[1, 3] });
else if (wirtlayerlist.ElementAt(i) == 20)
wirtReport.Add(wirtResult[2, 0], new { Prop1 = wirtResult[2, 1], Prop2 = wirtResult[2, 2], Prop3 = wirtResult[2, 3] });
else if (wirtlayerlist.ElementAt(i) == 23)
wirtReport.Add(wirtResult[3, 0], new { Prop1 = wirtResult[3, 1], Prop2 = wirtResult[3, 2], Prop3 = wirtResult[3, 3] });
else if (wirtlayerlist.ElementAt(i) == 16)
wirtReport.Add(wirtResult[4, 0], new { Prop1 = wirtResult[4, 1], Prop2 = wirtResult[4, 2], Prop3 = wirtResult[4, 3] });
else if (wirtlayerlist.ElementAt(i) == 14)
wirtReport.Add(wirtResult[5, 0], new { Prop1 = wirtResult[5, 1], Prop2 = wirtResult[5, 2], Prop3 = wirtResult[5, 3] });
}
wirtReportPage.WirtReportDataGrid.ItemsSource = wirtReport;
wirtReportPage.ParentLayoutRoot = InfoStackPanel;
wirtReportPage.thisPass(this);
wirtReportPage.Show();
Do you have some ideas or clues on how to solve this problem? Thank you!!
... View more
06-19-2011
04:15 PM
|
0
|
0
|
603
|
POST
|
Thank you very much Doc 🙂 That works perfect! I change my codes like below and get a hyperlink button, and with a button click event I can implement some actions against MyMap.
<slData:DataGridTemplateColumn Header="Critical Resource">
<slData:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton Content="{Binding Key}" Foreground="Black" Click="Hyperlink_Click"/>
</DataTemplate>
</slData:DataGridTemplateColumn.CellTemplate>
</slData:DataGridTemplateColumn>
... View more
06-16-2011
10:43 PM
|
0
|
0
|
190
|
POST
|
Hi guys, I use draw class in my application to draw polygons. Is there a way to display the length automatically when you are drawing? Just like what it is in the measure action, a segment length and a total length are showing as you move the mouse. I know geometry service can be used to calculate the length, but that must happen after you finish drawing. Any ideas or thoughts? Thank you 🙂
... View more
06-16-2011
09:57 PM
|
0
|
3
|
2630
|
POST
|
Hi everyone, I attach a screenshot to describe my question [ATTACH]7358[/ATTACH]. I am keen to know how to implement such things in silverlight. Any thoughts or ideas? Thank you! In the picture you can see "Resource found" (with a underline) within "Resource within Buffer" column, which acts as a button. When you click on the words, something will happen on the map. "Click to see the statement" within "Notes" column acts as a hyperlink to open another pdf file. And I want to ask another question (may sounds a little stupid ...) The headers of the columns are long and I don't know how to arrange them in two lines or make them auto wrap. It seems there is no property for header to wrap. My design for the datagird is:
<slData:DataGrid x:Name="WirtReportDataGrid" Width="Auto" AutoGenerateColumns="False" HeadersVisibility="Column" Background="White"
IsReadOnly="False" Grid.Row="1"
CanUserSortColumns="True">
<slData:DataGrid.Columns>
<slData:DataGridTextColumn CanUserSort="True" Header="Critical Resource" Binding="{Binding Key}"/>
<slData:DataGridTextColumn CanUserSort="False" Header="Resource in Vicinity of Project Polygon" Binding="{Binding Value.Prop1}"/>
<slData:DataGridTextColumn CanUserSort="False" Header="Resource within Buffer" Binding="{Binding Value.Prop2}" />
<slData:DataGridTextColumn CanUserSort="False" Header="Notes" Binding="{Binding Value.Prop3}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
... View more
06-16-2011
12:25 PM
|
0
|
2
|
620
|
POST
|
Thanks a lot Doc! This really helps me out! 😄 And it is very useful for my future development. 🙂 Thanks again.
... View more
06-16-2011
12:17 PM
|
0
|
0
|
603
|
POST
|
Try as highlighted in red... it worked for me Hey Doc, that works perfectly! Thank you so much! I still have one question to consult: I have another two columns in the datagrid, like below, and 'Resource within Buffer' refers to 'found' or 'not found' 'Notes' refers to some notice word.
<slData:DataGridTextColumn Header="Resource within Buffer"/>
<slData:DataGridTextColumn Header="Notes"/>
So can I add more values within the same key and bind the other two values to the above columns? I saw new KeyValuePair only handle a key-value pair. Thanks a lot!!
wirtReport.Add(new KeyValuePair<string, string>(url, "RESOURCE FOUND"));
... View more
06-15-2011
02:48 PM
|
0
|
0
|
603
|
POST
|
Hey Doc, Thank you for the prompt reply. I have such datagrid in the xaml:
<slData:DataGrid x:Name="WirtReportDataGrid" Width="Auto" AutoGenerateColumns="False" HeadersVisibility="Column" Background="White"
IsReadOnly="False" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto" Grid.Row="1"
CanUserSortColumns="True">
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Header="Critical Resource"/>
<slData:DataGridTextColumn Header="Resource in Vicinity of Project Polygon"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
'Critical Resource' refers to the layer's name, like wetland, river. 'Resource in Vicinity of Project Polygon' refers to 'found' or 'not found'. I wrote below in cs file and it doesn't return any results in the datagrid.
private void WirtQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
string url ="";
if (wirtMapLayer.Count != 0)
url = wirtMapLayer.Peek();
if (featureSet == null || featureSet.Features.Count < 1)
{
wirtReport.Add(new KeyValuePair<string, string>(url, "NO RESOURCE FOUND"));
}
else if (featureSet != null && featureSet.Features.Count > 0)
{
wirtReport.Add(new KeyValuePair<string, string>(url, "FOUND"));
}
wirtReportPage.WirtReportDataGrid.ItemsSource = wirtReport;
}
So If I use your method, do I need to also set any binding on the columns in xaml?
... View more
06-15-2011
01:53 PM
|
0
|
0
|
603
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|