当前位置: 首页 > 编程日记 > 正文

[vb+mo] visual baisc 6.0 基于mapobjects 2.4 开发的数字化校园电子地图

程序的源代码下载地址:

https://docs.google.com/

请安装VB6.0企业版(不是企业版运行会报错,因为缺少相应的控件)和ESRI MO2.4

程序的质量一般,因为时间仓促,主要是毕业设计时间仓促.希望大家多多改进.有什么问题可以发邮件欢迎交流.

程序的主窗口代码:

'通用变量定义
Private lyrname As String
Private Const Searchtolpixels = 3
Public mark As Integer
Public fd As Boolean, sx As Boolean, my As Boolean, cX As String
Public lineMy As New MapObjects2.line
Public poly As New MapObjects2.Polygon
Public rect As New MapObjects2.Rectangle
Public cir As New MapObjects2.Ellipse
Public pt1 As New MapObjects2.Point
Public BufPoly As New MapObjects2.Polygon
Dim HasRec As Boolean
Dim recsParcel As MapObjects2.Recordset
Dim sym  As New Symbol
Dim SymBuf As New Symbol
Dim SymSel As New Symbol
Dim isLabelShow As Integer
Dim dr1 As DrawRect
Dim dd As String

' 面积计算
Private Sub AreaCal_Click()
    mark = 2
    Map1.MousePointer = moCross
End Sub

'输入查询地物名称
Private Sub Command1_Click()
    If Text1.Text = "" Then
        MsgBox "请输入要查询的地物!", vbOKOnly, "提示!"
   Else
       If HasRec = False Then
    End If
    '查询三个图层的名称并且显示
    For i = 0 To 2
        Set mylyr = Map1.Layers(i)
    Set recsParcel = mylyr.SearchExpression("名称  like " + "'" + "%" + Text1.Text + "%" + "'")

If i <> 3 Then
   
    End If

Next i
    Dim stats As MapObjects2.Statistics
    Set stats = recsParcel.CalculateStatistics("FeatureID")
    iParcel = stats.Count

If stats.Count < 1 Then
        MsgBox "没有找到"
   
    Else: Map1.FlashShape recsParcel.Fields("Shape").Value, 3
  If Not recsParcel.EOF Then
            form5.ListView1.ListItems.Clear
            For Each fld In recsParcel.Fields
                Set newItem = form5.ListView1.ListItems.Add
                newItem.Text = fld.Name
                newItem.SubItems(1) = fld.ValueAsString
              Next fld
                aString = recsParcel.Fields("名称").ValueAsString
                If aString = "运动场" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "3.jpg"
                     form5.Image1 = LoadPicture(dd)
                      form5.Show
                ElseIf aString = "图书馆" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "11.jpg"
                     form5.Image1 = LoadPicture(dd)
                      form5.Show
                ElseIf aString = "校行政楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "9.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "B1教学楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "8.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "A1教学楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "2.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "八一路" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "7.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "弘毅广场" Then
               
                    dd = App.Path + "\..\" + "图片" + "\" + "11.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "综合教学楼2" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "17.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "综合实验楼1" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "16.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf aString = "艺术楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "14.jpg"
                     form5.Image1 = LoadPicture(dd)
               form5.Show
                ElseIf Text1.Text = "" Then
               Else: dd = App.Path + "\..\" + "图片" + "\" + "13.jpg"
         form5.Image1 = LoadPicture(dd)
               form5.Show
           End If
               form5.Image1 = LoadPicture(dd)
               form5.Show
            End If

Map1.Refresh
    End If
    End If
End Sub

'显示属性窗口
Private Sub Command4_Click()
If Text1.Text = "" Then
        MsgBox "请输入要查询的地物!", vbOKOnly, "提示!"
Else
    If HasRec = False Then
    End If
    '查询三个图层的名称并且显示
    For i = 0 To 2
    Set mylyr = Map1.Layers(i)
 
    Set recsParcel = mylyr.SearchExpression("名称  = " + "'" + Text1.Text + "'")

If i <> 3 Then
    End If

Next i
    Dim stats As MapObjects2.Statistics
    Set stats = recsParcel.CalculateStatistics("FeatureID")
    iParcel = stats.Count

If stats.Count < 1 Then
        MsgBox "没有找到"
   
    Else: Map1.FlashShape recsParcel.Fields("Shape").Value, 3
  If Not recsParcel.EOF Then
            form5.ListView1.ListItems.Clear
            For Each fld In recsParcel.Fields
                'Set Recs = l.SearchByDistance(Loc, theTol, "")
                Set newItem = form5.ListView1.ListItems.Add
                newItem.Text = fld.Name
                newItem.SubItems(1) = fld.ValueAsString
              Next fld
                aString = recsParcel.Fields("名称").ValueAsString
                If aString = "运动场" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "3.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "图书馆" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "11.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "校行政楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "9.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "B1教学楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "8.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "A1教学楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "2.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "八一路" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "7.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "弘毅广场" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "11.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "综合教学楼2" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "17.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "综合实验楼1" Then
               
                    dd = App.Path + "\..\" + "图片" + "\" + "16.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "艺术楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "14.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
               Else: dd = App.Path + "\..\" + "图片" + "\" + "13.jpg"
                form5.Image1 = LoadPicture(dd)
                    form5.Show

