Select to view content in your preferred language

FullExtent of GroupLayer

680
1
04-24-2013 12:22 PM
LanceCrumbliss
Frequent Contributor
Is there anyway to get the FullExtent of a GroupLayer?  It always seems to be null, even when all other layers (siblings, childlayers) and the map itself are in the same spatialreference.  If there isn't a way, then what is the best way to zoom to the extent of a grouplayers childlayers?
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
If you are sure all your layers are in the same spatial reference you can Union the FullExtent of the children.

Code:

public Envelope GetFullExtent(Layer layer)
{
    if (layer is GroupLayer)
    {
        Envelope env = null;
        foreach (var l in ((GroupLayer) layer))
        {
            var e1 = GetFullExtent(l);
            if (env == null)
                env = e1;
            else
                env = env.Union(e1);
        }
        return env;
    }
    else
    {
        return layer.FullExtent;
    }
}
Or shorter but less clear:

public Envelope GetFullExtent(Layer layer)
{
    return layer is GroupLayer ? ((GroupLayer) layer).Aggregate<Layer, Envelope>(null, (env, l) => env == null ? GetFullExtent(l) : env.Union(GetFullExtent(l))) : layer.FullExtent;
}
0 Kudos