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); }
public static void ConvertLabels2Anno(IMap imap_0, IGeoFeatureLayer igeoFeatureLayer_0, string string_0, double double_0) { int i; IAnnotateLayerProperties igeoFeatureLayer0; IElementCollection elementCollection; IElementCollection elementCollection1; IElementCollection elementCollection2; IElement element; int num; IActiveView imap0 = imap_0 as IActiveView; int j = 0; int count = 0; IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass = new AnnotateLayerPropertiesCollection(); IAnnotateLayerPropertiesCollection annotationProperties = igeoFeatureLayer_0.AnnotationProperties; for (i = 0; i < annotationProperties.Count; i++) { annotationProperties.QueryItem(i, out igeoFeatureLayer0, out elementCollection, out elementCollection1); if (igeoFeatureLayer0 != null) { annotateLayerPropertiesCollectionClass.Add( (igeoFeatureLayer0 as IClone).Clone() as IAnnotateLayerProperties); } } igeoFeatureLayer0 = null; IOverposterProperties overposterProperties = (imap_0 as IMapOverposter).OverposterProperties; IGraphicsLayer double0 = (imap_0.BasicGraphicsLayer as ICompositeGraphicsLayer).AddLayer(string_0, igeoFeatureLayer_0); (double0 as IGraphicsLayerScale).ReferenceScale = double_0; double0.Activate(imap0.ScreenDisplay); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out igeoFeatureLayer0, out elementCollection, out elementCollection1); if (igeoFeatureLayer0 != null) { igeoFeatureLayer0.FeatureLayer = igeoFeatureLayer_0; igeoFeatureLayer0.GraphicsContainer = double0 as IGraphicsContainer; igeoFeatureLayer0.AddUnplacedToGraphicsContainer = false; igeoFeatureLayer0.CreateUnplacedElements = true; igeoFeatureLayer0.DisplayAnnotation = true; igeoFeatureLayer0.FeatureLinked = false; igeoFeatureLayer0.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures; igeoFeatureLayer0.UseOutput = true; ((igeoFeatureLayer0 as ILabelEngineLayerProperties2).OverposterLayerProperties as IOverposterLayerProperties2).TagUnplaced = true; } } annotateLayerPropertiesCollectionClass.Sort(); IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapProperties() { AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass }; ITrackCancel cancelTrackerClass = new CancelTracker(); (imap_0.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annotateMapPropertiesClass, imap_0, cancelTrackerClass); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out igeoFeatureLayer0, out elementCollection, out elementCollection2); if (igeoFeatureLayer0 != null) { count = count + elementCollection2.Count; if (elementCollection2.Count > 0) { IOverflowGraphicsContainer overflowGraphicsContainer = double0 as IOverflowGraphicsContainer; for (j = 0; j < elementCollection2.Count; j++) { elementCollection2.QueryItem(j, out element, out num); overflowGraphicsContainer.AddOverflowElement(element); } } igeoFeatureLayer0.FeatureLayer = null; } } igeoFeatureLayer_0.DisplayAnnotation = false; imap0.ContentsChanged(); imap0.Refresh(); }