End If
               form5.Image1 = LoadPicture(dd)
               form5.Show
            End If

Map1.Refresh
    End If
   End If
End Sub

' 清理缓冲图形
Private Sub command6_Click()
    Me.Map1.TrackingLayer.ClearEvents
    Option1.Value = False
    Option2.Value = False
    Option3.Value = False
    Option4.Value = False
    Option5.Value = False
End Sub

' 距离量算
Private Sub DistanceCal_Click()
    mark = 1
    Map1.MousePointer = moCross
End Sub

Sub AddLegend()
     ' 加载图例
    legend1.LoadLegend
    ' 获得活动图层的索引号
    legend1.Active(0) = True
    Dim Index As Long
    Index = legend1.getActiveLayer
    ' 如果索引号有效
    Exit Sub
End Sub

Private Sub Form_Load()
    Form1.Picture = LoadPicture()
    Call addlayers
    Call SetUpRenderers
    Call SetUpPointLabelRenderers
    Call SetUpLineLabelRenderers
    updateScale
    legend1.Active(0) = True
    legend1.setMapSource Map1
    legend1.LoadLegend True
    legend1.Visible = True
    '将图层名称添加到列表框里
    Dim mylyr As MapObjects2.MapLayer
    Map1.Refresh
    '详细定义符号
    Text3.Text = "100"
    Map1.TrackingLayer.SymbolCount = 4
    With Map1.TrackingLayer.Symbol(0)
        .SymbolType = moPointSymbol
        .Style = moTriangleMarker
        .Color = moRed
        .Size = 3
    End With
 
    With Map1.TrackingLayer.Symbol(1)
        .SymbolType = moLineSymbol
        .Color = moRed
        .Size = 3
    End With
 
    With Map1.TrackingLayer.Symbol(2)
        .SymbolType = moFillSymbol
        .Style = moGrayFill
        .Color = moRed
        .OutlineColor = moRed
    End With
 
    With Map1.TrackingLayer.Symbol(3)
        .SymbolType = moFillSymbol
        .Style = moGrayFill
        .Color = moBlue
        .OutlineColor = moBlue
    End With
End Sub

'添加数据方法
Sub addlayers()
    Dim DCONN As New MapObjects2.DataConnection
    DCONN.Database = App.Path + "\..\" + "数据" + "\"
    If Not DCONN.Connect Then
        MsgBox "没找到数据"
    End If
    '添加东区面
    Dim myMaplayer As New MapObjects2.MapLayer
    Set myMaplayer.GeoDataset = DCONN.FindGeoDataset("东区面")
    myMaplayer.Symbol.Color = moWhite
    Map1.Layers.Add myMaplayer
    AddLegend
    '添加东区线
    Set myMaplayer = New MapObjects2.MapLayer
    Set myMaplayer.GeoDataset = DCONN.FindGeoDataset("东区线")
    myMaplayer.Symbol.Color = moLightGray
    myMaplayer.Symbol.Style = moSolidLine
    myMaplayer.Symbol.Size = 2
    Map1.Layers.Add myMaplayer
    AddLegend
    '添加东区点
    Set myMaplayer = New MapObjects2.MapLayer
    Set myMaplayer.GeoDataset = DCONN.FindGeoDataset("东区点")
    myMaplayer.Symbol.Color = moTeal
    myMaplayer.Symbol.Style = moSolidLine
    myMaplayer.Symbol.Size = 3
    Map1.Layers.Add myMaplayer
    AddLegend
    'map2中添加底图
    Set yMaplayer = New MapObjects2.MapLayer
    Set yMaplayer.GeoDataset = DCONN.FindGeoDataset("东区面")
    yMaplayer.Symbol.Color = RGB(232, 241, 13)
    yMaplayer.Symbol.Style = mosolide
    Map2.Layers.Add yMaplayer
End Sub

Private Sub legend1_AfterSetLayerVisible(Index As Integer, isVisible As Boolean)
    Map1.Refresh
End Sub

Private Sub legend1_LayerDblClick(Index As Integer)
    Dim i As Integer
    i = legend1.getActiveLayer
    Dim str As String
    str = Map1.Layers.Item(i).Name
    If str = "东区点" Then
        Set Map1.Layers("东区点").Renderer = Nothing
        SetUpPointLabelRenderers
        CommonDialog1.ShowColor
        Map1.Layers("东区点").Symbol.Color = CommonDialog1.Color
        legend1.LoadLegend
    ElseIf str = "东区线" Then
        If MsgBox("修改颜色", vbYesNo) = vbNo Then
            Map1.Layers("东区线").Symbol.Color = moLightGray
            legend1.LoadLegend
        Else
            Set Map1.Layers("东区线").Renderer = Nothing
            SetUpLineLabelRenderers
            CommonDialog1.ShowColor
            Map1.Layers("东区线").Symbol.Color = CommonDialog1.Color
            legend1.LoadLegend
        End If
    ElseIf str = "东区面" Then
        If MsgBox("修改颜色", vbYesNo) = vbNo Then
            SetUpRenderers
            legend1.LoadLegend
        Else
            Set Map1.Layers("东区面").Renderer = Nothing
            CommonDialog1.ShowColor
            Map1.Layers("东区面").Symbol.Color = CommonDialog1.Color
            legend1.LoadLegend
        End If
    End If
    Map1.Refresh
