//zoom to featurelayer
void featureLayer_UpdateCompleted(object sender, EventArgs e)
{
FeatureLayer projFeatureLayer = (FeatureLayer)sender;
SetLegend();
if (projFeatureLayer.FullExtent != null)
{
double projectXMin = projFeatureLayer.FullExtent.XMin;
double projectXMax = projFeatureLayer.FullExtent.XMax;
double projectYMin = projFeatureLayer.FullExtent.YMin;
double projectYMax = projFeatureLayer.FullExtent.YMax;
double coordOffset = .01;
//Envelope cannot be a single point?
if (projectXMin == projectXMax && projectYMin == projectYMax)
{
projectXMax = projectXMax + coordOffset;
projectXMin = projectXMin - coordOffset;
}
Envelope projectEnvelope = new Envelope(projectXMin, projectYMin, projectXMax, projectYMax);
mainPage.map.ZoomTo(projectEnvelope);
}
else
{
mainPage.lblcustomStatusBar.Content = "Feature not found";
mainPage.lblcustomStatusBar.Foreground = new SolidColorBrush(Colors.Red);
mainPage.panelCustomLegend.Visibility = System.Windows.Visibility.Collapsed;
}
}Are you working with points?
I tested your code with the FeatureLayerSimple interactive sample and it looks working (despite there is only one feature layer).
Could you give more info on how to reproduce the issue? Thanks
FeatureSet featureSet = e.FeatureSet;
if (featureSet != null && featureSet.Features.Count > 0)
{
// If an item has been selected
GraphicsLayer graphicsLayer = mainPage.map.Layers["tempGraphicLayer"] as GraphicsLayer;
if (graphicsLayer == null)
{
graphicsLayer = new GraphicsLayer();
graphicsLayer.ID = "tempGraphicLayer";
mainPage.map.Layers.Add(graphicsLayer);
}
Graphic selectedFeature = null;
for (int i = 0; i < featureSet.Features.Count; i++)
{
// Show selected feature attributes in DataGrid
selectedFeature = featureSet.Features;
selectedFeature.Symbol = LayoutRoot.Resources["MarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
graphicsLayer.Graphics.Add(selectedFeature);
}
graphicsLayer.Opacity = 0.7;
double expandPercentage = 30;
double widthExpand = graphicsLayer.FullExtent.Width * (expandPercentage / 100);
double heightExpand = graphicsLayer.FullExtent.Height * (expandPercentage / 100);
if (graphicsLayer != null)
{
ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
graphicsLayer.FullExtent.XMin - (widthExpand / 2),
graphicsLayer.FullExtent.YMin - (heightExpand / 2),
graphicsLayer.FullExtent.XMax + (widthExpand / 2),
graphicsLayer.FullExtent.YMax + (heightExpand / 2));
mainPage.map.ZoomTo(displayExtent);
KeyValuePair<int, string> str = (KeyValuePair<int, string>)lstChainage.SelectedItem;
mainPage.lblcustomStatusBar.Content = str.Value + " located";
mainPage.lblcustomStatusBar.Foreground = new SolidColorBrush(Colors.Blue);
}
}
I tweaked the FeatureLayerSimple sample to return only one feature (Where="CITY_NAME='Spokane'") and your initial code is still working.
Though the code you just posted is not working since the FullExtent size is zero (the size of one point geometry is zero : that's normal).
So I suggest that in this case you introduce a minimum size (as you did in your first post with 'coordOffset')