Exemplo n.º 1
0
        /// <summary>
        ///     Determines whether the specified parent of the layer is visible in the map.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="layer">The layer.</param>
        /// <returns>Returns <see cref="bool" /> representing <c>true</c> when the parent layer is visible.</returns>
        public static bool IsParentVisible(this IMap source, ILayer layer)
        {
            bool isLayerVisible;
            bool isParentVisible;

            IMapLayers2 layers = (IMapLayers2)source;

            layers.IsLayerVisibleEx(layer, out isLayerVisible, out isParentVisible);
            return(isParentVisible);
        }
Exemplo n.º 2
0
        public void Refresh()
        {
            TableList.Clear();
            RelationLookup.Clear();
            IMap        aMap       = ArcMap.Document.FocusMap as IMap;
            IMapLayers2 layers     = ArcMap.Document.FocusMap as IMapLayers2;
            IEnumLayer  someLayers = layers.Layers;
            ILayer      aLayer     = null;

            while ((aLayer = someLayers.Next()) != null)
            {
                IFeatureLayer2 someFeatlayer = aLayer as IFeatureLayer2;
                if (someFeatlayer != null)
                {
                    IFeatureClass featClass = someFeatlayer.FeatureClass as IFeatureClass;
                    if (featClass != null)
                    {
                        IEnumRelationshipClass someRelationships = featClass.RelationshipClasses[esriRelRole.esriRelRoleAny] as IEnumRelationshipClass;
                        if (someRelationships != null)
                        {
                            IRelationshipClass aRelationship = someRelationships.Next();
                            while (aRelationship != null)
                            {
                                Debug.WriteLine(aRelationship.OriginClass.AliasName + " <--> " + aRelationship.DestinationClass.AliasName);
                                IDataset aDataset       = aRelationship.OriginClass as IDataset;
                                IDataset anotherDataset = aRelationship.DestinationClass as IDataset;
                                AddDataset(new IDataset[] { aDataset, anotherDataset });
                                IDataset aDS = featClass as IDataset;
                                if (aDS != null)
                                {
                                    Debug.WriteLine(aDS.Name + "," + aDataset.Name + "," + anotherDataset.Name);
                                    string name = aDS.Name.Equals(aDataset.Name, StringComparison.InvariantCultureIgnoreCase) ? anotherDataset.Name : aDataset.Name;
                                    if (RelationLookup.ContainsKey(name))
                                    {
                                        RelationLookup[name].Add(aRelationship);
                                    }
                                    else
                                    {
                                        RelationLookup.Add(name, new List <IRelationshipClass>()
                                        {
                                            aRelationship
                                        });
                                    }
                                }
                                aRelationship = someRelationships.Next();
                            }
                        }
                    }
                }
            }
            TableList.Sort((a, b) => a.TableName.CompareTo(b.TableName));
        }
Exemplo n.º 3
0
        public static void TraceLayerProperties(this IMap map)
        {
            string s  = "Layer: {0} is visible: {1}";
            string ms = "IMapLayers2: {0} is visible: {1}. Parent is visible:{2}";

            IEnumLayer  enumLayer = (IEnumLayer)map.get_Layers(null, true);
            IMapLayers2 mapLayers = map as IMapLayers2;
            ILayer      layer     = null;

            while ((layer = enumLayer.Next()) != null)
            {
                bool isvis;
                bool isparentvis;

                mapLayers.IsLayerVisibleEx(layer, out isvis, out isparentvis);

                ILayer2 layer2 = layer as ILayer2;
                Trace.WriteLine(s.FormatString(layer2.Name, layer2.Visible));

                Trace.WriteLine(ms.FormatString(layer2.Name, isvis, isparentvis));
            }
        }
Exemplo n.º 4
0
        public ILayer GetLayerFromFeature(IFeature feat)
        {
            IFeatureClass fc         = feat.Class as IFeatureClass;
            IMap          aMap       = ArcMap.Document.FocusMap as IMap;
            IMapLayers2   layers     = ArcMap.Document.FocusMap as IMapLayers2;
            IEnumLayer    someLayers = layers.Layers;
            ILayer        aLayer     = null;

            while ((aLayer = someLayers.Next()) != null)
            {
                IFeatureLayer2 someFeatlayer = aLayer as IFeatureLayer2;
                if (someFeatlayer != null)
                {
                    IDataset newDS = someFeatlayer.FeatureClass as IDataset;
                    IDataset ds    = feat.Class as IDataset;
                    Debug.WriteLine($"{newDS.Name},{ds.Name}");
                    if (newDS.Name.Equals(ds.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(aLayer);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Determines whether the specified layer is visible in the map.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="layer">The layer.</param>
        /// <returns>Returns <see cref="bool" /> representing <c>true</c> when the layer is visible.</returns>
        /// <remarks>
        ///     It does this by checking to see if the layer is not drawn due to scale ranges and also by validating whether
        ///     or not the layer is in a composite layer or group layer that is not visible.
        /// </remarks>
        public static bool IsLayerVisible(this IMap source, ILayer layer)
        {
            IMapLayers2 layers = (IMapLayers2)source;

            return(layers.IsLayerVisible(layer));
        }
Exemplo n.º 6
0
        private void method_2(IMapLayers2 imapLayers2_0, ILayer ilayer_0, bool bool_1)
        {
            Exception exception;

            try
            {
                if (imapLayers2_0 is IScene)
                {
                    try
                    {
                        imapLayers2_0.AddLayer(ilayer_0);
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        if (!(exception is COMException))
                        {
                            MessageBox.Show(exception.Message);
                        }
                        else if ((exception as COMException).ErrorCode != -2147219200)
                        {
                            MessageBox.Show(exception.Message);
                        }
                        else
                        {
                            MessageBox.Show("无法添加具有未知空间参考的数据");
                        }
                    }
                }
                else if (!(imapLayers2_0 is IGlobe))
                {
                    int layerIndex = -1;
                    layerIndex = CommonHelper.GetLayerIndex(imapLayers2_0 as IMap, ilayer_0);
                    imapLayers2_0.InsertLayer(ilayer_0, true, layerIndex);
                }
                else
                {
                    try
                    {
                        imapLayers2_0.AddLayer(ilayer_0);
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                        if (!(exception is COMException))
                        {
                            MessageBox.Show(exception.Message);
                        }
                        else if ((exception as COMException).ErrorCode != -2147219200)
                        {
                            MessageBox.Show(exception.Message);
                        }
                        else
                        {
                            MessageBox.Show("无法添加具有未知空间参考的数据");
                        }
                    }
                }
            }
            catch (Exception exception3)
            {
            }
        }