本文共 1934 字,大约阅读时间需要 6 分钟。
参考网上的文章,并做了一些补充。原文链接:
首先使用接口装载.style文件,注意.style文件需要用到ESRI.ArcGIS.Framework.StyleGalleryClass类,而非ServerStyleGalleryClass类,这个类是用来读取.serverstyle文件的。也就是说,对于加载不同的文件,建立的对象不同。
说明:.style是desktop支持的格式,.serverstyle是engine支持的格式。加载.style文件,需要新建ESRI.ArcGIS.Framework.StyleGalleryClass对象,加载.serverstyle文件,需要新建ServerStyleGalleryClass对象
-
- IStyleGallery styleGalley = new ESRI.ArcGIS.Framework.StyleGalleryClass();
- IStyleGalleryStorage styleGalleryStorage = styleGalley as IStyleGalleryStorage;
- int styleCount = styleGalleryStorage.FileCount;
-
- bool styleExit = false;
- for (int i = 0; i < styleCount; i++)
- {
- if (styleGalleryStorage.get_File(i) == this.pathBox.Text)
- styleExit = true;
- }
- if (styleExit == false)
- styleGalleryStorage.AddFile(Path);
加载Sytle文件中某个指定的Symbol(以Marker为例):
-
- IStyleGalleryItem styleGalleryItem;
- IEnumStyleGalleryItem enumStyleGalleryItem = null;
-
- string markerSymbolName = "TestMarker1";
-
-
-
- enumStyleGalleryItem = styleGalley.get_Items("Marker Symbols", styleset, "");
- enumStyleGalleryItem.Reset();
- styleGalleryItem = enumStyleGalleryItem.Next();
- while (styleGalleryItem != null)
- {
- if (styleGalleryItem.Name == markerSymbolName)
- {
- IMarkerSymbol symbol = (IMarkerSymbol)styleGalleryItem.Item;
- break;
- }
- styleGalleryItem = enumStyleGalleryItem.Next();
- }
- System.Runtime.InteropServices.Marshal.ReleaseComObject(enumStyleGalleryItem);
附图:StyleManager,看其中左边树状菜单,第一级节点(ESRI.style),即为StyleSet,对应get_Items函数的第二个参数,第二级节点(例如Reference System等)即为ClassName,对应第一个参数,右侧的列表中,可以看到每一个元素的Category,对应第三个参数
![](http://hi.csdn.net/attachment/201101/28/0_129617593823D8.gif)
转载地址:http://lpaxb.baihongyu.com/