CityMaker炫酷标签效果创建

CityMaker炫酷标签效果创建

2017/5/17 17:12:51

 圈内人都知道伟景行的City Maker模型效果无人能敌,同样的给主席汇报的2次触摸屏的DMS也是牛逼的不行,但是用者都知道这东西没有创建接口,不能用在我们平时的脚本制作和展示上,那么今天我给大家提供一段代码,会的直接用起来,不会的找身边的码农,帮助你写个小插件,也让你的汇报瞬间高大上起来。

CityMaker炫酷标签效果创建



       开始,


1、下载CityMaker的SDK安装包,安装,之后找到安装目录下的  C:\Program Files (x86)\CityMaker 7\CityMaker SDK\Samples\CSharp\beginner\Authorizationz这个示例,拷贝出来,vs打开工程,之后可以在NetAuthorization.cs类中写死收到的lic授权文件地址  licenseServer.SetHost(AppDomain.CurrentDomain.BaseDirectory + "20170504.lic", 8588, "");


2、示例主页面有个menu,添加一个“加载FDB”和一个“保存CEP”2个功能。


3、从任意的示例中找到加载FDB的函数拷贝过来到加载FDB事件里,没错就是任意的,基本示例都是加载FDB的,所以几乎每个里面都有这个。

CityMaker炫酷标签效果创建



在这里加一段遍历FDB中点对象的代码。代码如下:


  //遍历fdb中的点,并创建tablelabel


               IFdeCursor cursor = fc.Search(null, true);                      //遍历整个fc


               IRowBuffer row = null;                                          


               string aimgroup = fc.Name;


               System.Guid group = axRenderControl1.ProjectTree.FindItem(aimgroup);


               if (group.ToString() != "00000000-0000-0000-0000-000000000000")


                   axRenderControl1.ProjectTree.DeleteItem(group);//存在就删除,重新创建。


               group = axRenderControl1.ProjectTree.CreateGroup(aimgroup, axRenderControl1.ProjectTree.RootID);


               //读取每一条记录并创建


               while ((row = cursor.NextRow()) != null)


               {


                   int nPos = row.FieldIndex("Geometry");


                   if (nPos != -1 && !row.IsNull(nPos))


                   {


                       IGeometry mp = row.GetValue(nPos) as IGeometry;


                       IPoint p = mp as IPoint;


                       string imgpath = AppDomain.CurrentDomain.BaseDirectory +fc.Name+".png";//背景图片


                       int namePos = row.FieldIndex("名称");


                       if (namePos != -1 && !row.IsNull(namePos))


                       {


                          string  name = row.GetValue(namePos).ToString();


                          LoadTableLabel(p,name, group, imgpath,name);//图片在此函数中设置


                       }


                     


                   }


               }


里面用到的LoadTableLabel函数如下:


 private void LoadTableLabel(IPoint postion, string id, System.Guid gid, string imgPath,string posName)


       {


           ITableLabel dynamicTableLabel = axRenderControl1.ObjectManager.CreateTableLabel(5, 2, gid);


           dynamicTableLabel.VisibleMask = gviViewportMask.gviViewNone;


           double posZ = axRenderControl1.Terrain.GetElevation(postion.X, postion.Y, gviGetElevationType.gviGetElevationFromDatabase);


           dynamicTableLabel.Position.SetCoords(postion.X, postion.Y, posZ, 0, 0);


           dynamicTableLabel.Position.SpatialCRS = new CRSFactory().CreateWGS84();


           dynamicTableLabel.MaxVisibleDistance = 100;


           dynamicTableLabel.MinVisibleDistance = 0;


           dynamicTableLabel.SetColumnWidth(0, 100); //左右列的长度


           dynamicTableLabel.SetColumnWidth(1, 50); //左右列的长度



           dynamicTableLabel.Name = id;



           dynamicTableLabel.TitleTextAttribute.BackgroundColor = 0x00000000;


           dynamicTableLabel.TitleTextAttribute.TextColor = 0xFF00FFFF;


           dynamicTableLabel.TitleBackgroundColor = 0x00000000;




           dynamicTableLabel.BorderColor = 0x00000000;


           dynamicTableLabel.TitleText = "";// "给水设备编号:" + id;


           dynamicTableLabel.SetRecord(0, 0, "    " + posName);


          // dynamicTableLabel.SetRecord(0, 1, " ");


           //dynamicTableLabel.SetRecord(1, 0, "  水压(MPA):");


           //dynamicTableLabel.SetRecord(1, 1, " 1.2");



           dynamicTableLabel.BackgroundImageName = imgPath;



           dynamicTableLabel.TableBackgroundColor = 0x00000000;




           // 第一列文本样式


           TextAttribute headerTextAttribute = new TextAttribute();


           headerTextAttribute.TextColor = ARGBToUint(100, 127, 60, 0);


           headerTextAttribute.OutlineColor = 0xffff10ff;



           headerTextAttribute.Font = "细黑";


           headerTextAttribute.Bold = true;


           headerTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineLeft;


           dynamicTableLabel.SetColumnTextAttribute(0, headerTextAttribute);



           // 第二列文本样式


           TextAttribute contentTextAttribute = new TextAttribute();


           contentTextAttribute.TextColor = 0xffff10ff;


           contentTextAttribute.OutlineColor = ARGBToUint(100, 127, 60, 64);


           contentTextAttribute.TextSize = 12;


           contentTextAttribute.Font = "黑体";


           contentTextAttribute.Bold = false;


           contentTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineLeft;


           dynamicTableLabel.SetColumnTextAttribute(1, contentTextAttribute);



           // 标题文本样式


           TextAttribute capitalTextAttribute = new TextAttribute();


           capitalTextAttribute.TextColor = 0xffffffff;


           capitalTextAttribute.OutlineColor = 4279834905;


           capitalTextAttribute.BackgroundColor = 0xFF0000FF;


           capitalTextAttribute.Font = "华文新魏";


           capitalTextAttribute.TextSize = 14;


           capitalTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineCenter;


           capitalTextAttribute.Bold = true;


           dynamicTableLabel.TitleTextAttribute = null;



           dynamicTableLabel.VisibleMask = gviViewportMask.gviViewAllNormalView;



       }


自己创建个点图层的fdb或者点shp导入一个FDB中,用这个代码试试吧。

CityMaker炫酷标签效果创建



信息来源:互联网
  • 关于我们
  • 产品与解决方案
  • 案例分享
  • 戎光资讯
  • 联系我们
Copyright©2013-2021 南京戎光软件科技有限公司,All Rights Reserved. 苏ICP备14019124号-1