End Sub

Private Sub legend1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i As Integer
    Dim str As String
    i = legend1.getActiveLayer
    'MsgBox i
    If i = -1 Then i = 2
   
    str = Map1.Layers(i).Name
    lyrname = str
  '  i = 0
End Sub

'标注部分
Private Sub Map1_AfterLayerDraw(ByVal Index As Integer, ByVal canceled As Boolean, ByVal hdc As stdole.OLE_HANDLE)
    If Index = 0 Then Map2.TrackingLayer.Refresh True
    Dim mylyr As MapLayer
    Dim myrcs As MapObjects2.Recordset
    Dim iCount As Integer
    Dim i As Integer
    iCount = Map1.Layers.Count
    HasRec = False
    If Text1.Text <> "" Then
        '模糊查询部分<三个图层一起查询>
        For i = 0 To iCount - 1
            Set mylyr = Map1.Layers(i)
            Set myrcs = mylyr.SearchExpression("名称 like " + "'" + "%" + Text1.Text + "%" + "'")
            Set g_symSelection = New MapObjects2.Symbol

With g_symSelection
                .SymbolType = Map1.Layers(i).Symbol.SymbolType
                .Color = moRed
                .Size = 5.2
            End With

If mylyr.shapeType = moShapeTypePolygon Then
                g_symSelection.Outline = False
            End If


            If Not myrcs.EOF Then
                Map1.DrawShape myrcs, g_symSelection
                HasRec = True
            End If
        Next i
    End If
    Map1.Refresh
End Sub

Private Sub Map1_BeforeLayerDraw(ByVal Index As Integer, ByVal hdc As stdole.OLE_HANDLE)

Map1.Refresh
    Map2.Refresh
End Sub


Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    '********************************距离统计******************************************
    If mark = 1 Then
        Dim line1 As MapObjects2.line   ' Line Object: A Line object represents a
            ' geometric shape that has two or more vertices.
            Set line1 = Map1.TrackLine  ' TrackLine Method: Rubber-bands a multi-point
            ' line on the Map and returns a Line object.
            Map1.TrackingLayer.Refresh True
            Me.StatusBar1.Panels(5).Text = "地图距离为: " + Format(line1.Length, "#.00") + " Meters"
            ' Panels属性功能:返回对Panel对象的(Panels)集合的引用     Length Property:
            ' Returns the length of a Line object in map units.
    End If
    '*********************************面积统计*****************************************
    If mark = 2 Then
            Dim poly1 As MapObjects2.Polygon
            Set poly1 = Map1.TrackPolygon
            Map1.TrackingLayer.Refresh True
            Me.StatusBar1.Panels(5).Text = "面积为: " + Format(poly1.Area, "#.00") + " Square Meters"
            ' Area Property: Returns the area of an object in square map units.
    End If
    '**********************************************************************************
    Dim r As MapObjects2.Rectangle
    If fd = True Then  '放大
        Map1.MousePointer = moZoomIn
        Set r = Map1.TrackRectangle
        Set Map1.Extent = r
        Map1.Refresh
        Map2.Refresh
        updateScale
    End If

If my = True Then
        Map1.Pan   '漫游
        Map1.MousePointer = moPan
    End If
   
    If sx = True Then  '缩小
       
        Map1.MousePointer = moZoomOut
        Dim Loc As New MapObjects2.Point
        Dim mapwidth As Double, mapheigth As Double
        Set Loc = Map1.ToMapPoint(X, Y)
        Set r = Map1.Extent
        mapwidth = Map1.Extent.Width
        mapheight = Map1.Extent.Height
        r.Right = Loc.X + mapwidth
        r.Left = Loc.X - mapwidth
        r.Top = Loc.Y + mapheight
        r.Bottom = Loc.Y - mapheight
        Set Map1.Extent = r
        Map1.Refresh
        Map2.Refresh
        updateScale
    End If
    '显示属性<分图层显示>
    If Toolbar1.Buttons(5).Value = 1 Then
        mark = 0
        Map1.MousePointer = moIdentify
        If lyrname <> "" Then
            Call identify(X, Y)
        Else
            MsgBox "请在图层显示框中单击地物所在的图层!", vbOKOnly, "提示!"
        End If
    End If
 
    '点缓冲
    If Option1.Value Then
        Dim pt As New MapObjects2.Point
        Dim eventPt As New MapObjects2.GeoEvent
        Dim buffPt As New MapObjects2.Polygon
        Dim buffEventPt As New MapObjects2.GeoEvent
   
        Set pt = Map1.ToMapPoint(X, Y)
        Set eventPt = Map1.TrackingLayer.AddEvent(pt, 0)
        Set buffPt = pt.Buffer(Text3.Text, Map1.FullExtent)

