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類後面還有介紹)

如上圖所示的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個類,如下圖所示:

每一個類都包含有若干個IStyleGaleryItem,如下圖所示

上圖中,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(種類、類別)這個屬性。如下圖所示:

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);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章