private static void filterSelected(ILayer layer, IMapView2D view, IExtents worldBounds)
        {
            if (layer == null)
            {
                return;
            }

            FeatureLayer filterLayer = layer as FeatureLayer;

            if (filterLayer != null)
            {
                if (layer.Enabled &&
                    filterLayer.AreFeaturesSelectable &&
                    layer.IsVisibleWhen(isInView(view.WorldWidth)))
                {
                    SpatialBinaryExpression spatialExpression
                        = SpatialBinaryExpression.Intersects(new FeaturesCollectionExpression(filterLayer.Features),
                                                             new ExtentsExpression(worldBounds));
                    filterLayer.SelectedFilter = filterLayer.SelectedFilter == null
                        ? new FeatureQueryExpression(new AllAttributesExpression(), spatialExpression, null)
                        : new FeatureQueryExpression(filterLayer.SelectedFilter, spatialExpression);
                }
            }

            IEnumerable <ILayer> layers = layer as IEnumerable <ILayer>;

            if (layers != null)
            {
                foreach (ILayer child in layers)
                {
                    filterSelected(child, view, worldBounds);
                }
            }
        }