FeatureLayer lyr = MapView.Layers[1] as FeatureLayer; foreach (Graphic g in lyr) { if (g.Geometry == null || g.Geometry.Extent == null) { MessageBox.Show(string.Format("Graphic with ID={0} has no extent.", g.Attributes["ObjectID"])); break; } }
foreach (Graphic g in lyr.Graphics) {//same code goes here.}
<esri:SimpleMarkerSymbol x:Key="ResultsMarkerSymbol" > <esri:SimpleMarkerSymbol.ControlTemplate> <ControlTemplate> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"> <Storyboard> <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty= "(Fill).(Color)" To="#FFF5FF45" Duration="0:0:0.1" /> </Storyboard> </VisualState> <VisualState x:Name="MouseOver"> <Storyboard> <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Fill).(Color)" To="#8800FFFF" Duration="0:0:0.1" /> </Storyboard> </VisualState> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Fill).(Color)" To="#8800FFFF" Duration="0:0:0.1" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Ellipse x:Name= "Element" Stroke="Blue" Fill="#8800FFFF" StrokeStartLineCap="Round" StrokeThickness="2" StrokeLineJoin="Round" StrokeEndLineCap="Round" Width="16" Height="16" /> </Grid> </ControlTemplate> </esri:SimpleMarkerSymbol.ControlTemplate> </esri:SimpleMarkerSymbol>
if (featureSet != null && featureSet.Features.Count > 0) { // Show selected feature attributes in DataGrid foreach (Graphic selectedFeature in featureSet.Features) { // Hightlight selected feature selectedFeature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol; // Add to table DataGrid graphicsLayer.Graphics.Add(selectedFeature); // Zoom to selected feature (define expand percentage) ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = selectedFeature.Geometry.Extent; double expandPercentage = 30; double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100); double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100); ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope( selectedFeatureExtent.XMin - (widthExpand / 2), selectedFeatureExtent.YMin - (heightExpand / 2), selectedFeatureExtent.XMax + (widthExpand / 2), selectedFeatureExtent.YMax + (heightExpand / 2)); Map.ZoomTo(displayExtent); } ResultsDisplay.Visibility = Visibility.Visible; } MyDrawSurface.IsEnabled = false;