生活随笔
收集整理的這篇文章主要介紹了
MapXtreme2008中操作矢量符号和定制符号
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??本文部分說明內容摘自網絡文章,經過本人在MapXtreme2008中編寫相關的演示例子,詳細說明如何操作MapXtreme2008提供的矢量符號和定制符號。
? MapXtreme 在其安裝過程中自動安裝 10 種 MapInfo 特定的 TrueType 字體。這些字體為用戶提供了字形符號選擇,范圍涉及天氣、房地產、交通等。字形編號為 Unicode 字符值,由于這些編號位于第一個 Unicode 字符代碼塊范圍內,因此,與 ASCII 字符集兼容。
??MapXtreme包含三種點樣式:BitmapPointStyle (位圖點樣式)、FontPointStyle(字體點樣式)和SimpleVectorPointStyle(簡單矢量點樣式)。
????????
?簡單矢量點樣式
?????????此樣式包含使用MapInfo 3.0 兼容專有字體用于繪制點的樣式屬性(MapInfow.fnt)。SimpleVectorPointStyle 屬性包括了要為點繪制的實際符號的顏色、點大小和形狀碼。標準集包括符號31 至67。以下是符號與形狀碼的對應圖,31是空。在比較簡單的場合使用此樣式已經足夠,但是很多場合都不簡單。
結構:
public?SimpleVectorPointStyle(
???short?code,
???Color?color,
???double?pointSize
);
code??????? 上面圖片中對應的形狀碼
color????????填充符號的顏色,上面圖片中為黑色
pointSize????符號大小
?字體點樣式
??????????? 使用FontPointStyle 類可以顯示TrueType字體集,允許的最大點大小為240 點。這給了我們很大的自由空間,其中的MapInfo Symbols字體和上面的字體是相同的,不過MapInfo Symbols是TrueType字符集。MapXtreme自帶的字體:
??????????? Map Symbols
??????????? MapInfo Arrows
??????????? MapInfo Cartographic
??????????? MapInfo Miscellaneous
??????????? MapInfo Oil&Gas
??????????? MapInfo Real Estate
??????????? MapInfo Shields
????????????MapInfo Symbols
????????????MapInfo Transportation
????????????MapInfo Weather
可以使用一些相關軟件查看這些字體的具體內容,比如 字體試衣間 、微軟自帶的 字符映射表 。
public?FontPointStyle(
???short?code,
???Font?font,
???short?angle,
???Color?color,
???double?pointSize
);
code??????? 字體映射的編碼
font??????? 字體的樣式。很關鍵,字體樣式的強大全靠它了
angle??????? 字體旋轉的角度
color??????? 字體填充的顏色
pointSize??? 字體的大小,12就差不多了
位圖點樣式
????????????定制的位圖符號位于 C:\Program Files\Common Files\MapInfo\MapXtreme\6.x\CustSymb。每個圖像的文件擴展名都是 .BMP。可以用編程方式通過 MapInfo.Styles 命名空間中的 BitmapPointStyleRepository 集合類訪問這些符號。可以創建自己的位圖圖像并將其添加到 CustSymb 目錄。盡管事實上對創建的圖像沒有大小限制,不過 MapXtreme 顯示圖像的能力取決于可用的內存。圖像不一定必須是方形,而且還可以具有最多24 位顏色深度。要確保圖像以其高度和寬度顯示,則必須在各自圖像的 BitmapPointStyle 對象中將Boolean "NativeSize" 屬性設置為 true。
????????????位圖點樣式應該是最可能被用到的樣式。它通過自定義的圖片來標識地圖上的圖元。位圖點樣式具有ShowWhiteBackground 屬性;如果設置為false,則位圖中的白像素為透明。默認情況下,ShowWhiteBackground 被設置為false。
public?BitmapPointStyle(
???string?strName,
???BitmapStyles?style,
???Color?color,
???double?pointSize
);
strName??????? 圖片的相對路徑加上名稱。一般圖片的根路徑是? X:\Program Files\Common Files\MapInfo\MapXtreme\6.x\CustSymb??? X為安裝盤。同時圖片也放在那里。
style??????????? 圖片的樣式。
- None: 按默認的狀態顯示。并且白色部分將透明。
- ShowWhiteBackground: 顯示白色部分。
- ApplyColor: 在標識中的透明部分將用第三個參數的顏色填充.
- NativeSize: 按標識的真實大小和象素顯示,第四項參數將無效.
color??????? 白色部分的填充色
pointSize??? 標識大小
下面分別介紹這幾種圖標如何在Web中添加展示,下面列出相關代碼。
Code
????????protected?void?Page_Load(object?sender,?System.EventArgs?e)
????????{
????????????if?(StateManager.IsManualState())
????????????{
????????????????MapInfo.Mapping.Map?myMap?=?GetMapObj();
????????????????if?(Session.IsNewSession)
????????????????{
????????????????????MapInfo.WebControls.MapControlModel?controlModel?=?MapControlModel.SetDefaultModelInSession();
????????????????????//instanciate?AppStateManager?class
????????????????????AppStateManager?myStateManager?=?new?AppStateManager();
????????????????????//put?current?map?alias?to?state?manager?dictionary
????????????????????myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey]?=?this.MapControl1.MapAlias;
????????????????????//put?state?manager?to?session
????????????????????StateManager.PutStateManagerInSession(myStateManager);
????????????????????#region?測試代碼
????????????????????if?(myMap?!=?null)
????????????????????{
????????????????????????if?(myMap.Layers["TempLayerAlias"]?!=?null)
????????????????????????{
????????????????????????????myMap.Layers.Remove("TempLayerAlias");
????????????????????????}
????????????????????}
????????????????????//?Need?to?clean?up?"dirty"?temp?table?left?by?other?customer?requests.
????????????????????MapInfo.Engine.Session.Current.Catalog.CloseTable("TempTableAlias");
????????????????????//?Need?to?clear?the?DefautlSelection.
????????????????????MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();
????????????????????//?Creat?a?temp?table?and?AddPintPointCommand?will?add?features?into?it.
????????????????????MapInfo.Data.TableInfoMemTable?ti?=?new?MapInfo.Data.TableInfoMemTable("TempTableAlias");
????????????????????//?Make?the?table?mappable
????????????????????ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
????????????????????ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
????????????????????MapInfo.Data.Table?table?=?MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
????????????????????//?Create?a?new?FeatureLayer?based?on?the?temp?table,?so?we?can?see?the?temp?table?on?the?map.
????????????????????myMap.Layers.Insert(0,?new?FeatureLayer(table,?"templayer",?"TempLayerAlias"));
????????????????????IMapLayer?lyr?=?myMap.Layers["TempLayerAlias"];
????????????????????if?(lyr?==?null)?return;
????????????????????FeatureLayer?fLyr?=?lyr?as?FeatureLayer;
????????????????????MapInfo.Geometry.DPoint?point?=?new?DPoint(100,?20);
????????????????????MapInfo.Geometry.Point?geoPoint?=?new?MapInfo.Geometry.Point(myMap.GetDisplayCoordSys(),?point);
????????????????????
????????????????????//?創建內置MapInfo符號圖標
????????????????????SimpleVectorPointStyle?vStyle?=?new?SimpleVectorPointStyle();
????????????????????vStyle.Code?=?67;
????????????????????vStyle.Color?=?Color.Red;
????????????????????vStyle.PointSize?=?Convert.ToInt16(48);
????????????????????vStyle.Attributes?=?StyleAttributes.PointAttributes.BaseAll;
????????????????????vStyle.SetApplyAll();
????????????????????//?Create?a?Feature?which?contains?a?Point?geometry?and?insert?it?into?temp?table.
????????????????????Feature?feature?=?new?Feature(geoPoint,?vStyle);
????????????????????MapInfo.Data.Key?key?=?fLyr.Table.InsertFeature(feature);
????????????????????//創建自定義位圖樣式
????????????????????//位圖相對于位置C:\Program?Files\Common?Files\MapInfo\MapXtreme\6.8.0\CustSymb
????????????????????string?fileName?=?@"AMBU1-32.BMP";
????????????????????BitmapPointStyle?bStyle?=?new?BitmapPointStyle(fileName);
????????????????????bStyle.PointSize?=?Convert.ToInt16(24);
????????????????????bStyle.NativeSize?=?true;
????????????????????bStyle.Attributes?=?StyleAttributes.PointAttributes.BaseAll;
????????????????????bStyle.SetApplyAll();
????????????????????point?=?new?DPoint(140,?55);
????????????????????geoPoint?=?new?MapInfo.Geometry.Point(myMap.GetDisplayCoordSys(),?point);
????????????????????feature?=?new?Feature(geoPoint,?bStyle);
????????????????????key?=?fLyr.Table.InsertFeature(feature);
????????????????????//添加字體圖樣式
????????????????????//FontPointStyle?fStyle?=?new?FontPointStyle();
????????????????????//fStyle.Color?=?Color.Red;
????????????????????//fStyle.Font.Name?=?"NewCom?Vehicle";
????????????????????//fStyle.PointSize?=?Convert.ToInt16(24);
????????????????????//fStyle.Attributes?=?StyleAttributes.PointAttributes.BaseAll;
????????????????????//fStyle.SetApplyAll();
????????????????????FontPointStyle?fStyle?=?new?FontPointStyle();
????????????????????fStyle.Code?=?66;
????????????????????fStyle.PointSize?=?48;
????????????????????fStyle.Color?=?System.Drawing.Color.Red;
????????????????????fStyle.Font.Name?=?"Uniwill";
????????????????????fStyle.Font.FontWeight?=?MapInfo.Styles.FontWeight.Bold;
????????????????????fStyle.Angle?=?900;
????????????????????point?=?new?DPoint(180,?85);
????????????????????geoPoint?=?new?MapInfo.Geometry.Point(myMap.GetDisplayCoordSys(),?point);
????????????????????feature?=?new?Feature(geoPoint,?fStyle);
????????????????????key?=?fLyr.Table.InsertFeature(feature);
????????????????????#endregion
????????????????}
????????????????//?Now?Restore?State
????????????????StateManager.GetStateManagerFromSession().RestoreState();
????????????}
????????}
其他部分的相關代碼如下:
Code
????????//?At?the?time?of?unloading?the?page,?save?the?state
????????protected?void?Page_UnLoad(object?sender,?System.EventArgs?e)
????????{
????????????if?(StateManager.IsManualState())
????????????{
????????????????StateManager.GetStateManagerFromSession().SaveState();
????????????}
????????}
????????private?MapInfo.Mapping.Map?GetMapObj()
????????{
????????????MapInfo.Mapping.Map?myMap?=?MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
????????????if?(myMap?==?null)
????????????{
????????????????myMap?=?MapInfo.Engine.Session.Current.MapFactory[0];
????????????}
????????????return?myMap;
????????}
以上得到的界面效果如下圖所示,分別有3個對應的圖標與之對應。
更多專業前端知識,請上
【猿2048】www.mk2048.com
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的MapXtreme2008中操作矢量符号和定制符号的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。