Select to view content in your preferred language

Zooming to just beyond full extent

727
2
10-26-2010 02:41 PM
JackCibor
Frequent Contributor
In my silverlight apps i am trying to have the map zoom to the results of queries or GP tasks (graphics layers) with the following C# code:

MyMap.ZoomTo(graphicsLayer.FullExtent)

When i do so, the furthest outlying feature is right on the edge of the map. So I want to zoom to something just greater than the full extent so there is a little space between my furthest out feature and the edge of the map.

So I came up with something like this:

                Envelope myExtent = new Envelope();
                myExtent.XMax = ((graphicsLayer.FullExtent.XMax) + 0.02);
                myExtent.XMin = ((graphicsLayer.FullExtent.XMin) - 0.02);
                myExtent.YMax = ((graphicsLayer.FullExtent.YMax) + 0.02);
                myExtent.YMin = ((graphicsLayer.FullExtent.YMin) - 0.02);
                //MyMap.ZoomTo(graphicsLayer.FullExtent)
                MyMap.ZoomTo(myExtent);

But this only works for zooming in a narrow range of scales. If scales vary greatly this kind of approach does not work well.


Have you seen any examples of a better way to do this??
0 Kudos
2 Replies
STharshini
Emerging Contributor
In my silverlight apps i am trying to have the map zoom to the results of queries or GP tasks (graphics layers) with the following C# code:

MyMap.ZoomTo(graphicsLayer.FullExtent)

When i do so, the furthest outlying feature is right on the edge of the map. So I want to zoom to something just greater than the full extent so there is a little space between my furthest out feature and the edge of the map.

So I came up with something like this:

                Envelope myExtent = new Envelope();
                myExtent.XMax = ((graphicsLayer.FullExtent.XMax) + 0.02);
                myExtent.XMin = ((graphicsLayer.FullExtent.XMin) - 0.02);
                myExtent.YMax = ((graphicsLayer.FullExtent.YMax) + 0.02);
                myExtent.YMin = ((graphicsLayer.FullExtent.YMin) - 0.02);
                //MyMap.ZoomTo(graphicsLayer.FullExtent)
                MyMap.ZoomTo(myExtent);

But this only works for zooming in a narrow range of scales. If scales vary greatly this kind of approach does not work well.


Have you seen any examples of a better way to do this??



Have you tried :myMap.Zoom();Please check the below link

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~Zoom.h...

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~ZoomFa...
0 Kudos
JackCibor
Frequent Contributor
Have you tried :myMap.Zoom();Please check the below link

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~Zoom.h...

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~ZoomFa...


It seems that the zoom factor is for double clicking and scrolling with the mouse. And MyMap.Zoom zooms in a specified amount from the current extent. So I tried          

Map1.ZoomTo(graphicsLayer.FullExtent);
Map1.Zoom(0.9);

But when I do this the second line executes an instant after the first line, so the map is zoomed by the second line before it has a chance to zoom to the extent of the graphics layer.
0 Kudos