Ejemplo n.º 1
0
        // Removes all layers from the map
        private void RemoveAllMapLayers()
        {
            MapLayerEnumerator enumer = mapControl1.Map.Layers.GetMapLayerEnumerator();

            while (enumer.MoveNext())
            {
                mapControl1.Map.Layers.Remove(enumer.Current);
            }
        }
Ejemplo n.º 2
0
        private void DeletePieTheme()
        {
            // Remove previous themes:
            MapLayerEnumerator e = mapControl1.Map.Layers.GetMapLayerEnumerator(MapLayerFilterFactory.FilterByType(typeof(ObjectThemeLayer)));

            while (e.MoveNext())
            {
                mapControl1.Map.Layers.Remove(e.Current);
                e = mapControl1.Map.Layers.GetMapLayerEnumerator(MapLayerFilterFactory.FilterByType(typeof(ObjectThemeLayer)));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets a given layer's visibility for a given map.
        /// </summary>
        /// <remarks>This method sets the layers visibility with a given layer alias to <c>true</c> or <c>false</c>.
        /// If the layer type is a feature layer, then it also sets the visibility for all modifers. If it is a group layer then it sets the visibility for all internal layers.
        /// If it is a label layer then it sets the visibility of all label sources. If the layer type passed is either a modifier or label source then it finds the modifier or label and sets the visibility.
        /// </remarks>
        /// <param name="mapAlias">MapAlias of the map.</param>
        /// <param name="layerAlias">LayerAlias of the layer.</param>
        /// <param name="lyrType">Type of the layer.</param>
        /// <param name="visible">Visibility to be set.</param>
        public virtual void SetLayerVisibility(string mapAlias, string layerAlias, string lyrType, bool visible)
        {
            Map map = GetMapObj(mapAlias);

            MapLayerEnumerator lenum = map.Layers.GetMapLayerEnumerator(MapLayerEnumeratorOptions.Recurse);

            foreach (IMapLayer lyr in lenum)
            {
                if (lyr.Alias.Equals(layerAlias) && lyr.Type.ToString().Equals(lyrType))
                {
                    lyr.Enabled = visible;
                    if (lyr.Type == LayerType.Normal)
                    {
                        FeatureStyleModifiers mods = ((FeatureLayer)lyr).Modifiers;
                        // Go through modifiers to set visibility
                        foreach (FeatureStyleModifier fsm in mods)
                        {
                            fsm.Enabled = visible;
                        }
                        break;
                    }
                    if (lyr.Type == LayerType.Group)
                    {
                        // Go through collection to set visibility
                        foreach (IMapLayer inlayer in (GroupLayer)lyr)
                        {
                            inlayer.Enabled = visible;
                        }
                        break;
                    }
                    if (lyr.Type == LayerType.Label)
                    {
                        // go through label sources to set visibility
                        foreach (LabelSource source in ((LabelLayer)lyr).Sources)
                        {
                            source.Enabled = visible;
                            foreach (LabelModifier lm in source.Modifiers)
                            {
                                lm.Enabled = visible;
                            }
                        }
                        break;
                    }
                }
                else
                {
                    // The layeralias did not match, hence the alias may be modifier or label source
                    // If it is modifier find it
                    if (lyrType.Equals("Mod"))
                    {
                        // Find it and set visibility
                        if (lyr.Type == LayerType.Normal)
                        {
                            FeatureStyleModifiers mods = ((FeatureLayer)lyr).Modifiers;
                            foreach (FeatureStyleModifier fsm in mods)
                            {
                                if (fsm.Alias.Equals(layerAlias))
                                {
                                    fsm.Enabled = visible;
                                }
                            }
                        }
                    }
                    // If it is label source find it and set it's visibility
                    if (lyrType.Equals("Label"))
                    {
                        if (lyr.Type == LayerType.Label)
                        {
                            foreach (LabelSource source in ((LabelLayer)lyr).Sources)
                            {
                                if (source.Alias.Equals(layerAlias))
                                {
                                    source.Enabled = visible;
                                    foreach (LabelModifier lm in source.Modifiers)
                                    {
                                        lm.Enabled = visible;
                                    }
                                }
                            }
                        }
                    }

                    // If it is label source modifier then set it's visibility
                    if (lyrType.Equals("LabelMod"))
                    {
                        if (lyr.Type == LayerType.Label)
                        {
                            foreach (LabelSource source in ((LabelLayer)lyr).Sources)
                            {
                                foreach (LabelModifier lm in source.Modifiers)
                                {
                                    if (lm.Alias.Equals(layerAlias))
                                    {
                                        lm.Enabled = visible;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Find a FeatureLayer in the map which uses the
        /// specified table, and return it.
        /// </summary>
        /// <param name="map">The Map object to search</param>
        /// <param name="sourceTable">
        /// A table which may or may not be displayed in a FeatureLayer</param>
        /// <param name="currentFeatureLayer">
        /// If null is passed, we will return the first FeatureLayer we find
        /// that uses the specified table; if currentFeatureLayer is not
        /// null, we will search for the next FeatureLayer that uses
        /// the same table.
        /// </param>
        /// <param name="wrapAround">true if you want a "find next" search
        /// to wrap around to the beginning of the layer tree, if necessary,
        /// to find the next layer; false if you do not want the search to wrap.
        /// </param>
        /// <returns>A FeatureLayer object (which may be identical to
        /// the currentFeatureLayer param, e.g. if the currentFeatureLayer
        /// param represents the only FeatureLayer in the map); or null if
        /// the map does not contain any FeatureLayer based on the specified table.
        /// </returns>
        private FeatureLayer LocateNextFeatureLayer(
            Map map, Table sourceTable, FeatureLayer currentFeatureLayer, bool wrapAround)
        {
            FilterByLayerType featureLayerFilter =
                new FilterByLayerType(
                    LayerType.Normal, LayerType.Grid,
                    LayerType.Raster, LayerType.Wms);

            MapLayerEnumerator mapLayerEnum =
                map.Layers.GetMapLayerEnumerator(
                    featureLayerFilter, MapLayerEnumeratorOptions.Recurse);

            FeatureLayer matchingFeatureLayer       = null;
            FeatureLayer firstMatchingFeatureLayer  = null;
            bool         bPassedCurrentFeatureLayer = false;

            foreach (FeatureLayer featLyr in mapLayerEnum)
            {
                if (featLyr.Table == sourceTable)
                {
                    // This FeatureLayer uses the correct table
                    if (firstMatchingFeatureLayer == null)
                    {
                        // We found our first match, so make a note of it,
                        // even though it may not be ideal (i.e. it may not
                        // be the "next" FeatureLayer that was requested).
                        firstMatchingFeatureLayer = featLyr;
                    }

                    // Now determine whether this match is an ideal match.
                    // We may have been passed a FeatureLayer, and asked
                    // to find the "next" FeatureLayer.  So we may need
                    // to skip over the current FeatureLayer if it's
                    // the same as the FeatureLayer that was passed in.
                    if (currentFeatureLayer != null &&
                        !bPassedCurrentFeatureLayer)
                    {
                        // We WERE asked to find the "next" FeatureLayer,
                        // which means that our first task is to find
                        // the FeatureLayer that the user right-clicked.
                        // But according to the flag, we have not yet
                        // looped past the currently-selected FeatureLayer.
                        // So we will continue the loop instead of
                        // assigning  matchingFeatureLayer.
                        if (featLyr == currentFeatureLayer)
                        {
                            bPassedCurrentFeatureLayer = true;
                        }
                        continue;
                    }

                    matchingFeatureLayer = featLyr;
                    break;
                }
            }

            if (matchingFeatureLayer == null)
            {
                // We did not find an ideal match (i.e. we may have been
                // asked to find the Next FeatureLayer, and there may not
                // have been a Next FeatureLayer).
                // At this point, since we did not find a perfect match,
                // we will consider a less-than-perfect match.
                if (wrapAround)
                {
                    // wrapAround is true, meaning that when we search for
                    // the next layer, we should wrap around to the top of
                    // the layer list, if necessary
                    matchingFeatureLayer = firstMatchingFeatureLayer;
                }
                else
                {
                    // wrapAround is false, meaning that when we cannot find
                    // a next layer, we should return the layer that was
                    // originally specified, which will tell the caller,
                    // "there is no Next layer."
                    matchingFeatureLayer = currentFeatureLayer;
                }
            }
            return(matchingFeatureLayer);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Find a LabelSource in the map which uses the
        /// specified table, and return it, or return null
        /// if no suitable LabelSource exists.
        /// </summary>
        /// <param name="map">The Map object to search</param>
        /// <param name="sourceTable">
        /// A table which may or may not be labeled currently</param>
        /// <param name="currentLabelSource">
        /// If null is passed, we will return the first LabelSource we find
        /// that uses the specified table; if currentLabelSource is not
        /// null, we will search for the next LabelSource that uses
        /// the same table.
        /// </param>
        /// <param name="wrapAround">true if you want a "find next" search
        /// to wrap around to the beginning of the layer tree, if necessary,
        /// to find the next LabelSource; false if you do not the search to wrap.
        /// </param>
        /// <returns>A LabelSource object (which may be identical to
        /// the currentLabelSource param, e.g. if the currentLabelSource
        /// param represents the only LabelSource in the map); or null if
        /// the map does not contain any LabelSource based on the specified table.
        /// </returns>
        private LabelSource LocateNextLabelSource(
            Map map, Table sourceTable, LabelSource currentLabelSource, bool wrapAround)
        {
            // Get a collection of all LabelLayers in the map
            FilterByLayerType labelLayerFilter =
                new FilterByLayerType(LayerType.Label);

            MapLayerEnumerator mapLayerEnum =
                map.Layers.GetMapLayerEnumerator(
                    labelLayerFilter, MapLayerEnumeratorOptions.Recurse);

            _firstLabelLayer = null;
            LabelSource matchingLabelSource       = null;
            LabelSource firstMatchingLabelSource  = null;
            bool        bPassedCurrentLabelSource = false;

            // Given the set of all LabelLayers in the layer tree,
            // search each LabelLayer to try to find a LabelSource
            // child node that is based on the specified table
            // (the sourceTable param).
            // OR: If a non-null currentLabelSource param
            // was passed in, then it represents an existing
            // LabelSource, and our job is to find the NEXT
            // LabelSource that uses the same table.
            foreach (LabelLayer ll in mapLayerEnum)
            {
                if (_firstLabelLayer == null)
                {
                    // Make a note of the first LabelLayer we find;
                    // later, if we decide to create a new LabelSource,
                    // it will go into this first LabelLayer.
                    _firstLabelLayer = ll;
                }

                // Look through this LabelLayer's collection of LabelSources
                foreach (LabelSource lblSource in ll.Sources)
                {
                    if (lblSource.Table == sourceTable)
                    {
                        // This LabelSource uses the correct table
                        if (firstMatchingLabelSource == null)
                        {
                            // We found our first match, so make a note of it,
                            // even though it may not be ideal (i.e. it may not
                            // be the "next" LabelSource that was requested).
                            firstMatchingLabelSource = lblSource;
                        }

                        // Now determine whether this match is an ideal match.
                        // We may have been passed a LabelSource, and asked
                        // to find the "next" LabelSource.  So we may need
                        // to skip over the current LabelSource if it's
                        // the same as the LabelSource that was passed in.
                        if (currentLabelSource != null &&
                            !bPassedCurrentLabelSource)
                        {
                            // We WERE asked to find the "next" LabelSource,
                            // which means that our first task is to find
                            // the LabelSource that the user right-clicked.
                            // But according to the flag, we have not yet
                            // looped past the currently-selected LabelSource.
                            // So we will continue the loop instead of
                            // assigning  matchingLabelSource.
                            if (lblSource == currentLabelSource)
                            {
                                // We were asked to find the next LabelSource,
                                // and this LabelSource is the same one that
                                // was passed in.  In this case, just set the
                                // flag, so that the next match will be used.
                                bPassedCurrentLabelSource = true;
                            }
                            continue;
                        }

                        // We found a LabelSource that is a perfect match.
                        matchingLabelSource = lblSource;
                        break;
                    }
                }                 // This ends the "for each LabelSource in this LabelLayer" loop

                if (matchingLabelSource != null)
                {
                    // We found an ideal match, so we can skip searching
                    // the other LabelLayers.  Break the outer foreach loop:
                    break;
                }
            }             // This ends the "for each LabelLayer" loop

            if (matchingLabelSource == null)
            {
                // We end up here if we did not find an ideal match; for
                // example, if we were asked to find the "next" node, and
                // we did not find a next matching node, but we did find a
                // previous matching node, we end up here.
                // At this point, since we did not find a perfect match,
                // we will consider a less-than-perfect match.
                if (wrapAround)
                {
                    // Wrapping is On, meaning that when we search for
                    // the next LabelSource, we should wrap around to the top of
                    // the layer list, if necessary
                    matchingLabelSource = firstMatchingLabelSource;
                }
                else
                {
                    // Wrap is Off, meaning: if we did not find a Next LabelSource,
                    // return the LabelSource that was originally specified,
                    // which will tell the caller, "there IS no Next LabelSource."
                    matchingLabelSource = currentLabelSource;
                }
            }
            return(matchingLabelSource);
        }