首页 百科知识 使用图元集

使用图元集

时间:2022-06-19 百科知识 版权反馈
【摘要】:二、使用图元集Features集合类似于Selection集合,因为两者都是Feature对象的集合。在Selections集合中自动高亮显示选中的图元,而在Features集合中不会突出显示图元。1.取得图层中的图元在使用Features集合前必须先创建集合。表6-12 取得Features集合的Layers集合以下程序通过半径查找操作建立一个Features集合,并选取查找返回的Features集合。Feature对象方法使用户可以创建和操作独立图元对象。把图元附加到地图时地图的坐标系与图元相关联。

二、使用图元集

Features集合类似于Selection集合,因为两者都是Feature对象的集合。但是,Features集合与Selection集合各有一组不同的方法和属性集,而且两个集合类型的行为也不同。在Selections集合中自动高亮显示选中的图元,而在Features集合中不会突出显示图元。

1.取得图层中的图元

在使用Features集合前必须先创建集合。可以用Layer对象方法创建Feature对象的集合。表6-12列出了取得Features集合的Layers集合的方法。

表6-12 取得Features集合的Layers集合

以下程序通过半径查找操作建立一个Features集合,并选取查找返回的Features集合。

Dim fs as Features

Dim pt As New MapXLib.Point

pt.Set-96.731,39.728

set fs=map1.Layers(1).SearchWithinDistance(pt,_

5,miUnitMile,miSearchTypePartiallyWithin)

map1.Layers(1).Selection.Replace fs

2.搜索类型常数

搜索类型常数及其功能描述见表6-13所示。

表6-13 搜索类型常数

以下代码是工具使用的事件,它为用户单击点处的图元创建集合。

Private Sub Map1_ToolUsed(ByVal ToolNum As Integer,ByVal X1 As Double,ByVal Y1 As Double,ByVal X2 As Double,ByVal Y2 As Double,ByVal Distance As Double,ByVal Shift As Boolean,ByVal Ctrl As Boolean,EnableDefault As Boolean)

  Dim ftr As Feature'creates a Feature object

  Dim fs As Features'creates a collection of features

  Dim pt As New Point'creates a new point

  'the new point created has coordinate values set when the user clicks on a feature

  pt.Set X1,Y1

  'If the tool used is the custom info tool then create a collection of features from the

  'States layer and print the State Name feature into a message box.

  If ToolNum=InfoTool Then

  'create the collecton of features at the point the user clicked

    Set fs=Map1.Layers("USA").SearchAtPoint(pt)

    'print the State Name feature into a message box.

    For Each ftr In fs

      MsgBox ftr.Name

    Next

  End If

3.操纵Features集合

表6-14列出了在集合中添加、删除、复制图元对象来操作Features集合的方法。

表6-14 操纵Features集合

4.Feature对象

Features集合由Feature对象集合组成。Feature对象对应于地图上的图元,例如符号、线或区域。Feature对象方法使用户可以创建和操作独立图元对象。在创建独立图元对象后,必须将该图元对象附加到地图上后才能引用对象的所有方法和属性。把图元附加到地图时地图的坐标系与图元相关联。

以下是Visual Basic示例显示如何创建独立的Text图元,然后修改其标题。

Dim f As New Feature

Dim fNew As Feature

'Add a new text object to layer 1

f.Attach Map1

f.Type=miFeatureTypeText

f.Point.Set Map1.CenterX,Map1.CenterY

f.Caption="This is a text object"

Set fNew=Map1.Layers(1).AddFeature(f)

'Change the text caption

fNew.Caption="Changed Text"

fNew.Update

5.图元对象属性

表6-15定义了图元对象的属性。

表6-15 图元对象属性

img162

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

我要反馈