Esempio n. 1
0
        // Update the filter when the user clicks OK.
        // Note that we are not setting DialogResult here;
        // that's done in the base class.
        private void buttonOK_Click(object sender, System.EventArgs e)
        {
            if (_filter != null && _filter is ToolFilter &&
                listBoxList.Items.Count > 0)
            {
                // The list is not empty, and the filter is a type of filter
                // that we can modify; proceed.
                ToolFilter toolFilter =
                    _filter as ToolFilter;

                // Try to cast the various filters to ToolFilter objects,
                // so that we can call the ToolFilter.SetExplicitInclude method
                ToolFilter selectToolFilter = null;
                if (_selectFilter != null)
                {
                    selectToolFilter = _selectFilter as ToolFilter;
                }

                ToolFilter editToolFilter = null;
                if (_editFilter != null)
                {
                    editToolFilter = _editFilter as ToolFilter;
                }

                ToolFilter insertToolFilter = null;
                if (_insertFilter != null)
                {
                    insertToolFilter = _insertFilter as ToolFilter;
                }

                // Check each list item to see if it has been selected or de-selected
                for (int i = 0; i < listBoxList.Items.Count; i++)
                {
                    FeatureLayer layer    = (FeatureLayer)(listBoxList.Items[i]);
                    bool         bInclude = listBoxList.GetSelected(i);
                    if (bInclude && !(_filter.IncludeLayer(layer))
                        ||
                        !bInclude && _filter.IncludeLayer(layer)
                        )
                    {
                        // Either the layer was on and the user turned it off,
                        // or vice versa.  Update the filter's status to note
                        // that the layer has been explicitly turned on or off.
                        toolFilter.SetExplicitInclude(layer, bInclude);

                        // Now, we might want to adjust the other filters.
                        // For example, if a layer is changed so that it is no
                        // longer selectable, we should turn off Editable and Insertable.
                        // Or if a layer is made Insertable (Drawable),
                        // we should make sure both Selectable and Editable are on.
                        if (FilterType == FilterType.Selectable)
                        {
                            // We're letting the user choose the selectable layers...
                            if (!bInclude)
                            {
                                // The user changed this layer to NOT be selectable,
                                // so make sure the layer isn't Editable or Insertable
                                if (editToolFilter != null &&
                                    editToolFilter.IncludeLayer(layer))
                                {
                                    // This layer IS currently editable; turn it off.
                                    editToolFilter.SetExplicitInclude(layer, false);
                                }

                                if (insertToolFilter != null &&
                                    insertToolFilter.IncludeLayer(layer))
                                {
                                    // This layer IS currently insertable; turn it off.
                                    insertToolFilter.SetExplicitInclude(layer, false);
                                }
                            }
                        }
                        else if (FilterType == FilterType.Editable)
                        {
                            // We're letting the user choose the editable layers...
                            if (bInclude)
                            {
                                // The user changed this layer to be editable,
                                // so make sure the layer IS Selectable
                                if (selectToolFilter != null &&
                                    !selectToolFilter.IncludeLayer(layer))
                                {
                                    // This layer is NOT currently selectable; turn it on.
                                    selectToolFilter.SetExplicitInclude(layer, true);
                                }
                            }
                            else
                            {
                                // The user changed this layer to be NOT editable,
                                // so make sure it isn't Insertable either.
                                if (insertToolFilter != null &&
                                    insertToolFilter.IncludeLayer(layer))
                                {
                                    // This layer IS currently insertable; turn it off.
                                    insertToolFilter.SetExplicitInclude(layer, false);
                                }
                            }
                        }
                        else
                        {
                            // We're letting the user choose the insertable layers...
                            if (bInclude)
                            {
                                // The user changed this layer to be insertable,
                                // so make sure the layer IS Editable and Selectable
                                if (selectToolFilter != null &&
                                    !selectToolFilter.IncludeLayer(layer))
                                {
                                    // This layer is NOT currently selectable; turn it on.
                                    selectToolFilter.SetExplicitInclude(layer, true);
                                }
                                if (editToolFilter != null &&
                                    !editToolFilter.IncludeLayer(layer))
                                {
                                    // This layer is NOT currently editable; turn it on.
                                    editToolFilter.SetExplicitInclude(layer, true);
                                }
                            }
                        }
                    }
                }
            }
            // Let the base class set DialogResult
        }
        // Return a comma-separated list of layer names, representing the list of
        // layers that are active according to the specified filter.
        // This method calls itself recursively to search within GroupLayers.
        private string BuildLayerList(string str, LayersBase layers, IMapLayerFilter filter)
        {
            bool bAllLayers=true;

            foreach (IMapLayer layer in layers)
            {
                if (layer is GroupLayer)
                {
                    GroupLayer grpLyr = layer as GroupLayer;
                    str = BuildLayerList(str, grpLyr, filter);
                    if (str.StartsWith("<All>: ")) str=str.Remove(0,7);
                    else bAllLayers=false;
                }
                else if (layer is FeatureLayer)
                {
                    FeatureLayer featLyr = layer as FeatureLayer;
                    if (featLyr != null && featLyr.IsVisible &&
                        featLyr.Type != LayerType.Raster &&
                        featLyr.Type != LayerType.Wms &&
                        featLyr.Type != LayerType.Grid)
                    {
                        if (filter.IncludeLayer(featLyr) )
                        {
                            if (str.Length > 0)
                            {
                                str += ", ";
                            }
                            str += featLyr.Name;
                        }
                        else bAllLayers=false;
                    }
                }
            }

            if (str.Length==0) str = bAllLayers ? "<No layers available>" : "<None>";

            else if (bAllLayers==true)
            {
                if (str.Length > 16) str="<All>";
                else str="<All>: " + str;
            }

            return str;
        }
Esempio n. 3
0
        // Return a comma-separated list of layer names, representing the list of
        // layers that are active according to the specified filter.
        // This method calls itself recursively to search within GroupLayers.
        private string BuildLayerList(string str, LayersBase layers, IMapLayerFilter filter)
        {
            bool bAllLayers = true;

            foreach (IMapLayer layer in layers)
            {
                if (layer is GroupLayer)
                {
                    GroupLayer grpLyr = layer as GroupLayer;
                    str = BuildLayerList(str, grpLyr, filter);
                    if (str.StartsWith("<All>: "))
                    {
                        str = str.Remove(0, 7);
                    }
                    else
                    {
                        bAllLayers = false;
                    }
                }
                else if (layer is FeatureLayer)
                {
                    FeatureLayer featLyr = layer as FeatureLayer;
                    if (featLyr != null && featLyr.IsVisible &&
                        featLyr.Type != LayerType.Raster &&
                        featLyr.Type != LayerType.Wms &&
                        featLyr.Type != LayerType.Grid)
                    {
                        if (filter.IncludeLayer(featLyr))
                        {
                            if (str.Length > 0)
                            {
                                str += ", ";
                            }
                            str += featLyr.Name;
                        }
                        else
                        {
                            bAllLayers = false;
                        }
                    }
                }
            }

            if (str.Length == 0)
            {
                str = bAllLayers ? "<No layers available>" : "<None>";
            }

            else if (bAllLayers == true)
            {
                if (str.Length > 16)
                {
                    str = "<All>";
                }
                else
                {
                    str = "<All>: " + str;
                }
            }

            return(str);
        }