This sample demonstrates using an ESRI.ArcGIS.Client.Tasks GeometryService that takes an input polyline graphic and makes a redline polygon graphic output. The GeometryService takes the input polyline to attempt to make a closed polygon against a FeatureLayer of parcels and if successful the output redline polygon graphic is returned.
To use the sample, connect the dots to create a polyline which defines a boundary for a new polygon. Double click the final dot (#3) to auto complete the polygon boundary.
<UserControlx:Class="ArcGISWPFSDK.AutoComplete"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:esri="http://schemas.esri.com/arcgis/client/2009"><Gridx:Name="LayoutRoot"><Grid.Resources><LinearGradientBrushx:Key="PanelGradient"EndPoint="0.5,1"StartPoint="0.5,0"><LinearGradientBrush.RelativeTransform><TransformGroup><ScaleTransformCenterY="0.5"CenterX="0.5"/><SkewTransformCenterY="0.5"CenterX="0.5"/><RotateTransformAngle="176"CenterY="0.5"CenterX="0.5"/><TranslateTransform/></TransformGroup></LinearGradientBrush.RelativeTransform><GradientStopColor="#FF145787"Offset="0.16"/><GradientStopColor="#FF3D7FAC"Offset="0.502"/><GradientStopColor="#FF88C5EF"Offset="0.984"/></LinearGradientBrush><esri:SimpleMarkerSymbolx:Key="BlackMarkerSymbol"Color="Black"Size="10"/><esri:SimpleLineSymbolx:Key="RedLineSymbol"Color="Red"Width="4"Style="Solid"/><esri:SimpleFillSymbolx:Key="BlueFillSymbol"Fill="#660000FF"BorderBrush="Blue"BorderThickness="2"/><esri:SimpleFillSymbolx:Key="RedFillSymbol"Fill="#66FF0000"BorderBrush="Red"BorderThickness="2"/></Grid.Resources><esri:Mapx:Name="MyMap"Extent="-83.32428481333132,42.61615162222472,-83.31723104257484,42.61906045707023"><esri:ArcGISTiledMapServiceLayerID="StreetMapLayer"Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/><esri:GraphicsLayerID="ParcelsGraphicsLayer"/><esri:GraphicsLayerID="CompletedGraphicsLayer"/><esri:GraphicsLayerID="ConnectDotsGraphicsLayer"><esri:GraphicSymbol="{StaticResource BlackMarkerSymbol}"><esri:MapPointX="-83.3215192779185"Y="42.6176674939048"/><esri:Graphic.MapTip><TextBlockText="Click"FontSize="12"Foreground="White"><TextBlock.Effect><DropShadowEffectOpacity="1"ShadowDepth="2"/></TextBlock.Effect></TextBlock></esri:Graphic.MapTip></esri:Graphic><esri:Graphic><esri:Graphic.Symbol><esri:TextSymbolFontFamily="Arial"FontSize="16"Foreground="Black"Text="1"OffsetX="-5"OffsetY="15"/></esri:Graphic.Symbol><esri:MapPointX="-83.3215192779185"Y="42.6176674939048"/></esri:Graphic><esri:GraphicSymbol="{StaticResource BlackMarkerSymbol}"><esri:MapPointX="-83.3212324913845"Y="42.6179747651913"/><esri:Graphic.MapTip><TextBlockText="Click"FontSize="12"Foreground="White"><TextBlock.Effect><DropShadowEffectOpacity="1"ShadowDepth="2"/></TextBlock.Effect></TextBlock></esri:Graphic.MapTip></esri:Graphic><esri:Graphic><esri:Graphic.Symbol><esri:TextSymbolFontFamily="Arial"FontSize="16"Foreground="Black"Text="2"OffsetX="-5"OffsetY="15"/></esri:Graphic.Symbol><esri:MapPointX="-83.3212324913845"Y="42.6179747651913"/></esri:Graphic><esri:GraphicSymbol="{StaticResource BlackMarkerSymbol}"><esri:MapPointX="-83.3209183918471"Y="42.6178655131783"/><esri:Graphic.MapTip><TextBlockText="Double click"FontSize="12"Foreground="White"><TextBlock.Effect><DropShadowEffectOpacity="1"ShadowDepth="2"/></TextBlock.Effect></TextBlock></esri:Graphic.MapTip></esri:Graphic><esri:Graphic><esri:Graphic.Symbol><esri:TextSymbolFontFamily="Arial"FontSize="16"Foreground="Black"Text="3"OffsetX="-5"OffsetY="15"/></esri:Graphic.Symbol><esri:MapPointX="-83.3209183918471"Y="42.6178655131783"/></esri:Graphic></esri:GraphicsLayer></esri:Map><GridHorizontalAlignment="Right"VerticalAlignment="Top"Margin="0,10,10,0"><RectangleFill="{StaticResource PanelGradient}"Stroke="Gray"RadiusX="10"RadiusY="10"Margin="0,0,0,5"><Rectangle.Effect><DropShadowEffect/></Rectangle.Effect></Rectangle><RectangleFill="#FFFFFFFF"Stroke="DarkGray"RadiusX="5"RadiusY="5"Margin="10,10,10,15"/><TextBlockx:Name="ResponseTextBlock"Foreground="Black"Text="Connect the dots to create a polyline which defines a boundary for a new polygon. Double click the final dot (#3) to auto complete the polygon boundary."Width="200"TextAlignment="Left"Margin="30,20,20,30"TextWrapping="Wrap"/></Grid></Grid></UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
namespace ArcGISWPFSDK
{
publicpartialclass AutoComplete : UserControl
{
private Draw MyDrawObject;
GraphicsLayer outputGraphicsLayer;
public AutoComplete()
{
InitializeComponent();
MyMap.MinimumResolution = double.Epsilon;
QueryTask queryTask =
new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/TaxParcel/AssessorsParcelCharacteristics/MapServer/1");
Query query = new Query();
query.Geometry = MyMap.Extent;
query.ReturnGeometry = true;
queryTask.ExecuteCompleted += queryTask_ExecuteCompleted;
queryTask.Failed += queryTask_Failed;
queryTask.ExecuteAsync(query);
MyDrawObject = new Draw(MyMap)
{
DrawMode = DrawMode.Polyline,
IsEnabled = true,
LineSymbol = LayoutRoot.Resources["RedLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol
};
MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
outputGraphicsLayer = MyMap.Layers["CompletedGraphicsLayer"] as GraphicsLayer;
}
void queryTask_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Query error: " + e.Error);
}
void queryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
GraphicsLayer parcelGraphicsLayer = MyMap.Layers["ParcelsGraphicsLayer"] as GraphicsLayer;
foreach (Graphic g in e.FeatureSet.Features)
{
g.Symbol = LayoutRoot.Resources["BlueFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
parcelGraphicsLayer.Graphics.Add(g);
}
}
privatevoid MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
{
//outputGraphicsLayer.ClearGraphics();
ESRI.ArcGIS.Client.Geometry.Polyline polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
polyline.SpatialReference = MyMap.SpatialReference;
Graphic polylineGraphic = new Graphic()
{
Geometry = polyline
};
List<Graphic> polylineList = new List<Graphic>();
polylineList.Add(polylineGraphic);
GeometryService geometryService =
new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.AutoCompleteCompleted += GeometryService_AutoCompleteCompleted;
geometryService.Failed += GeometryService_Failed;
GraphicsLayer graphicsLayer = MyMap.Layers["ParcelsGraphicsLayer"] as GraphicsLayer;
List<Graphic> polygonList = new List<Graphic>();
foreach (Graphic g in graphicsLayer.Graphics)
{
g.Geometry.SpatialReference = MyMap.SpatialReference;
polygonList.Add(g);
}
geometryService.AutoCompleteAsync(polygonList, polylineList);
}
void GeometryService_AutoCompleteCompleted(object sender, GraphicsEventArgs e)
{
outputGraphicsLayer.ClearGraphics();
foreach (Graphic g in e.Results)
{
g.Symbol = LayoutRoot.Resources["RedFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
outputGraphicsLayer.Graphics.Add(g);
}
if (e.Results.Count > 0)
(MyMap.Layers["ConnectDotsGraphicsLayer"] as GraphicsLayer).ClearGraphics();
}
privatevoid GeometryService_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Geometry Service error: " + e.Error);
}
}
}
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Namespace ArcGISWPFSDK
PartialPublicClass AutoComplete
Inherits UserControl
Private MyDrawObject As Draw
Private outputGraphicsLayer As GraphicsLayer
PublicSubNew()
InitializeComponent()
MyMap.MinimumResolution = Double.Epsilon
Dim queryTask AsNew QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/TaxParcel/AssessorsParcelCharacteristics/MapServer/1")
Dim query AsNew Query()
query.Geometry = MyMap.Extent
query.ReturnGeometry = TrueAddHandler queryTask.ExecuteCompleted, AddressOf queryTask_ExecuteCompleted
AddHandler queryTask.Failed, AddressOf queryTask_Failed
queryTask.ExecuteAsync(query)
MyDrawObject = New Draw(MyMap) With { _
.DrawMode = DrawMode.Polyline, _
.IsEnabled = True, _
.LineSymbol = TryCast(LayoutRoot.Resources("RedLineSymbol"), ESRI.ArcGIS.Client.Symbols.LineSymbol) _
}
AddHandler MyDrawObject.DrawComplete, AddressOf MyDrawObject_DrawComplete
outputGraphicsLayer = TryCast(MyMap.Layers("CompletedGraphicsLayer"), GraphicsLayer)
EndSubPrivateSub queryTask_Failed(sender AsObject, e As TaskFailedEventArgs)
MessageBox.Show("Query error: " & Convert.ToString(e.[Error]))
EndSubPrivateSub queryTask_ExecuteCompleted(sender AsObject, e As QueryEventArgs)
Dim parcelGraphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("ParcelsGraphicsLayer"), GraphicsLayer)
ForEach g As Graphic In e.FeatureSet.Features
g.Symbol = TryCast(LayoutRoot.Resources("BlueFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
parcelGraphicsLayer.Graphics.Add(g)
NextEndSubPrivateSub MyDrawObject_DrawComplete(sender AsObject, args As DrawEventArgs)
'outputGraphicsLayer.ClearGraphics();Dim polyline As ESRI.ArcGIS.Client.Geometry.Polyline = TryCast(args.Geometry, ESRI.ArcGIS.Client.Geometry.Polyline)
polyline.SpatialReference = MyMap.SpatialReference
Dim polylineGraphic AsNew Graphic() With { _
.Geometry = polyline _
}
Dim polylineList AsNew List(Of Graphic)()
polylineList.Add(polylineGraphic)
Dim geometryService AsNew GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer")
AddHandler geometryService.AutoCompleteCompleted, AddressOf GeometryService_AutoCompleteCompleted
AddHandler geometryService.Failed, AddressOf GeometryService_Failed
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("ParcelsGraphicsLayer"), GraphicsLayer)
Dim polygonList AsNew List(Of Graphic)()
ForEach g As Graphic In graphicsLayer.Graphics
g.Geometry.SpatialReference = MyMap.SpatialReference
polygonList.Add(g)
Next
geometryService.AutoCompleteAsync(polygonList, polylineList)
EndSubPrivateSub GeometryService_AutoCompleteCompleted(sender AsObject, e As GraphicsEventArgs)
outputGraphicsLayer.ClearGraphics()
ForEach g As Graphic In e.Results
g.Symbol = TryCast(LayoutRoot.Resources("RedFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
outputGraphicsLayer.Graphics.Add(g)
NextIf e.Results.Count > 0 Then
TryCast(MyMap.Layers("ConnectDotsGraphicsLayer"), GraphicsLayer).ClearGraphics()
EndIfEndSubPrivateSub GeometryService_Failed(sender AsObject, e As TaskFailedEventArgs)
MessageBox.Show("Geometry Service error: " & Convert.ToString(e.[Error]))
EndSubEndClassEndNamespace