<!-- Buffer Results Panel --> <userControls:WindowPanel x:Name="BufferResultsWindowPanel" Visibility="Collapsed" Width="Auto" Height="Auto" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="30,0,0,50"> <StackPanel> <esri:FeatureDataGrid x:Name="BufferResultsQueryDetailsDataGrid" AutoGenerateColumns="False" MaxHeight="150" VerticalScrollBarVisibility="Auto" Map="{Binding ElementName=Map}" GraphicsLayer="{Binding ElementName=Map, Path=Layers.[BufferResultsGraphicsLayer], UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource FeatureDataGridStyle1}"> <esri:FeatureDataGrid.Columns> <data:DataGridTextColumn Binding="{Binding PPN}" Header="PPN" /> <data:DataGridTextColumn Binding="{Binding OWNERNAME}" Header="Owner Name" /> <data:DataGridTextColumn Binding="{Binding ADDRESS}" Header="Address" /> </esri:FeatureDataGrid.Columns> </esri:FeatureDataGrid> <Button x:Name="BufferResultsExportAllButton" ToolTipService.ToolTip="Export to Excel" Click="ExportAllButton_Click" HorizontalAlignment="Left" Margin="10" Height="25" Width="25"> <Button.Template> <ControlTemplate> <Image Source="/Standard;component/Images/excel2010.png"/> </ControlTemplate> </Button.Template> </Button> </StackPanel> </userControls:WindowPanel>
public void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs args) { _pointAndBufferGraphicsLayer = Map.Layers["BufferGraphicsLayer"] as GraphicsLayer; _resultsGraphicsLayer = Map.Layers["BufferResultsGraphicsLayer"] as GraphicsLayer; _pointAndBufferGraphicsLayer.Graphics.Clear(); _resultsGraphicsLayer.Graphics.Clear(); if (IdentifyBorder.Visibility == Visibility.Collapsed) { Map.Cursor = Cursors.Hand; //Identify Graphics Object GraphicsLayer identifyicongraphicsLayer = Map.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer; identifyicongraphicsLayer.Visible = false; if (BufferButton.IsChecked == true) { //Buffer Tool _geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); _geometryService.BufferCompleted += GeometryService_BufferCompleted; _geometryService.Failed += GeometryServiceBuffer_Failed; _queryTaskBuffer = new QueryTask("http://96.61.212.3/GISServices/rest/services/PFR6-17/MapServer/0"); _queryTaskBuffer.ExecuteCompleted += QueryTaskBuffer_ExecuteCompleted; _queryTaskBuffer.Failed += QueryTaskBuffer_Failed; //Buffer Tool _geometryService.CancelAsync(); _queryTask.CancelAsync(); Graphic clickGraphic = new Graphic(); clickGraphic.Symbol = LayoutRoot.Resources["BufferMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = args.MapPoint; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = Map.SpatialReference; clickGraphic.SetZIndex(2); _pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic); // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = new SpatialReference(4326), OutSpatialReference = Map.SpatialReference, Unit = LinearUnit.Foot, }; //Insert Buffer Radius string bufferlength = BufferTextBox.Text; double doublebufferlength = Convert.ToDouble(bufferlength); bufferParams.Distances.Add(doublebufferlength); bufferParams.Features.Add(clickGraphic); _geometryService.BufferAsync(bufferParams); } } void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args) { Graphic bufferGraphic = new Graphic(); bufferGraphic.Geometry = args.Results[0].Geometry; bufferGraphic.Symbol = LayoutRoot.Resources["BufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; bufferGraphic.SetZIndex(1); _pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic); ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query(); query.ReturnGeometry = true; query.OutSpatialReference = Map.SpatialReference; query.Geometry = bufferGraphic.Geometry; query.OutFields.Add("OWNERNAME,PPN,ADDRESS"); _queryTaskBuffer.ExecuteAsync(query); } private void QueryTaskBuffer_ExecuteCompleted(object sender, QueryEventArgs args) { if (args.FeatureSet.Features.Count < 1) { MessageBox.Show("No features found"); return; } else { if (BufferResultsWindowPanel.IsOpen == false) { BufferResultsWindowPanel.Toggle(); } foreach (Graphic selectedGraphic in args.FeatureSet.Features) { selectedGraphic.Symbol = LayoutRoot.Resources["ParcelSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; _resultsGraphicsLayer.Graphics.Add(selectedGraphic); //Populates the Data Grid with the results and shows the corresponding Window Panel BufferResultsQueryDetailsDataGrid.ItemsSource = selectedGraphic.Attributes; } BufferResultsWindowPanel.Visibility = Visibility.Visible; } } private void GeometryServiceBuffer_Failed(object sender, TaskFailedEventArgs args) { MessageBox.Show("Geometry service failed: " + args.Error); } private void QueryTaskBuffer_Failed(object sender, TaskFailedEventArgs args) { MessageBox.Show("Query failed: " + args.Error); } #endregion
Solved! Go to Solution.