Set buffEventPt = Map1.TrackingLayer.AddEvent(buffPt, 3)
       
    '线缓冲
    ElseIf Option2.Value Then
        Dim line As New MapObjects2.line
        Dim eventLine As New MapObjects2.GeoEvent
        Dim buffLine As New MapObjects2.Polygon
        Dim buffEventLine As New MapObjects2.GeoEvent
   
        Set line = Map1.TrackLine
        Set eventLine = Map1.TrackingLayer.AddEvent(line, 1)
        Set buffLine = line.Buffer(Text3.Text, Map1.FullExtent)
        Set buffEventLine = Map1.TrackingLayer.AddEvent(buffLine, 3)


    '矩形缓冲
    ElseIf Option3.Value Then
        Dim rect As New MapObjects2.Rectangle
        Dim eventRect As New MapObjects2.GeoEvent
        Dim buffRect As New MapObjects2.Polygon
        Dim buffEventRect As New MapObjects2.GeoEvent
   
        Set rect = Map1.TrackRectangle
        Set eventRect = Map1.TrackingLayer.AddEvent(rect, 2)
        Set buffRect = rect.Buffer(Text3.Text, Map1.FullExtent)
        Set buffEventRect = Map1.TrackingLayer.AddEvent(buffRect, 3)

'多边形缓冲
    ElseIf Option4.Value Then
        Dim poly As New MapObjects2.Polygon
        Dim eventPoly As New MapObjects2.GeoEvent
        Dim buffPoly As New MapObjects2.Polygon
        Dim buffEventPoly As New MapObjects2.GeoEvent
   
        Set poly = Map1.TrackPolygon
        Set eventPoly = Map1.TrackingLayer.AddEvent(poly, 2)
        Set buffPoly = poly.Buffer(Text3.Text, Map1.FullExtent)
        Set buffEventPoly = Map1.TrackingLayer.AddEvent(buffPoly, 3)
 
    '椭圆缓冲

ElseIf Option5.Value Then
        Dim arect As New MapObjects2.Rectangle
        Dim elli As New MapObjects2.Ellipse
        Dim eventElli As New MapObjects2.GeoEvent
        Dim buffElli As New MapObjects2.Polygon
        Dim buffEventElli As New MapObjects2.GeoEvent
   
        Set arect = Map1.TrackRectangle
        elli.Top = arect.Top
        elli.Bottom = arect.Bottom
        elli.Left = arect.Left
        elli.Right = arect.Right
   
        Set eventElli = Map1.TrackingLayer.AddEvent(elli, 2)
        Set buffElli = elli.Buffer(Text3.Text, Map1.FullExtent)
        Set buffEventElli = Map1.TrackingLayer.AddEvent(buffElli, 3)
        'Else: MsgBox "请选择缓冲类型并且输入缓冲距离"
   
    End If
   
End Sub

Private Sub identify(X As Single, Y As Single) '******地物属性查询*******************
 
    Dim theTol As Double
    Dim Loc As New Point
   
    If lyrname = "" Then
        MsgBox "请选中要查询的图层"
    Else
        Set l = Map1.Layers(lyrname)
        Set Loc = Map1.ToMapPoint(X, Y)
        theTol = Map1.ToMapDistance(Searchtolpixels * Screen.TwipsPerPixelX)
   
        Set Recs = l.SearchByDistance(Loc, theTol, "")
 
        If Not Recs.EOF Then
            form5.ListView1.ListItems.Clear
            For Each fld In Recs.Fields
                'Set Recs = l.SearchByDistance(Loc, theTol, "")
                Set newItem = form5.ListView1.ListItems.Add
                   newItem.Text = fld.Name
                newItem.SubItems(1) = fld.ValueAsString
            Next fld
                aString = Recs.Fields("名称").ValueAsString
               
                If aString = "运动场" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "3.jpg"
                    form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "图书馆" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "11.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "校行政楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "9.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "B1教学楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "8.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "A1教学楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "2.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "八一路" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "7.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "弘毅广场" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "11.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "综合教学楼2" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "17.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "综合实验楼1" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "16.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
                ElseIf aString = "艺术楼" Then
                    dd = App.Path + "\..\" + "图片" + "\" + "14.jpg"
                     form5.Image1 = LoadPicture(dd)
                    form5.Show
               Else: dd = App.Path + "\..\" + "图片" + "\" + "13.jpg"
                form5.Image1 = LoadPicture(dd)
                form5.Show
        End If
            End If
                End If
End Sub

Private Sub Map2_AfterTrackingLayerDraw(ByVal hdc As stdole.OLE_HANDLE)
     Dim sym As New MapObjects2.Symbol  ' Symbol Object: A Symbol object consisits
     ' of attributes that control how a features or graphic shape in displayed.
     sym.OutlineColor = moGreen ' OutlineColor Property: Returns or sets the outline
     ' color of a Polygon object's Symbol.
     sym.Style = moTransparentFill  ' Style Property: Returns or sets the style of
     ' a Symbol object.
     Map2.DrawShape Map1.Extent, sym
