AE二次开发,右键图层,设置图层要素标注
2013-10-15 13:52
295 查看
#region 成员变量 private string m_zttName = string.Empty; private string m_sqlCondition = ""; private ITool m_tool; private ITOCControl2 tocControl; private IMapControl3 mapControl; private IToolbarMenu toolMenuMap; private IToolbarMenu toolMenuLayer; private MakeFeature _makeFeature = new MakeFeature(); #endregion
//右键菜单Load方法中写 tocControl = (ITOCControl2)toc.Object; mapControl = (IMapControl3)mcView.Object; //创建菜单 toolMenuMap = new ToolbarMenuClass(); toolMenuLayer = new ToolbarMenuClass(); toolMenuLayer.AddItem(_makeFeature, -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText); toolMenuLayer.SetHook(mapControl);
private void toc_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { try { #region toolbarmenu esriTOCControlItem tocItem = esriTOCControlItem.esriTOCControlItemNone; IBasicMap basicMap = null; ; ILayer layer = null; object legendGroup = null; object index = null; //获取鼠标点击信息 toc.HitTest(e.x, e.y, ref tocItem, ref basicMap, ref layer, ref legendGroup, ref index); if (e.button == 2) { //设置选中图层标注状态 IGeoFeatureLayer curLayer = layer as IGeoFeatureLayer; _makeFeature.SetChecked = curLayer.DisplayAnnotation; if (tocItem == esriTOCControlItem.esriTOCControlItemMap) { toc.SelectItem(basicMap, null); } else { toc.SelectItem(layer, null); } //设置CustomProperty为layer (用于自定义的Layer命令) mcView.CustomProperty = layer; //弹出右键菜单 if (tocItem == esriTOCControlItem.esriTOCControlItemMap) { toolMenuMap.PopupMenu(e.x, e.y, toc.hWnd); } else { toolMenuLayer.PopupMenu(e.x, e.y, toc.hWnd); } } #endregion } catch (Exception ex) { FrmErrHandle.ErrorLogShow(ex); } }
#region 图层要素标注 /// <summary> /// 图层要素标注 /// </summary> public class MakeFeature : BaseCommand { private IMapControl3 mapControl; private ITextSymbol textSymbolTC = null;//图层标注 /// <summary> /// 设置图层选择状态 /// </summary> public bool SetChecked { get { return base.m_checked; } set { base.m_checked = value; } } //构造函数 public MakeFeature() { base.m_caption = "标注要素"; base.m_checked = false; //标注字体初始化 this.textSymbolTC = new TextSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 0; color.Green = 0; color.Blue = 0; color.Transparency = 255; this.textSymbolTC.Color = color; this.textSymbolTC.Size = 9; this.textSymbolTC.Font.Bold = false; this.textSymbolTC.Font.Name = "宋体"; } //重写BaseCommand基类的虚拟方法OnClick() public override void OnClick() { ILayer layer = (ILayer)mapControl.CustomProperty; IFeatureLayer featureLayer = layer as IFeatureLayer; DataRow[] drs = PublicConstant.TC_DRS; foreach (DataRow dr in drs) { string labelField = dr["labelField"] == DBNull.Value ? "" : dr["labelField"].ToString(); string tcTitle = dr["title"] == DBNull.Value ? "" : dr["title"].ToString(); if (tcTitle == featureLayer.Name) { string[] fieldShow = { labelField }; IGeoFeatureLayer layerShow = featureLayer as IGeoFeatureLayer; if (base.m_checked == false && layerShow.DisplayAnnotation == false) { base.m_checked = true; this.DrawLabel(fieldShow, layerShow, textSymbolTC, mapControl); } else if (base.m_checked == true && layerShow.DisplayAnnotation == true) { base.m_checked = false; layerShow.DisplayAnnotation = false; } this.mapControl.Refresh(); } } } //重写BaseCommand基类的抽象方法OnCreate(object hook) public override void OnCreate(object hook) { mapControl = (IMapControl3)hook; } /// <summary> /// 设置图层标签 /// </summary> /// <param name="FieldShow">标注字段</param> /// <param name="layerShow">标注图层</param> /// <param name="textSymbol">标注字体</param> /// <param name="MapShow">AxMapControl</param> /// <returns></returns> private void DrawLabel(string[] FieldShow, IGeoFeatureLayer layerShow, ITextSymbol textSymbol, ESRI.ArcGIS.Controls.IMapControl3 MapShow) { if (FieldShow.Length == 0) return; layerShow.DisplayAnnotation = true; string strFieldString = "[" + FieldShow[0] + "]"; if (FieldShow[0] == "TBBH") { strFieldString = "CInt(" + strFieldString + ")"; } for (int i = 1; i < FieldShow.Length; i++) { strFieldString = strFieldString + "+[" + FieldShow[i] + "]"; } IAnnotateLayerPropertiesCollection pannprocol = layerShow.AnnotationProperties; ILabelEngineLayerProperties plabelengin; IAnnotateLayerProperties pannPro; IBasicOverposterLayerProperties pbasicoverposterlayerprops = new BasicOverposterLayerPropertiesClass(); pbasicoverposterlayerprops.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape; IElementCollection eleTmp = new ElementCollectionClass(); for (int j = 0; j < pannprocol.Count; j++) { pannprocol.QueryItem(j, out pannPro, out eleTmp, out eleTmp); plabelengin = (ILabelEngineLayerProperties)pannPro; plabelengin.Expression = strFieldString; plabelengin.Symbol = textSymbol; plabelengin.BasicOverposterLayerProperties = pbasicoverposterlayerprops; } ITrackCancel pcon = new CancelTrackerClass(); pcon.Continue(); layerShow.Draw(esriDrawPhase.esriDPAnnotation, MapShow.ActiveView.ScreenDisplay, pcon); } } #endregion
相关文章推荐
- terraExplorer 6.6 for javascript 获取地理要素上的坐标值,通过图层设置标注(作为上一篇的补充)
- arcgis engine开发中图层标注设置
- Aragis Engine 二次开发中,如何根据符号库文件 设置图层样式
- ILayerEffects接口用来设置一个要素图层的透明度,对比度,对比度
- ArcEngine二次开发_03(鼠标在图层中选择要素进行高亮显示)
- ArcgisEngine+C#开发中,对一个图层进行过滤,并只显示符合条件的要素
- ArcView GIS 应用与开发技术(3)-地理要素的显示和标注
- Maplex中,设置面要素标注锚点位置
- TerraExplorer 6.6 for JavaScript 通过图层获取地理要素,获取图层属性信息,矢量标注等通用方法
- ArcGlobe三维开发之四——设置globe图层的缓存属性)
- AE开发图层右键打开属性表
- AE开发之计算要素图层
- ArcGIS API for Silverlight之Web Mapping开发:根据图层属性查询、定位、高亮显示并显示标注(2)
- 设计师给了px单位的标注,Android开发到底要设置多少dip、dp、sp?
- AE开发:如何设置图层符号
- ArcGlobe三维开发之五——获取并设置Globe图层的叠加次序
- AE二次开发-判断栅格图层是否存在属性表,获取栅格字段的唯一值
- MapObject学习笔记-第三讲 图层标注、图层控制和电子地图常用工具开发(添加经过修正与VS2005兼容的Legend控件下载)
- AE二次开发-获取图层的属性表
- AE二次开发中,过滤后的图层,实现缩放至图层效果