IStyleGallery 和IstyleGalleryItem以及IStyleGalleryStorage接口理解

IStyleGalleryStorage

Provides access to members that manage the files used in the Style Gallery.

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description   IStyleGalleryStorage is used to manage the styles that can then be edited using the IStyleGallery interface. Use the CanUpdate property to determine if the TargetFilei is editable. Use AddFile and RemoveFile to move styles in and out of the gallery.

IStyleGalleryStorage 用来管理可以使用IStyleGallery编辑的Styles文件,我们可以将IStyleGalleryStorage看做 一个存放Style文件的一个大的容器,每一个style文件由IStyleGalleryItems组成,通过IStyleGalleryStorage 我们可以添加、删除、更新对应的style文件。ESRI为我们提供了很多的默认的style文件,这些style文件的默认的存放路径C:\Program Files\ArcGIS\Styles下。 该路径下 有两种类型的文件,一种是文件扩展名称为.ServerStyle的文件,一种是文件扩展名称为style的文件。ServerStyle文件用于AE的开发,Style文件是ArcMap可以使用的样式文件。ESRI自带的工具里面有一种工具可以将style类型的文件转换为ServerStyle类型的文件,然后提供给ArcGIS Engine使用。

下面主要说明一下IStyleGalleryStorage对象的几个主要成员

AddFile;

语法:Public Void AddFile(string path);

Path:表示文件在本地的存放位置,比如:C:\Program Files\ArcGIS\Styles\ Business.style或者C:\Program Files\ArcGIS\Styles\ Business.ServerStyle文件

该函数的意思是将一个指定位置的style文件添加到这个指定的容器里面,然后就可以通过IStyleGallery来对这些容器中的IStyleGalleryItem对象进行调用、处理等基本操作。

2)DefaultStylePath: 是一个只读类型的属性,她返回的是ESRI中style文件默认的存放路径,这个跟ArcGIS软件的安装路径有关。返回值是一个String类型的变量,她的默认值可以是C:\Program Files\ArcGIS\Styles 这个是我本地计算机的DefualtStylePath的返回,因为我的ArcGIS软件安装在C盘。

3)File属性  The file at the given index.  返回指定索引值的style文件的全路径名称、或者文件名称。

4)FileCount :The number of files in the Style Gallery  返回 IStyleGalleryStorage中所包含的style文件的数量。

5)RemoveFile(string path) 返回指定路径的style文件。

6)TargetFile   The target output file for adding, updating and removing items. 这个是个可读、可写的属性。这个属性用来设置要编辑的目标文件,这个需要给定一个style文件的路径,如果本地计算机在指定的位置存在这个一个文件,那么系统就修改这个一个文件,如果本地计算机不存在这个一个文件,那么系统就将会在给定的位置创建一个新的style文件。当我们需要为IStyleGallery添加IStyleGalleryItem示例的时候,就需要指定这个属性,用来设置要编辑的IstyleGalleryStoragy中的某一个相对应的style文件。比如,在创建一个新的IstyleGalleryStoragy实例的时候,指定TargetFile属性,这个Style文件中就将默认的包含两个style文件,

一个是C:\Users\Administrator\AppData\Roaming\ESRI\ArcMap\Administrator.style文件,

一个是C:\Program Files\ArcGIS\Styles\ESRI.style文件

每一个文件都是由IStyleGalleryItem项组成的。并且每一个.style文件或.ServerStyle文件中的IStyleGalleryItem中的Item属性都有一个Class类型,然后根据不同的Class类型,添加后划分到对应的Class类型中,如下图所示:(关于Class类后面还有介绍)

 IStyleGallery <wbr>和IstyleGalleryItem以及IStyleGalleryStorage接口理解

如上图所示的ESRI.style文件中,有很多类型的IstyleGalleryItem项,比如:Reference Systems/Maplex Labels/Shadows/Area Patches/Line Patches等等。每一个类都有若干数量的IStyleGalleryItem组成,比如上图中的Color Ramps项就是由右边的IStyleGalleryItem项组成的。

2:IStyleGallery

>Provides access to members modify the Style Gallery. 提供重新定义StyleGallery的方法的访问权限。

>Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

IStyleGallery is used to access styles, add new items with AddItem, remove items with RemoveItem, make updates with UpdateItem and save your changes with SaveStyle. Styles provide storage for your colors, map elements, symbols, and properties of symbols.

我的理解:

IStyleGallery可以看成是ISyleGalleryItem的容器,我们在上一节中已经提到我们可以把IStyelGalleryStorage看做一个.style和.ServerStyle文件的容器,并管理这些style文件,而这些style文件内是由ISyleGalleryItem项组成的。但是IStyleGaleryStorage却没有提供管理这些Style文件内的IStyleGalleryItem的借口,所以不能管理这些IstyleGalleryItem,这个时候就出现了IStyleGallery借口,由他来管理IStyleGalleryStorage容器内所有的IstyleGalleryItem项,比如,添加、删除、更新等操作 。

下面接下来讲解一下他的几个属性以及他的方法:

ClassCount  只读属性,Number of classes in the Style Gallery。StyleGallery是有IStyleGalleryItem项组成的,这些IStyleGlleryItem分别属于不同的类,并且IStyleGalery默认的将IStyleGalleryItem分为12个类,如下图所示:

 IStyleGallery <wbr>和IstyleGalleryItem以及IStyleGalleryStorage接口理解

