Zoom to multiple  Feature Layers

2014
4
02-20-2012 07:15 PM
SantoshV
New Contributor II
Hi, I have a query where I add many feature in runtime..
now i write
               
 if (projFeatureLayer.FullExtent != null)
                {
                    double projectXMin = projFeatureLayer.FullExtent.XMin;
                    double projectXMax = projFeatureLayer.FullExtent.XMax;
                    double projectYMin = projFeatureLayer.FullExtent.YMin;
                    double projectYMax = projFeatureLayer.FullExtent.YMax;
                    //To also Envelope a single point
                    double coordOffset = .01;

                    if (projectXMin == projectXMax && projectYMin == projectYMax)
                    {
                        projectXMax = projectXMax + coordOffset;
                        projectXMin = projectXMin - coordOffset;
                    }

                    //Set Zoom Duration (Time)
                    mainPage.map.ZoomDuration = new TimeSpan(0, 0, Convert.ToInt32(App.Current.Resources["ZoomDuration"]));

                    Envelope projectEnvelope = new Envelope(projectXMin, projectYMin, projectXMax, projectYMax);
                    //Set zoom Extents
                    mainPage.map.ZoomTo(projectEnvelope.Expand(Convert.ToDouble(App.Current.Resources["ZoomExpand"])));
                    mainPage.panelCustomLegend.Visibility = System.Windows.Visibility.Visible;

                    //mainPage.boolRefreshCustomLegend = true;
                    //mainPage.CustomLegend.Refresh();

                    return true;
                }

to zoom to one feature layer on "feature layer update-completed event" but how do I zoom to all the feature layers added on the map...??

Please guide
0 Kudos
4 Replies
OrlandoCarvajal
New Contributor III
If you are loading multiple layers at runtime at once and you want to do some processing after all of them have finished updating, you'll have to keep a counter to find out when all of them have completed. Then you can calculate the extent from all layers by using Union() and do your zoom ...
I hope that's what you are looking for; I'm not quite sure of your scenario.
0 Kudos
SantoshV
New Contributor II
If you are loading multiple layers at runtime at once and you want to do some processing after all of them have finished updating, you'll have to keep a counter to find out when all of them have completed. Then you can calculate the extent from all layers by using Union() and do your zoom ...
I hope that's what you are looking for; I'm not quite sure of your scenario.


[ATTACH=CONFIG]12111[/ATTACH]

Hi thanks you for your reply..
I am sorry I did not give enough information about the query..

I have a query where the input values need me to query upto 3 ranges and I return 3 thematics with different symbology on the map
therefore I have created 3 layers with different symbology but same data and created a service to access it..

here I am adding 3 feature layers  onto the map .Since the query keysin values in range, for everyvalue keydin I create a new feature layer and display it on the map
1 feature layer for every range. so after adding 3 different feature layers I would like to zoom to its extent.
therefore I need to either merge(ie union the feature layer) else add up the extents..
is it possible to add the extents so that I can fix all the 3 feature layer on the map..
Please guide...
0 Kudos
OrlandoCarvajal
New Contributor III
That's what I meant by Union(). See example:

                Envelope extent = new Envelope();
                foreach (FeatureLayer featureLayer in featureLayers)
                    foreach (Graphic graphic in featureLayer.Graphics)
                        if (graphic.Geometry != null)
                            extent = extent.Union(graphic.Geometry.Extent);

                // do zoom ...
0 Kudos
SantoshV
New Contributor II
Thnx for your reply

I saved the XMin, XMax, YMin, YMax from the feature layer calculated the envelope and zoomed to it , it worked fine anywys 🙂
0 Kudos