MapX使用数据库数据添加专题图(系列之三)

MapX使用数据库数据添加专题图(系列之三)

关键字MapX Delphi 专题图

作者:杨雨田 blue_bat@126.com

 

本文描述了在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.

 

杨雨田 blue_bat@126.com

二零零四年八月二日

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
QT是一个跨平台的C++形用户界面应用程序开发框架,非常适合用于开发GUI界面应用程序。而MapX则是QT中的一个地控件,它提供了丰富的地相关功能,包括地的显示、标记、测量、搜索等。 想要学习和使用QT中的MapX教程,可以按照以下步骤进行: 1. 首先,确保你已经安装了QT开发环境。可以从官方网站上下载并安装QT的最新版本。 2. 在QT的官方网站上,可以找到MapX的官方文档和教程。根据你的需求和兴趣,选择适合你的教程进行学习。 3. 在MapX教程中,你可以学习如何在QT中使用MapX控件,并了解其基本的属性和方法。例如,你可以学习如何在界面上显示地,如何添加标记点,如何获取地上的点击事件等等。 4. 在学习过程中,可以通过实践和编写简单的示例代码来巩固所学的知识。通过编写小项目,可以更好地理解和应用MapX的功能。 5. 在教程中,还可以学习到MapX的高级功能,如地的缩放、平移,地的搜索和定位,地的路径规划等等。 6. 在学习过程中,如果遇到问题或者需要进一步的帮助,可以参考MapX的官方文档、官方论坛或者通过网络搜索来获取解答。 总结来说,学习和使用QT中的MapX教程需要具备一定的C++语言基础和QT开发环境的安装配置。通过系统地学习和实践,可以掌握MapX的基本使用方法,并能够根据需求开发出功能丰富的地应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

blue_bat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值