每一个类都包含有若干个IStyleGaleryItem,如下图所示

 IStyleGallery <wbr>和IstyleGalleryItem以及IStyleGalleryStorage接口理解

上图中,ESRI.Style文件包含22个类,当前我们选中North Arrows指北针类,然后右边就显示出来North Arrow类中所包含的IStyleGalleryItem项,可以看出有很多个这样的Item。

ClassCount属性也就是返回当前的StyleGallery中所包含的类的数目。在IStyleGallery中,不管我们包含多少个IStyle文件,IStyleGallery中包含的类的种类的数量都是一定的,即22个。也就是说,每一个Style文件中包含的类的数量以及类的名称都是一样的,我们也可以这样理解,当我们创建一个.style文件的时候,系统就自动在style文件中创建22个类,尽管这个时候,每个类中的IStyleGalleryItem都为空。

Class属性, 通过调用.get_Class(int index) 来返回指定索引值的IStyleGaleryClass对象,请看下面一段代码

int StyleGalleryClassCouont = styleGellery.ClassCount;

            IStyleGalleryClass styleGaleryClass = null;

            for (int i = 0; i < StyleGalleryClassCouont; i++)

            {

                styleGaleryClass = styleGellery.get_Class(i);

                string name = styleGaleryClass.Name;

            }

关于IStyleGalleryClass 我们可以在以后讲解,这里只需要知道通过这个属性可以返回一个IStyleGaleryItem类的一个示例。

AddItem 语法如下所示:

Public void AddItem(IstyleGalleryItem item);

描述:Adds an item to the target style file.

CateGories属性

描述:The categories within the given class. 返回指定名称的Class中所包含的IStyleGallery所属的类别。

每一个IStyleGalleryClass类都包含有多个IstyleGalleryItem项,为了大体上区别这些IstyleGalleryItem项,我们又给这些IstyleGalleryItem项归类,也就是说,每一个IstyleGalleryItem都有这个Cagegories(种类、类别)这个属性。如下图所示:

 IStyleGallery <wbr>和IstyleGalleryItem以及IStyleGalleryStorage接口理解

5)Clear  方法

语法:  Public void Clear();

Discription:Removes all styles from the Style Gallery.

Items  返回满足指定参数的IstyleGalleryItems

Discription: The style items from the specified style file, in the specified class and category. The style set and category may be blank to return all items.

语法:IEnumStyleGalleryItem  get_Items(string className,string styleSet,string category)

className:表示,IStyleGalleryItem所属的类

StyleSet:表示IstyleGalleryItem所存在的style文件

Category:IstyleGalleryItem 所属的类别。

参考代码:

            IStyleGallery styleGellery = new StyleGalleryClass();

            IStyleGalleryStorage styleGalleryStorage = styleGellery as IStyleGalleryStorage;

            string tt = styleGalleryStorage.DefaultStylePath;

            string iStyleFilePath = tt + "Civic.style";

            styleGalleryStorage.AddFile(iStyleFilePath);

            string ClassName = "Color Ramps";

            string StyleCategory = "Default Ramps";

            IEnumStyleGalleryItem enumStyleGalleryItem = styleGellery.get_Items(ClassName, iStyleFilePath, StyleCategory);

            IStyleGalleryItem StyleGalleryItemEnum = null;

            ArrayList al = new ArrayList();

            while ((StyleGalleryItemEnum = enumStyleGalleryItem.Next()) != null)

            {

                al.Add(StyleGalleryItemEnum.Name);

            }

            int itemCount = al.Count;

RemoveItem

Discription: Removes an item from the target style file.

这个方法挺简单,直接调用就可以了。

SaveStyle

Discription: Saves the specified style to a file. If class is specified, only items in that class will be saved.

这里面的有一个参数:FileName不是很理解

UpdateItem

Discription: Updates an existing item in target style file.(可以看出,这里需要指定IStyleGalery的TargetFile属性,用来更新的操作也是更新这个属性指定的文件中的Item成员)

下面讲解下:IstyleGalleryItem

Defination: Provides access to members that define items in the Style Gallery.

Product Availability:Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description:Symbols and map elements are stored in the Style Gallery. Each symbol or map element has a unique ID that can be read from the item within the style gallery. A Name and Category are also properties of the items within the style gallery. These two fields, along with the Item itself, can be updated and changed as necessary.

主要方法:

Category  :The category of the item.

ID: Id for the item in the Style Gallery.

Item: The symbol or map element to be stored in the Style Gallery item.

Name :The name of the item in the Style Gallery.

理解:IStyleGalleryItem项是IStyleGallery中最小的组成单元,即使是最小的单元,但是他也有她自己的属性,比如:Category、ID、Name等属性。我们也需要将IStyleGalleyItem理解成一个小的容器,因为每一个IStyleGalleryItem中都包含着一个属性Item属性,symbol或者地图都包含在这样一个IStyleGalleryItem项中。

参考代码:

IStyleGallery styleGallery = new StyleGallery();

IEnumStyleGalleryItem styleGalleryItem = (IEnumStyleGalleryItem)styleGallery;//从这一行可以看出一个IStyleGallery实例可以直接的转换为一个IEnumStyleGaleryItem对象

styleGalleryItem.Reset();

string itemName = styleGalleryItem.Next().Name;

MessageBox.Show(itemName);

转自:http://blog.sina.com.cn/s/blog_7a07046a0100sr82.html

原文地址:https://www.cnblogs.com/qiernonstop/p/3061523.html