mapx+vb实战摘要(三)

ppp80上个月去天津(2004)做这个项目,加班加点忙乎过了十一,现在项目终于完成了第一阶段,可以闲下来总结一下了。
   在做这个项目之前我只是自学了一个月的supermap,不过感觉gis这些东西都是大同小异,没什莫可怕;关键比较郁闷的是本来根本就是做.net,现在却要用vb实在太。。。算了,赶鸭子上架,不会也得会呀!

    其实本人对这个实在只能称得上一知半解,学的和用的一样多,不过还是给自己和别人留下点东西吧,也许会有帮助呢:)(共五篇)

6制作专题图
  Map1.DataSets.Item(DsName).Themes.Add ThemeType, FieldList, "trafficflupiebar"
  注意:如果是柱状图和饼图等可以是多个字段的,FieldList就是数组名;否则就是字段名。
              如果你觉得制作的专题图不够大,可自己控制专题图的大小
              Map1.DataSets.Item(DsName).Themes("trafficflubar").Properties.Size = 1‘图形的高度,默认值为 0.25 英寸
              Map1.DataSets.Item(DsName).Themes("trafficflubar").Properties.BarWidth = 1‘每个柱体的宽度,默认值为 0.25 英寸
             你可以改变专题图的图例,比如制作等级符号的专题图,默认的是#号,你可以改变成你喜欢的样式
    Dim oStyle As style
    Set oStyle = New style
    oStyle.SymbolFont.Size = 35
    oStyle.SymbolCharacter = 35
    oStyle.SymbolFont.Name = "Map Symbols"
   oStyle.SymbolFontColor = &HFF00FF
Map1.DataSets.Item(DsName).Themes("trafficfluGradSymbol").Properties.SymbolStyle = oStyle
Set oStyle = Nothing


 7自定义专题图图例
      Dim LegTexts As New MapXLib.LegendTexts
  Dim tLegend As MapXLib.Legend
Set tLegend = Map1.DataSets(DsName).Themes("trafficflubar").Legend
  tLegend.Title = "交通流量"
  tLegend.Left = Map1.MapScreenWidth - tLegend.Width
    tLegend.Top = Map1.MapScreenHeight - tLegend.Height
 
  tLegend.BodyTextStyle.TextFont.Size = 8
  Set LegTexts = tLegend.LegendTexts
  tLegend.Visible = True
    LegTexts(1).Text = "小货"
    LegTexts(2).Text = "中货"
    LegTexts(3).Text = "大货"



8 邦定标注字段,自定义标注样式
sqlstr 是数据库取的数据集,showfield是要显示的字段名称

  Sub showdatalable(sqlstr As String, showfield As String)
'--------------------------显示标注
Dim CnShowData As New ADODB.Connection
Dim Cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
On Error Resume Next
CnShowData.CursorLocation = adUseClient
CnShowData.Open ConStr
Set Cmd.ActiveConnection = CnShowData
Cmd.CommandText = sqlstr

rs.Open Cmd, , adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
     Map1.AutoRedraw = False
     rs.MoveFirst
     
 Dim lyr As MapXLib.Layer
    Dim ftr As MapXLib.Feature
    Dim obj As MapXLib.Feature
    Dim FId As Long
    Dim rvs As RowValues
    Dim ds As MapXLib.Dataset
    Dim oStyle As style
    Dim zi As Single
 Do
    FId = 0
    If Map1.DataSets.Count > 0 Then
      Set lyr = Map1.Layers.Item(JDlyrName)
     
        Set ds = Map1.DataSets.Item(JDlyrName)
            For Each obj In lyr.AllFeatures
             Set rvs = ds.RowValues(obj)
              If Trim(rvs.Item("编号").Value) = Trim(Str(rs!orderno)) Then
              FId = obj.FeatureID
              Exit For
              End If
            Next
      If FId <> 0 Then
        lyr.Selection.SelectByID FId, miSelectionNew '交调点对应编号
        If lyr.Selection.Count > 0 Then
       
        Set oStyle = New style
        oStyle.TextFont.Size = 12
        oStyle.TextFont.Bold = True
        oStyle.SymbolFontColor = vbWhite
        oStyle.TextFontBackColor = vbBlue
        oStyle.TextFontOpaque = True

       ‘标注的样式为蓝底白字
        Map1.Annotations.AddText(rs(showfield), lyr.Selection(1).CenterX, lyr.Selection(1).CenterY, miPositionTL).Graphic.style = oStyle
        
         End If
      End If
    Else
     MsgBox "请先添加数据集!"
     Exit Sub
    End If
    
    Set ds = Nothing
    Set rvs = Nothing
    rs.MoveNext
 Loop While Not rs.EOF
  Map1.AutoRedraw = True
  Else
   MsgBox "无法显示数据,请检查数据是否为空?"
  End If
  rs.Close
  Set rs = Nothing
 CnShowData.Close
 Set CnShowData = Nothing
End Sub


9 删除专题图
  a,隐藏专题图
   ds.Themes("trafficflupiebar").Visible = False
  b,彻底删除
   专题图是与数据集有关的,所以要先指出数据集
    Dim ds As MapXLib.Dataset
    For Each ds In Map1.DataSets
    ds.Themes.RemoveAll
    Next

10全层显示
   Set fMainForm.Map1.NumericCoordSys = fMainForm.Map1.DisplayCoordSys
   
    If LayerCombo.Text = "所有图层" Then
        Set fMainForm.Map1.Bounds = fMainForm.Map1.Layers.Bounds
    Else
        Dim LayerName As String
        LayerName = LayerCombo.Text
        Set fMainForm.Map1.Bounds = fMainForm.Map1.Layers(LayerName).Bounds
    End If

 11改变地图比例,中心点
   fMainForm.Map1.ZoomTo  ViewZoom, ViewX, ViewY‘ViewZoom地图比例;ViewX, ViewY是中心点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值