private void CreateBuffLine_Click(object sender, RoutedEventArgs e)
{
_geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
_geometryService.BufferCompleted += GeometryService_BufferLineCompleted;
_geometryService.Failed += BuffLineSelectGeometryService_Failed;
_queryTask = new QueryTask((Layers.SelectedItem as FeatureLayer).Url);
_queryTask.ExecuteCompleted += BuffLineQueryTask_ExecuteCompleted;
_queryTask.Failed += BuffLineQueryTask_Failed;
_lineAndBufferGraphicsLayer = Map.Layers["MyGraphicsLayer"] as GraphicsLayer;
GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
_geometryService.CancelAsync();
_queryTask.CancelAsync();
//Gives users ability to draw line
MyDrawObject = new Draw(Map)
{
DrawMode = DrawMode.Polyline,
IsEnabled = true,
LineSymbol = LayoutRoot.Resources["ClipLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol
};
// Start MyDrawObject_DrawComplete, which turns the drawn poly into a graphic
MyDrawObject.DrawComplete += MyDrawObject_BuffLineDrawComplete;
}
private void MyDrawObject_BuffLineDrawComplete(object sender, DrawEventArgs args)
{
//Disable the drawing tool
MyDrawObject.IsEnabled = false;
//Assign the graphic draw to a graphiclayer, the graphic layer is defined in xaml
GraphicsLayer graphicsLayer = Map.Layers["MyGraphicsLayer"] as GraphicsLayer;
//Ready the graphic
Graphic graphic = new Graphic()
{
Symbol = LayoutRoot.Resources["ClipLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol,
Geometry = args.Geometry
};
// Input spatial reference for buffer operation defined by first feature of input geometry array
graphic.Geometry.SpatialReference = Map.SpatialReference;
_lineAndBufferGraphicsLayer.ClearGraphics();
graphicsLayer.ClearGraphics();
graphic.SetZIndex(2);
_lineAndBufferGraphicsLayer.Graphics.Add(graphic);
// 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,
};
bufferParams.Distances.Add(Int32.Parse(BufferLineSelectDistanceTextBox.Text));
bufferParams.Features.Add(graphic);
_geometryService.BufferAsync(bufferParams);
}
void GeometryService_BufferLineCompleted(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);
_lineAndBufferGraphicsLayer.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("*");
_queryTask.ExecuteAsync(query);
}
private void BuffLineQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
if (featureSet == null || featureSet.Features.Count < 1)
{
MessageBox.Show("No features retured from query");
return;
}
GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
if (featureSet != null && featureSet.Features.Count > 0)
{
foreach (Graphic feature in featureSet.Features)
{
switch (featureSet.GeometryType.ToString())
{
case "Polygon":
feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
break;
case "Polyline":
feature.Symbol = LayoutRoot.Resources["CustomGrowLineSymbol"] as LineSymbol;
break;
case "Point":
feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
break;
}
graphicsLayer.Graphics.Insert(0, feature);
}
ResultsDisplay.IsExpanded = true;
}
MyDrawSurface.IsEnabled = false;
}
private void BuffLineSelectGeometryService_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Geometry service failed: " + args.Error);
}
private void BuffLineQueryTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Query failed: " + args.Error);
}
<!-- Line Buffer Point Select Window -->
<userControls:CollapsiblePanel x:Name="BufferLineSelect" IsExpanded="False"
RenderTransformOrigin="1,0"
VerticalContentAlignment="Top" HorizontalContentAlignment="Right" Margin="0,75,10,0" Effect="{StaticResource dropShadow}" >
<Grid x:Name="BufferLineSelectGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Border Background="{StaticResource CommonPanelBorderBackgroundBrush}" BorderBrush="{StaticResource CommonBorderBrush}" BorderThickness="1" CornerRadius="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Border Effect="{StaticResource miniDropShadow}" Style="{StaticResource RibbonElementBorder}" Padding="15" Margin="10" >
<StackPanel Orientation="Vertical" Margin="10" HorizontalAlignment="Left" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="5">
<TextBlock x:Name="BufferSelectLineInformationTextBlock"
Text="Select a layer from the drop down list. Then enter a Buffer Distance. Next click on map to set a location. A buffer will used to display the layer that is selected in drop down menu within buffer distance specified (feet) of the location."
Margin="0,0,5,0" Width="290" HorizontalAlignment="Left" TextWrapping="Wrap" FontFamily="Arial" Foreground="#FFFFFFFF" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="Enter a Buffer Distance (in feet). The Value must be greater than 0: " VerticalAlignment="Center" FontFamily="Arial" Foreground="#FFFFFFFF" />
<TextBox x:Name="BufferLineSelectDistanceTextBox" Text="500" Width="50" TextAlignment="Right" Margin="0,0,5,0" />
</StackPanel>
<!-- Button for line creation-->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="3">
<TextBlock Text="Click Button to enable Draw Polyline: " VerticalAlignment="Center" FontFamily="Arial" Foreground="#FFFFFFFF" />
<Button Style="{StaticResource ClearButtonStyle}" Cursor="Hand" HorizontalAlignment="Center" Margin="0,0,0,5" ToolTipService.ToolTip="Create Polyline" Click="CreateBuffLine_Click">
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin="-5">
<Image Source="images/DrawPolyline.png" Height="50" Width="50" Stretch="UniformToFill" Margin="5,0,5,0" />
</Grid>
</Button>
</StackPanel>
<!--End Button for line creation-->
</StackPanel>
</StackPanel>
</Border>
</Border>
<Image Source="images/CloseX.png" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="3" Stretch="None" Cursor="Hand" ToolTipService.ToolTip="Close" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown" >
<actions:ToggleCollapseAction TargetName="BufferLineSelect" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>
</Grid>
</userControls:CollapsiblePanel>
<!--END Line Point Select Window -->