End Sub

Private Sub Map2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' convert to map point
    Dim p As MapObjects2.Point
    Set p = Map2.ToMapPoint(X, Y)
   
    ' if the click happended inside the indicator, then start dragging
    If Map1.Extent.IsPointIn(p) Then    ' IsPointIn Method: Returns a value that indicates
    ' whether a Point falls within an object.
        Set dr1 = New DrawRect
        dr1.DragStart Map1.Extent, Map2, X, Y
    End If
End Sub

Private Sub Map2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Not dr1 Is Nothing Then
        dr1.DragMove X, Y
    End If
    ' 鼠标在鹰眼上移动,状态栏中显示相应的坐标
    Dim pt As New MapObjects2.Point
    Set pt = Map1.ToMapPoint(X, Y)
    StatusBar1.Panels(2).Text = "X = " & pt.X
    StatusBar1.Panels(3).Text = "Y = " & pt.Y
End Sub

Private Sub Map2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Not dr1 Is Nothing Then
        Set Map1.Extent = dr1.DragFinish(X, Y)
        Set dr1 = Nothing
    End If
End Sub

Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    '更新状态条的坐标显示
    Dim curPoint As Point
    Dim curX As Double
    Dim curY As Double
    '将屏幕目标转换为地理坐标
    Set curPoint = Map1.ToMapPoint(X, Y)
    curX = curPoint.X
    curY = curPoint.Y
    '压缩取小数点后2位
    Dim cX As String, cy As String
    cX = curX
    cy = curY
    cX = Left(cX, InStr(cX, ".") + 2)
    cy = Left(cy, InStr(cy, ".") + 2)
    StatusBar1.Panels(2).Text = "X := " & cX
    StatusBar1.Panels(3).Text = "Y := " & cy
End Sub

' 更新比例尺
Public Sub updateScale()
    ScaleBar1.MapExtent.MaxX = Map1.Extent.Right
    ScaleBar1.MapExtent.MinX = Map1.Extent.Left
    ScaleBar1.MapExtent.MaxY = Map1.Extent.Bottom
    ScaleBar1.MapExtent.MinY = Map1.Extent.Top
   
    ScaleBar1.PageExtent.MinX = Map1.Left / Screen.TwipsPerPixelX
    ScaleBar1.PageExtent.MinY = Map1.Top / Screen.TwipsPerPixelY
    ScaleBar1.PageExtent.MaxX = (Map1.Left + Map1.Width) / Screen.TwipsPerPixelX
    ScaleBar1.PageExtent.MaxY = (Map1.Top + Map1.Height) / Screen.TwipsPerPixelY
   
    ScaleBar1.Refresh
    isLabelShow = ScaleBar1.RFScale
    'MsgBox isLabelShow
    StatusBar1.Panels(4).Text = "比例尺 1 : " & Format$(ScaleBar1.RFScale, "###,###,###,###,###")
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
    If Toolbar1.Buttons(1).Value = tbrPressed Then
        Map1.MousePointer = moZoomIn '鼠标成放大形状
        fd = True
        sx = False
        my = False
        mark = 0
    End If

If Toolbar1.Buttons(2).Value = tbrPressed Then
        Map1.MousePointer = moZoomOut '鼠标成缩小状
        sx = True
        my = False
        fd = False
        mark = 0
    End If

If Toolbar1.Buttons(3).Value = tbrPressed Then
        Map1.MousePointer = moPan   '鼠标成漫游状
        my = True
        sx = False
        fd = False
        mark = 0
    End If

If Toolbar1.Buttons(4).Value = tbrPressed Then
        Map1.MousePointer = moArrow  '全图显示
        Map1.Extent = Map1.FullExtent
        Map1.Refresh
        Toolbar1.Buttons(4).Value = tbrUnpressed
        mark = 0
    End If
    If Toolbar1.Buttons(5).Value = tbrPressed Then
        Map1.MousePointer = moIdentify
    End If
    If Toolbar1.Buttons(6).Value = tbrPressed Then
        Map1.MousePointer = moCross  '鼠标成十字
        mark = 1
    End If
    If Toolbar1.Buttons(7).Value = tbrPressed Then
        Map1.MousePointer = moCross  '鼠标成十字
        mark = 2
    End If
     If Toolbar1.Buttons(8).Value = tbrPressed Then
     Option1.Value = True
      ' MsgBox "请在右面板中选择缓冲区的类型及距离并且在地图上操作"
        mark = 0
    End If
    If Toolbar1.Buttons(9).Value = tbrPressed Then
        Map1.MousePointer = moArrow
        mark = 3
        IsClear = Not IsClear
        Text1.Text = ""
        mark = 0
        Me.Map1.TrackingLayer.ClearEvents
        Option1.Value = False
        Option2.Value = False
        Option3.Value = False
        Option4.Value = False
        Option5.Value = False
        Map1.Refresh
        Toolbar1.Buttons(9).Value = tbrUnpressed
    End If
