Exemple #1
0
        public void LabelQueryInfo(string name, string strContent, IPoint pt, IMap pMap, bool isRemoveLast)
        {
            //获取并激活Graphic标注图层
            if (pt == null)
            {
                return;
            }
            IActiveView             pActiveView             = pMap as IActiveView;
            ICompositeGraphicsLayer pCompositeGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer;

            //WeatherLabel标记组,通过ArcMap的Layers Properties的Annotation group可以看到
            IGraphicsLayer pGraphicsLayer = pCompositeGraphicsLayer.FindLayer("WeatherLabel");

            pMap.ActiveGraphicsLayer = pGraphicsLayer as ILayer;
            pGraphicsLayer.Activate(pActiveView.ScreenDisplay);
            IGraphicsContainer pGraphicsContainer = pGraphicsLayer as IGraphicsContainer;//转换到图形容器接口

            IElementCollection pElementCollection = new ElementCollectionClass();

            AddBalloonCalloutLabel(name, strContent, pt, pElementCollection);//我们需要一个新的私有函数来实现设置标签元素背景,BalloonCallout对象

            //添加标注
            if (isRemoveLast == true)
            {
                pGraphicsContainer.DeleteAllElements();
            }

            pGraphicsContainer.AddElements(pElementCollection, 1000);

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds);
        }
        private void _UpdateButtons()
        {
            if (cbxFromLayer.SelectedValue is IFeatureLayer &&
                cbxToLayer.SelectedValue is IFeatureLayer &&
                cbxFromField.SelectedValue is string &&
                cbxToField.SelectedValue is string)
            {
                btnAdd.Enabled = true;
            }
            else
            {
                btnAdd.Enabled = false;
            }

            bool          enableRemove = false;
            IFeatureLayer fromLayer    = cbxFromLayer.SelectedValue as IFeatureLayer;

            if (fromLayer != null)
            {
                ICompositeGraphicsLayer basicGraphicsLayer = (ICompositeGraphicsLayer)_document.FocusMap.BasicGraphicsLayer;
                string          graphicsLayerName          = _GetGraphicsLayerName(fromLayer.FeatureClass);
                ICompositeLayer compositeLayer             = (ICompositeLayer)basicGraphicsLayer;
                for (int i = 0; i < compositeLayer.Count; i++)
                {
                    if (compositeLayer.get_Layer(i).Name == graphicsLayerName)
                    {
                        enableRemove = true;
                        break;
                    }
                }
            }
            btnRemove.Enabled = enableRemove;
        }
