Zoom to layer

Jul 28, 2012 at 1:01 AM
Edited Jul 28, 2012 at 1:02 AM

Sorry if such an elementary thing has been covered but I searched and searched and couldn't find it.  How can I zoom to the extent of a layer? 

What I'm looking for is something like

Map.ZoomToLayer(1)
but that obviously doesn't exist.

Jul 28, 2012 at 1:16 AM
Edited Jul 28, 2012 at 1:17 AM

Hi,

Here goes some code:

foreach (IMapLayer lay in map1.GetAllLayers())
{
    if (lay != null)
    {
        if (lay.IsSelected == true)
        {
            //gets the SelectedLayer
            var layer = map1.Layers.SelectedLayer;
            if (layer != null)
            map1.ViewExtents = layer.DataSet.Extent;
        }
        else
        {
         //if lay is not selected, ask the user to select  (highlight) some layer
        MessageBox.Show("Selecione uma Camada.");   
        }
    }
    else
    {
        //if lay is null, ask the user to add some layer
        MessageBox.Show("Adicione uma Camada.");
    }
}
Regards,
Evemar
Jul 31, 2012 at 6:40 PM

Thanks. 

Aug 3, 2012 at 2:59 AM

well, can you test the function with the layer of mappointlayer which has only one point feature, i test it and there is no exception but show nothing on the map , it seems that the point feature disappear!  can you tell me a tips or give me some example code, i will very appreciate with your help!

Aug 3, 2012 at 1:57 PM

Hi,

I have tested that and when I make zoom to a point layer with only one point, it raises an exception.

I will investigate and try some workaround.

Regards,

Evemar