End Sub

Private Sub 打印_Click()
    Map1.PrintMap "MyMap", "", True
End Sub

Private Sub 地点查询_Click()
MsgBox "请在右面板输入要查询的地名然后点击查询按钮"
    Map1.MousePointer = moIdentify
    my = True
    fd = False
    sx = False
End Sub

'判断实现地图的放大,缩小,漫游,全图
Private Sub 放大_Click()
    Map1.MousePointer = moZoomIn
    fd = True
    my = False
    sx = False
    updateScale
    mark = 0
End Sub

Private Sub 漫游_Click()
    Map1.MousePointer = moPan
    my = True
    fd = False
    sx = False
    mark = 0
End Sub

Private Sub 全图_Click()
    Set Map1.Extent = Map1.FullExtent
    updateScale
    mark = 0
End Sub

Private Sub 缩小_Click()
    Map1.MousePointer = moZoomOut
    sx = True
    my = False
    fd = False
    updateScale
    mark = 0
End Sub


Private Sub 关于_Click()
    Form4.Show
    mark = 0
End Sub

Private Sub 退出_Click()
    End
End Sub

'加载图片
Private Sub 许昌学院风光图_Click()
    Form3.Show
End Sub
'加在规划图
Private Sub 许昌学院规划图_Click()
    Form2.Show
End Sub

' 按类型显示图层颜色
Sub SetUpRenderers()
    Dim ly As New MapObjects2.MapLayer
    Set ly = Map1.Layers("东区面")
    Set ly.Renderer = New ValueMapRenderer
    ly.Renderer.SymbolType = moFillSymbol
    ly.Renderer.Field = "类型"
   
    ly.Renderer.ValueCount = 9
    ly.Renderer.Value(0) = "水域"
    ly.Renderer.Value(1) = "道路"
    ly.Renderer.Value(2) = "公寓"
    ly.Renderer.Value(3) = "教学楼"
    ly.Renderer.Value(4) = "绿地"
    ly.Renderer.Value(5) = "林地"
    ly.Renderer.Value(6) = "办公楼"
    ly.Renderer.Value(7) = "运动场"
    ly.Renderer.Value(8) = "其他"
   
    '为不同类型设置不同颜色
    ly.Renderer.Symbol(0).Color = RGB(20, 157, 255)
    ly.Renderer.Symbol(1).Color = moLightGray
    ly.Renderer.Symbol(2).Color = moWhite
    ly.Renderer.Symbol(3).Color = moWhite
    ly.Renderer.Symbol(4).Color = moGreen
    ly.Renderer.Symbol(5).Color = moGreen
    ly.Renderer.Symbol(6).Color = moWhite
    ly.Renderer.Symbol(7).Color = RGB(251, 197, 4)
    ly.Renderer.Symbol(8).Color = moLightYellow
End Sub


' 添加点注记
Sub SetUpPointLabelRenderers()
    Dim ly1 As New MapObjects2.MapLayer
    Dim fnt1 As New StdFont
    Set ly1 = Map1.Layers("东区点")
    fnt1.Name = "Arial"
    fnt1.Bold = False
    fnt1.Size = 2
    fnt1.Strikethrough = True
    Dim lr1 As New MapObjects2.LabelRenderer
    ly1.Renderer = lr1
   
    With lr1
        .Field = "名称"
        .SymbolCount = 1
        .AllowDuplicates = True
        .SplinedText = True
        .Symbol(0).Color = moRed
    End With
End Sub

' 添加线注记
Sub SetUpLineLabelRenderers()
    Dim ly2 As New MapObjects2.MapLayer
    Dim fnt2 As New StdFont
    Dim lr2 As New LabelRenderer
    Set ly2 = Map1.Layers("东区线")
    fnt2.Name = "Arial"
    fnt2.Bold = True
    fnt2.Size = 2
    fnt2.Strikethrough = True
    ly2.Renderer = lr2
   
    With lr2
        .Field = "名称"
        .SymbolCount = 1
        .AllowDuplicates = True
        .SplinedText = False
        .Symbol(0).Color = moPurple
    End With
End Sub

最后运行时候的界面:

 

转载于:https://www.cnblogs.com/sunliming/archive/2010/05/27/1745402.html

相关文章:

vsftp部署

1.安装该软件需要使用最高用户&#xff08;root&#xff09;进行安装&#xff0c;否则不能进行。 2.首先用命令检查VSFTP是否已经安装。chkconfig --list | grep vsftpd 3.安装vsftp。yum install –y vsftpd 4.启动vsftp。service vsftpd start 5.添加一个ftp用户。useradd f…

线程、线程匿名内部类、解决线程不安全的方式

线程 线程&#xff1a;正在运行的程序&#xff0c;是程序的执行路径&#xff1b;多线性 进程&#xff1a;是应用程序的载体&#xff0c;程序运行在虚拟机中。一个应用软件对应一个进程。 一个进程包含多个线程&#xff0c;一个线程对应一个进程。 好处&#xff1a;提高软件的运…

