關鍵字:MapX Delphi 專題圖
作者:楊雨田 [email protected]
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
本文描述了在MapX中添加專題圖的方法,其中MapX中關於添加專題圖的過程語法描述如下(介於英語水平太高,能認識的英文字母大概還有二十多個,實在不願意打開金山詞霸給大家進行高質量的翻譯,哈哈):
OBJECT.Add ([Type], [Field], [Name], [ComputeTheme])
OBJECT Represents a Themes object.
Type Specifies the type of thematic map to create. This takes a ThemeTypeConstants value. This is an optional parameter, and if not specified (or specified as miThemeAuto), MapX will attempt to choose a good default based on the number of fields passed in as well as what other theme types are already being displayed. If MapX cannot choose a default theme type, an error is generated.
Field(s) Specifies the field or fields to thematically map. A field can be specified by name, index, or by a Field object. If you are creating a theme using multiple variables (such as a bar chart or pie chart), pass in a Fields collection or an array of field names, indexes, or Field objects. This is an optional parameter, and if not specified, MapX uses the first numeric field of the Dataset.
Name Specifies the name of the thematic map. This is a String parameter. This is an optional parameter, and if not specified, MapX generates a name such as StatesBySales.
ComputeTheme Boolean. The default value is True which will calculate the theme from the table data. If the value is set to False an invisible theme object will be created with 10 ranges for IndividualValue themes and 5 ranges for Ranged themes. You can then manually set the minimum and maximum values to define the theme with Theme.DataMin and Theme.DataMax. For ranged themes you can manually set the theme ranges or calculate equal size ranges determined by the minimum (Theme.DataMin) and maximum (Theme.DataMax) values.
關於專題圖的風格共有以下幾種:
miThemeRanged = 0
miThemeBarChart = 1
miThemePieChart = 2
miThemeGradSymbol = 3
miThemeDotDensity = 4
miThemeIndividualValue = 5
miThemeAuto = 6
miThemeNone = 9
具體都是什麼樣,請自己寫代碼看看,哈哈
下面是我寫的部分代碼:
unit Main;
interface
uses
Windows, Messages,{略去一部分} SysUtils, Variants, Classes;
type
TfrmMain = class(TForm)
mapMain: TMap; {地圖控件}
private
{ Private declarations }
ThemesList : TStringList; {用來保存多個專題圖的名稱列表}
public
{ Public declarations }
procedure ToAddThemes(style : integer; TheName : string); {添加專題圖}
procedure ToDeleteThemes; {刪除專題圖}
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
{略去其他功能代碼}
{
添加專題圖,參數style表示專題圖風格,TheName表示圖例標題
}
procedure TfrmMain.ToAddThemes(style : integer; TheName : string);
function DefaultName : string;{用來生成一唯一的名稱}
begin
{我用的方法是取一個當前時間,兩次調用本函數的時間間隔應該不會少於0.5秒,
所以這個方法在這個項目中可以取得唯一的名稱}
Result := 'YYT' + FormatDateTime('YYYYMMDDHHNNSSzzz',now);
end;
var
flds : array of string; {字段列表}
oBLayer : BindLayer; {綁定圖層}
ds : Dataset; {MapX數據集}
i : integer; {循環變量}
thm : theme; {MapX專題圖}
str : string; {用於保存字符串}
begin
{aqThemes可以是一個ADOQuery或者ADOTable,我使用的是ADOQuery。
在這個ADOQuery中前四個字段分別是:
ID(唯一的數字或者字符串,一般為編號),
NAME(字符串,要素的標簽),
X(浮點數,要素的經度或者橫坐標),
Y(浮點數,要素的緯度或者縱坐標)。
後面的其它字段都是數字類型,用來表示相關的數據。
◎請參考我的文章《從數據庫繪制MapX圖層(二)》,
url是http://dev.csdn.net/article/31/31719.shtm
}
if not aqThemes.Active then
begin
dmData.GiveMsg('系統基礎表沒有打開!');
exit;
end;
try
{取一個唯一的名字,}
str := DefaultName;
{設置綁定圖層的屬性}
oBLayer := coBindLayer.Create;
progress.StepPlus(2);
oBLayer.LayerName := str;
oBLayer.LayerType := miBindLayerTypeXY;
oBLayer.RefColumn1 := 'X';
oBLayer.RefColumn2 := 'Y';
{下面的調用和我在《從數據庫繪制MapX圖層(二)》使用的方法一樣,
請參考我的那篇文章,url是http://dev.csdn.net/article/31/31719.shtm}
ds := mapMain.Datasets.Add(12,
aqThemes.Recordset,
str,
'ID',
EmptyParam,
oBLayer,
EmptyParam,
EmptyParam);
{組織專題圖現實的數據字段,存儲在字符串數組中}
SetLength(flds,aqThemes.Fields.Count - 3);
for i:=3 to aqThemes.Fields.Count - 1 do
begin
flds[i - 3] := aqThemes.Fields.Fields[i].FieldName;
end;
{實際添加專題圖的過程}
thm := ds.Themes.Add(style,flds,DefaultName,EmptyParam);
{設置專題圖圖例標題}
thm.Legend.Title := TheName;
{記錄新添加的專題圖名稱}
ThemesList.Add(str);
{btnDeleteThemes是一個在本窗口上的按鈕,用來刪除專題圖,
添加專題圖後就將他顯示出來,如果刪除了全部專題圖就將他隱藏}
btnDeleteThemes.Visible := true;
except
GiveMsg('創建專題圖失敗!');{自定義過程,給出出錯提示}
end;
end;
{
刪除專題圖,我采用的方法是刪除所有專題圖
}
procedure TfrmMain.ToDeleteThemes;
var
i : integer; {循環變量}
begin
for i:=0 to ThemesList.Count-1 do{循環所有添加了的專題圖}
begin
{刪除數據集}
mapMain.Datasets.Remove(ThemesList.Strings[i]);
{刪除專題圖}
mapMain.Layers.Remove(ThemesList.Strings[i]);
{如果只想刪除某一個專題圖,不用循環就行了}
end;
{此時已經沒有專題圖了,將刪除專題圖按鈕隱藏}
btnDeleteThemes.Visible := false;
{清除專題圖名稱列表}
ThemesList.Clear;
end;
//...
end.