Select to view content in your preferred language

Zoom to Feature_layer not working when count is 1

854
6
01-09-2012 11:40 PM
SantoshV
Emerging Contributor
HI,
I have a method which returns a feature layer and zooms to it on the map..
but when the feature layer count is 1 the map does not zoom to the feature....
 //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;
            }
        }


Please do guide...
0 Kudos
6 Replies
JMcNeil
Deactivated User
Are you working with points?
0 Kudos
SantoshV
Emerging Contributor
Are you working with points?


Thnk you for the reply..
Yes I am working with point features here...
0 Kudos
DominiqueBroux
Esri Frequent Contributor
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
0 Kudos
SantoshV
Emerging Contributor
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


The code does work with a feature layer when the count is greater than 1 what I am talking is when the feature layer count is 1..
i.e only one feature....

for example in a graphics layer also when the graphic count is 1 the graphicsLayer.FullExtent.Width and graphicsLayer.FullExtent.Height is 0.0 but when the graphics count is greater than 2 it has values

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);
                    }
                }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
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')
0 Kudos
SantoshV
Emerging Contributor
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')


Yup your right I changed the value to 0.01 and it worked fine..
thnx a bunch 🙂
0 Kudos