工作流编程循序渐进(9:使用本地服务在宿主和工作流之间通信)

工作流编程循序渐进&#xff08;9&#xff1a;使用本地服务在宿主和工作流之间通信&#xff09; 作者 朱先忠 &#xff3b;摘要&#xff3d;在本篇中&#xff0c;首先详细分析本地服务有关概念&#xff0c;探讨本地服务在工作流运行时、工作流实例及工作流宿主间的地位及作用…

使用Properties连接数据库

使用Properties连接数据库 要注意的是&#xff1a; 1.通过配置文件来连接数据库时&#xff0c;连接信息要以 mysql.XXX开头,否则会提示异常。 java.sql.SQLException: Access denied for user localhost (using password: YES)生成配置文件的实现代码 1、创建写入配置信息工…

两边横线,中间标题

<!DOCTYPE html> <html> <head> <title>两边横线&#xff0c;中间标题</title> <meta http-equiv"Content-Type" content"text/html; charsetutf-8" /> <style type"text/css"> <!--ul { mar…

交换机基础配置

请同学们下载附件中的实验并完成。转载于:https://blog.51cto.com/coffee0546/204093

python高级-模块(14)

一、python中的模块 有过C语言编程经验的朋友都知道在C语言中如果要引用sqrt函数&#xff0c;必须用语句#include <math.h>引入math.h这个头文件&#xff0c;否则是无法正常进行调用的。 那么在Python中&#xff0c;如果要引用一些其他的函数&#xff0c;该怎么处理呢&am…

RabbitMQ学习系列二:.net 环境下 C#代码使用 RabbitMQ 消息队列

上一篇已经讲了Rabbitmq如何在Windows平台安装&#xff0c;不懂请移步&#xff1a;RabbitMQ学习系列一&#xff1a;windows下安装RabbitMQ服务 一、理论&#xff1a; .net环境下&#xff0c;C#代码调用RabbitMQ消息队列&#xff0c;本文用easynetq开源的.net Rabbitmq api来实…

一步步学会使用ASP.NET 4 WEB应用程序中使用URL Routing(翻译)

创建路由 路由就是将URL路径映射到具体的物理文件。若要将路由添加到网站中&#xff0c;请使用 RouteCollection.MapPageRoute 方法将它们添加到RouteTable类的静态Routes属性。 将用于添加路由的方法添加到 Global.asax 文件中 如果网站还没有 Global.asax 文件&#xff0c;…

Properties持久的属性集

Properties 属性集合继承了Hashtable 属性包括属性名和属性值&#xff08;键值对keyvalue&#xff09; 作用 可以存储多个键值&#xff0c;与map相似可以把键值对存储到文件中可以把文件中的键值对读取到Properties对象中 构造方法&#xff1a; Properties() 创建一个无默认…

让你二十年后仍是人才

1.不管坐什么位置&#xff0c;都要保持学习的习惯出社会工作十年到十五年左右&#xff0c;会有一种「上下卡住」的闭塞感与无力感。因为&#xff0c;这个阶段的上班族虽然拥有一定的资历与经验&#xff0c;工作也得心应手&#xff0c;但上面有比自己更资深的前辈压着&#xff0…

Django ORM操作

Django ORM操作 一般操作 看专业的官网文档&#xff0c;做专业的程序员&#xff01; 必知必会13条 <1> all(): 查询所有结果<2> get(**kwargs): 返回与所给筛选条件相匹配的对象&#xff0c;返回结果有且只有一个&#xff0c;如果符合筛选…

ChineseCalendar类[转]

///<summary>///Title: ChineseCalendar类 ///Description: 中文日期工具类 ///author 万灵杰[作者] ///version 1.0.0.0 ///date 2009年7月30日 ///modify ///date ///</summary>publicclassChineseCalendar { privatestaticrea…

程序员的自我救赎---13.1:职场招聘与面试心得

《前言》 《目录》 &#xff08;一&#xff09; Winner2.0 框架基础分析 &#xff08;二&#xff09;PLSQL报表系统 &#xff08;三&#xff09;SSO单点登录 &#xff08;四&#xff09; 短信中心 &#xff08;五&#xff09;钱包系统 &#xff08;六&#xff09;GPU支付中心 &…

网络编程 UDP通信的过程 TCP通信过程 多线程文件上传

网络概述 协议 在网络之间传出数据时需要按照指定的标准来传输&#xff0c;标准中规定了数据的格式、大小、传输的方式、传输速率。形成统一规范—>按照规范开发的代码—>协议&#xff08;应用层、传输层、网络层、链路层&#xff09; InetAddress类 用来分装网络地址…

set debug mode for flex builder

1. 要具备debug功能&#xff0c;我们必须要首先安装Flash Player Debug 版本。windows版本2. 安装好debug版本后&#xff0c;我们还需要添加日志的配置文件mm.cfg。该配置文件存放的目录如下&#xff1a;Macintosh OS X MacH D:Library:Application Support:macromedia:mm.cfgM…

XML 解析XML文档 XML约束