Exemple #3
0
        void revLabels_RemoveLabelsEvent()
        {
            IMap                    pMap                    = axMapControl1.Map;
            IActiveView             pActiveView             = pMap as IActiveView;
            ICompositeGraphicsLayer pCompositeGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer;
            IGraphicsLayer          pGraphicsLayer          = pCompositeGraphicsLayer.FindLayer("WeatherLabel");

            IGraphicsContainer pGraphicsContainer = pGraphicsLayer as IGraphicsContainer;

            pGraphicsContainer.DeleteAllElements();
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds);
        }
        private void _RemoveZingers(IFeatureLayer fromLayer)
        {
            ICompositeGraphicsLayer basicGraphicsLayer = (ICompositeGraphicsLayer)_document.FocusMap.BasicGraphicsLayer;
            string          graphicsLayerName          = _GetGraphicsLayerName(fromLayer.FeatureClass);
            ICompositeLayer compositeLayer             = (ICompositeLayer)basicGraphicsLayer;

            for (int i = 0; i < compositeLayer.Count; i++)
            {
                if (compositeLayer.get_Layer(i).Name == graphicsLayerName)
                {
                    basicGraphicsLayer.DeleteLayer(graphicsLayerName);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 获取地图中指定名称的存储元素的Graphics图层,找不到则返回Null
        /// (通过graphicslayer as IGraphicsContainer来增删改查元素,参考:https://www.cnblogs.com/bobird/articles/3169592.html)
        /// </summary>
        /// <param name="map">地图</param>
        /// <param name="layerName">图层名</param>
        /// <returns></returns>
        public static IGraphicsLayer GetGraphicsLayer(this IMap map, string layerName)
        {
            ICompositeGraphicsLayer compositeGrapLayer = map.BasicGraphicsLayer as ICompositeGraphicsLayer;
            ICompositeLayer         compositeLayer     = compositeGrapLayer as ICompositeLayer;

            for (int i = 0; i < compositeLayer.Count; i++)
            {
                if (compositeLayer.get_Layer(i).Name.Equals(layerName))
                {
                    return(compositeLayer.get_Layer(i) as IGraphicsLayer);
                }
            }
            return(null);
        }
Exemple #6
0
 public IGraphicsLayer FindGraphicsLayer(IBasicMap pBasicMap, string sLayerName)
 {
     try
     {
         if (pBasicMap == null)
         {
             return(null);
         }
         if (pBasicMap.LayerCount <= 0)
         {
             return(null);
         }
         if (string.IsNullOrEmpty(sLayerName))
         {
             return(null);
         }
         ICompositeGraphicsLayer basicGraphicsLayer = null;
         basicGraphicsLayer = pBasicMap.BasicGraphicsLayer as ICompositeGraphicsLayer;
         IGraphicsLayer layer2 = null;
         try
         {
             layer2 = basicGraphicsLayer.FindLayer(sLayerName);
         }
         catch (Exception)
         {
             return(pBasicMap.BasicGraphicsLayer);
         }
         if (layer2 == null)
         {
             return(null);
         }
         return(layer2);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "FindGraphicsLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
Exemple #7
0
        private IGraphicsLayer FindOrCreateGraphicsSubLayer(string SubLayerName)
        {
            IMap                    Map1 = axMapControl.Map;
            IGraphicsLayer          gl   = Map1.BasicGraphicsLayer;
            ICompositeGraphicsLayer cgl  = gl as ICompositeGraphicsLayer;
            IGraphicsLayer          sublayer;

            try
            {
                sublayer = cgl.FindLayer(SubLayerName);
                if (sublayer == null)
                {
                    sublayer = cgl.AddLayer(SubLayerName, null);
                }
            }
            catch (Exception ex)
            {
                sublayer = cgl.AddLayer(SubLayerName, null);
            }

            return(sublayer);
        }
        private void _AddZingers(IFeatureLayer fromLayer, string fromFieldName, IFeatureLayer toLayer, string toFieldName)
        {
            ICompositeGraphicsLayer basicGraphicsLayer = (ICompositeGraphicsLayer)_document.FocusMap.BasicGraphicsLayer;
            string graphicsLayerName = _GetGraphicsLayerName(fromLayer.FeatureClass);

            // Create lookup for "to" points
            Type toValueType;
            Dictionary <object, List <IPoint> > toPoints = _GetToPointLookup(toLayer, toFieldName, out toValueType);

            // Add zingers
            if (toPoints.Count > 0)
            {
                IGraphicsContainer graphics = (IGraphicsContainer)basicGraphicsLayer.AddLayer(graphicsLayerName, fromLayer);
                IFeatureCursor     cursor   = null;
                try
                {
                    int fromField = fromLayer.FeatureClass.FindField(fromFieldName);
                    cursor = fromLayer.FeatureClass.Search(null, false);
                    IFeature fromFeature = cursor.NextFeature();
                    while (fromFeature != null)
                    {
                        try
                        {
                            IPoint fromPoint = _GetFeaturePoint(fromFeature);
                            if (fromPoint != null)
                            {
                                object fromValue = fromFeature.get_Value(fromField);
                                if (fromValue != DBNull.Value)
                                {
                                    try
                                    {
                                        fromValue = Convert.ChangeType(fromValue, toValueType);
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Could not convert values in \"from\" field to type of value in \"to\" field.", ex);
                                    }

                                    if (toPoints.ContainsKey(fromValue))
                                    {
                                        foreach (IPoint toPoint in toPoints[fromValue])
                                        {
                                            IPolyline line = new PolylineClass();
                                            line.FromPoint = fromPoint;
                                            line.ToPoint   = toPoint;
                                            IElement element = new LineElementClass();
                                            element.Geometry = line;
                                            ((ILineElement)element).Symbol = _GetZingerSymbol();

                                            graphics.AddElement(element, 0);
                                        }
                                    }
                                }
                            }
                        }
                        finally
                        {
//                            UrbanDelineationExtension.ReleaseComObject(fromFeature);
                        }
                        fromFeature = cursor.NextFeature();
                    }
                }
                finally
                {
//                    UrbanDelineationExtension.ReleaseComObject(cursor);
                }
            }
        }
Exemple #9
0
        public void Do()
        {
            IFeatureCursorBuffer2 buffer = new FeatureCursorBufferClass
            {
                BufferSpatialReference    = this.m_pFocusMap.SpatialReference,
                DataFrameSpatialReference = this.m_pFocusMap.SpatialReference,
                SourceSpatialReference    = this.m_pFocusMap.SpatialReference,
                TargetSpatialReference    = this.m_pFocusMap.SpatialReference
            };

            if (this.m_SourceType == 0)
            {
                int  num;
                bool flag;
                buffer.GraphicsLayer2(this.m_pFocusMap.ActiveGraphicsLayer as IGraphicsLayer, this.bUseSelect, out num,
                                      out flag);
            }
            else
            {
                IFeatureCursor cursor = null;
                if (this.bUseSelect)
                {
                    if ((this.m_pFeatureLayer as IFeatureSelection).SelectionSet.Count == 0)
                    {
                        cursor = this.m_pFeatureLayer.Search(null, false);
                    }
                    else
                    {
                        ICursor cursor2;
                        (this.m_pFeatureLayer as IFeatureSelection).SelectionSet.Search(null, false, out cursor2);
                        cursor = cursor2 as IFeatureCursor;
                    }
                }
                else
                {
                    cursor = this.m_pFeatureLayer.Search(null, false);
                }
                buffer.FeatureCursor = cursor;
            }
            buffer.set_Units(this.m_pFocusMap.MapUnits, this.m_Units);
            if (this.m_BufferType == 0)
            {
                buffer.ValueDistance = this.m_dblRadius;
            }
            else if (this.m_BufferType == 1)
            {
                buffer.FieldDistance = this.m_FieldName;
            }
            else
            {
                buffer.set_RingDistance(this.m_Count, this.m_dblStep);
            }
            if (this.m_PolygonType == 0)
            {
                buffer.PolygonBufferType = esriBufferType.esriBufferAll;
            }
            else if (this.m_PolygonType == 1)
            {
                buffer.PolygonBufferType = esriBufferType.esriBufferOutside;
            }
            else if (this.m_PolygonType == 2)
            {
                buffer.PolygonBufferType = esriBufferType.esriBufferInside;
            }
            else
            {
                buffer.PolygonBufferType = esriBufferType.esriBufferOutsideIncludeInside;
            }
            buffer.Dissolve = this.bDissolve;
            try
            {
                if (this.m_OutputType == 0)
                {
                    (buffer as IBufferProcessingParameter).SaveAsGraphics = true;
                    ICompositeGraphicsLayer basicGraphicsLayer =
                        this.m_pFocusMap.BasicGraphicsLayer as ICompositeGraphicsLayer;
                    buffer.BufferToGraphics(basicGraphicsLayer);
                }
                else if (this.m_OutputType == 1)
                {
                    (buffer as IBufferProcessingParameter).InputHasPolygons = false;
                    (buffer as IBufferProcessingParameter).SimplifyShapes   = true;
                    buffer.Buffer((this.m_pOutFC as IDataset).FullName as IFeatureClassName);
                }
                else
                {
                    IObjectClassDescription description = new FeatureClassDescriptionClass();
                    IFields          requiredFields     = description.RequiredFields;
                    int              index       = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);
                    IFieldEdit       edit        = requiredFields.get_Field(index) as IFieldEdit;
                    IGeometryDefEdit geometryDef = edit.GeometryDef as IGeometryDefEdit;
                    geometryDef.SpatialReference_2 = this.m_pFocusMap.SpatialReference;
                    geometryDef.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
                    IFeatureClass o = this.m_pOutFeatureWorksapce.CreateFeatureClass(this.m_FeatClassName,
                                                                                     requiredFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                    IFeatureClassName fullName = (o as IDataset).FullName as IFeatureClassName;
                    Marshal.ReleaseComObject(o);
                    o = null;
                    GC.Collect();
                    buffer.Buffer(fullName);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }