public void ShowFeatures(List<IdentifyResult> results)
{
_dataItems = new List<DataItem>();
if (results != null && results.Count > 0)
{
IdentifyComboBox.Items.Clear();
foreach (IdentifyResult result in results)
{
Graphic feature = result.Feature;
string title = result.Value.ToString() + " (" + result.LayerName + ")";
_dataItems.Add(new DataItem()
{
Title = title,
Data = feature.Attributes
});
IdentifyComboBox.Items.Add(title);
}
// Workaround for bug with ComboBox
IdentifyComboBox.UpdateLayout();
IdentifyComboBox.SelectedIndex = 0;
}
IdentifyDetailsDataGrid.IsEnabled = false;
}
private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
{
IdentifyDetailsDataGrid.ItemsSource = null;
if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
{
IdentifyResultsPanel.Visibility = Visibility.Visible;
ShowFeatures(args.IdentifyResults);
}
else
{
IdentifyComboBox.Items.Clear();
IdentifyComboBox.UpdateLayout();
//IdentifyResultsPanel.Visibility = Visibility.Collapsed;
}
//test to colour clicked layers
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
if (args.IdentifyResults.Count > 0)
{
foreach (IdentifyResult result in args.IdentifyResults)
{
Graphic graphic = result.Feature;
switch (graphic.Attributes["Shape"].ToString())
{
case "Polygon":
graphic.Symbol = DefaultFillSymbol;
break;
case "Polyline":
graphic.Symbol = DefaultLineSymbol;
break;
case "Point":
graphic.Symbol = DefaultMarkerSymbol;
break;
}
graphicsLayer.Graphics.Add(result.Feature);
}
}
else
{
// MessageBox.Show("Found " + args.IdentifyResults.Count + " Features");
}
}
GraphicCollection toBuffer = new GraphicCollection();
void it_ExecuteCompleted(object sender, IdentifyEventArgs e)
{
bp.Features.Clear();
toBuffer.Clear();
foreach (var result in e.IdentifyResults)
{
if (bp.Features.Count == 0 || bp.Features[0].Geometry.GetType() == result.Feature.Geometry.GetType())
bp.Features.Add(result.Feature);
else
toBuffer.Add(result.Feature);
}
gm.BufferAsync(bp);
}
void gm_BufferCompleted(object sender, GraphicsEventArgs e)
{
GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
foreach(var result in e.Results)
{
layer.Graphics.Add(new Graphic()
{
Geometry = result.Geometry,
Symbol = this.LayoutRoot.Resources["RedFillSymbol"] as Symbol
});
}
if (toBuffer.Count > 0)
{
bp.Features.Clear();
foreach (var g in toBuffer)
{
if (bp.Features.Count == 0 || bp.Features[0].Geometry.GetType() == g.Geometry.GetType())
bp.Features.Add(g);
}
foreach (var g in bp.Features)
toBuffer.Remove(g);
gm.BufferAsync(bp);
}
}
GraphicCollection toBuffer = new GraphicCollection();
BufferParameters bp = new BufferParameters()
{
Unit = LinearUnit.Meter,
BufferSpatialReference = new SpatialReference(4326),
OutSpatialReference = MyMap.SpatialReference,
UnionResults = true
};
GeometryService gm=
new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
gm.BufferCompleted += GeometryService_BufferCompleted;
gm.Failed += GeometryService_Failed;