private void btnStartSplit_Click(object sender, RoutedEventArgs e)
{
// Empty container that gets filled with the polygon geometry I want
// cut by a polyline geometry.
private IList<Graphic> toSplit = new List<Graphic>();
// The source of the graphics used during cutting
GraphicsLayer editsMapLayer = ((GraphicsLayer)MainPage.CPMap.Layers["GraphicsLayer_PLUSelection"]);
// Look for the polyline I drew earlier, of which there will only be one
// because without the polyline, we cannot perform the cut...
//
// Start by getting a collection of all graphics in the graphics layer
GraphicCollection tEdits = editsMapLayer.Graphics;
// Then return only the geometries (of which there will be 0 or 1) where the type is
// ESRI....Polyline
Graphic theLine = tEdits.Where(g => g.Geometry.GetType().FullName == "ESRI.ArcGIS.Client.Geometry.Polyline").FirstOrDefault();
if (theLine == null) return; // And quit here if there was no line
// Obtain the geometry of that line...
ESRI.ArcGIS.Client.Geometry.Polyline theLineGeom = (ESRI.ArcGIS.Client.Geometry.Polyline)theLine.Geometry;
// I know that there is a polygon in my graphics layer to cut, so I search for it and add
// it to my set of geometries to be cut.
toSplit.Add(tEdits.Where(g => g.Geometry.GetType().FullName == "ESRI.ArcGIS.Client.Geometry.Polygon").FirstOrDefault());
// Create a new geometry service
ESRI.ArcGIS.Client.Tasks.GeometryService geoSvc = new ESRI.ArcGIS.Client.Tasks.GeometryService(MainPage.editorMainMap.GeometryServiceUrl);
// Setup the event handler
geoSvc.CutCompleted += new EventHandler<ESRI.ArcGIS.Client.Tasks.CutEventArgs>(geoSvc_CutCompleted);
// Call the cut process asynchronously passing in the container of one polygon geometry to cut,
// and one polyline geometry with which to cut that polygon geometry.
geoSvc.CutAsync(toSplit,theLineGeom);
}
void geoSvc_CutCompleted(object sender, ESRI.ArcGIS.Client.Tasks.CutEventArgs e)
{
MessageBox.Show("Cut Event Returned At Least!");
// I will be adding the returned geometries as new graphics to the SubAreas Featurelayer of my map.
FeatureLayer subareaMapLayer = ((FeatureLayer)MainPage.CPMap.Layers["SubAreas"]);
// Featurelayer save-event-handlers
subareaMapLayer.SaveEditsFailed += new EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(subareaMapLayer_SaveEditsFailed);
subareaMapLayer.EndSaveEdits += new EventHandler<ESRI.ArcGIS.Client.Tasks.EndEditEventArgs>(subareaMapLayer_EndSaveEdits);
subareaMapLayer.BeginSaveEdits += new EventHandler<ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs>(subareaMapLayer_BeginSaveEdits);
// This is where I find I will loop two times, once for each returned geometry...
// one geometry (A from my description above) is correct, and one (P) is not. There
// does not appear to be a third geometry (B)...
foreach (Graphic g in e.Results)
{
// Give the geometry/graphic a default symbol
g.Symbol = MainPage.MainGrid.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
// Set some attributes on the geometry/graphic...
g.Attributes["SubareaID"] = "{" + Guid.NewGuid().ToString() + "}";
g.Attributes["PlanningLandUnitID"] = OriginPlanningLandUnitId;
g.Attributes["LandUseID"] = Convert.ToInt32(OriginPlanningLandUnitUseId);
g.Attributes["parent_subareaid"] = SplitPractice.Description.ToString();
// Add the new graphic to the Featurelayer
subareaMapLayer.Graphics.Add(g);
// Save the edit
subareaMapLayer.SaveEdits();
} // Process next geometry/graphic in return set
subareaMapLayer.Update();
}
<esri:Editor x:Key="MyEditor"
Map="{Binding ElementName=MyMap}"
LayerIDs="ThreatAreas"
GeometryServiceUrl="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"
/>
for (int i = 0; i < e.Results.Count; i++)
{
int cutIndex = e.CutIndexes;
var r = e.Results[cutIndex];
//more code goes here.
}