XML 什么是XML Extensible Markup Language&#xff08;可扩展的标记语言&#xff09;他是一个语言&#xff0c;有自己的语法&#xff0c;和Java以及其他的编程无关“标记” 在文件中包含类似于张三 &#xff0c;这种用尖括号括起来的叫标记&#xff0c;使用来标记数据的。标…

Host Only、NAT和Bridge三种网络连接

Host Only、NAT和Bridge三种网络连接 在安装好了Linux镜像之后&#xff0c;如何连接物理机和虚拟机呢&#xff1f;这就需要网络连接&#xff0c;网络连接有三种&#xff1a;HostOnly、NAT、Bridge&#xff0c;它们都可用于Guest虚拟机和Host物理机之间的网络通信。 一、三者的不…

OSPF 提升 一 ----基础

ospf ccnp内容 一 link-state protocols IGP 开放式的最短路径优先协议 公有协议支持中到大型的网络 spf算法 链路状态协议1.传送的LSA link status advertisement 链路状态通告 包换拓扑信息具体包括&#xff1a;网段的前缀 掩码 连接的路由器的…

C#实现网页截图功能

//需要添加System.Drawing及System.Windows.Forms引用 using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Windows.Forms; namespace 网页截图 { class Program { [S…

微软发布全新多核心操作系统原型:Barrelfish

Windows 7完成之后&#xff0c;很多人开始把目光投向微软的下一代服务器和客户端操作系统Windows 8&#xff0c;不过今天微软放出了一套全新操作系统的原型&#xff0c;开发代号“Barrelfish”。该系统由微软剑桥研究院和苏黎世理工学院联合全新开发&#xff0c;专为现在和未来…

Docker应用:Kubernetes(容器集群)

Docker应用&#xff1a;Kubernetes&#xff08;容器集群&#xff09; 原文:Docker应用&#xff1a;Kubernetes&#xff08;容器集群&#xff09;阅读目录&#xff1a; Docker应用&#xff1a;Hello WorldDocker应用&#xff1a;Docker-compose&#xff08;容器编排&#xff09;…

通道应用——抠头发

通道应用——抠头发 原图&#xff1a; 效果图&#xff1a; 步骤&#xff1a;1、打开原图的“通道面板”&#xff0c;选择颜色对比分明的绿色通道&#xff0c;并新建一个绿色通道副本&#xff1b;2、选择“图像”-“调整”-“色阶”&#xff0c;调节色阶使得头发颜色更分明些&am…

2017 ACM/ICPC 南宁赛区小结 By JSB @ Reconquista

Statistics TYPE: Onsite ContestNAME: 2017 - ICPC - Asia NanningPLAT: pc^2TIME: 2017/11/26 09:00-14:00LOCA: Guangxi UniversityTEAM: Reconquista[shb,lsmll,jsb]RANK: 8/227 3.52%SOLVE: 8/13PENALTY: 451 ◦ A - 1 ◦ E - 123 (2) ◦ F - 8 ◦ H - 55 ◦ I - 97 (1) ◦…

用户管理系统控制台版连接数据库

建User表 CREATE TABLE user (id INT(11) NOT NULL AUTO_INCREMENT,name VARCHAR(20) DEFAULT NULL,pwd VARCHAR(20) DEFAULT NULL,PRIMARY KEY (id) ) ENGINEINNODB AUTO_INCREMENT5 DEFAULT CHARSETutf8User对象&#xff08;javaBean&#xff09; public class User {priva…

微信小程序组件 日历

js文件 use strict;let choose_year null,choose_month null;const conf {data: {hasEmptyGrid: false,showPicker: false},onLoad() {const date new Date();const cur_year date.getFullYear();const cur_month date.getMonth() 1;const weeks_ch [ 日, 一, 二, 三, …

node编写定时任务,for循环只执行一遍的解决办法

在用node编写定时任务时候&#xff0c;发现for循环只执行i0这一次&#xff0c;就不接着循环执行了&#xff0c;下面贴上代码&#xff1a; exports.task async function(ctx){ let { app } ctx, resultArr1 [],//查询的数据库数据 resultArr2 [];//查询的数据库…

oledb读不到dbf文件内容

最近在处理一批VFP的数据库&#xff0c;使用OleDB方式读取一直很正常&#xff0c;前两天突然碰到一张表怎么也读不出数据来&#xff0c;害我瞎忙了一整天&#xff0c;在研究了DBF文件结构后发现记录前的0x20位置存储的是0x2A。 一查才知道是删除标记&#xff0c;我倒&#xff0…

好用的截图工具

好用的截图工具...简单好用而且不大转载于:https://blog.51cto.com/dd123/208983

“AS3.0高级动画编程”学习:第二章转向行为(上)

因为这一章的内容基本上都是涉及向量的&#xff0c;先来一个2D向量类&#xff1a;Vector2D.as (再次强烈建议不熟悉向量运算的童鞋&#xff0c;先回去恶补一下高等数学-07章空间解释几何与向量代数.pdf) package {import flash.display.Graphics;public class Vector2D {privat…