MapObject学习笔记-在鹰眼指示窗口中拖动方框代码

                             在鹰眼指示窗口中拖动方框



类模块
dragfeedback定义

' WinAPI function declarations and constants

Private Declare Function GdiRectangle Lib "gdi32" Alias "Rectangle" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Private Declare Function SetROP2 Lib "gdi32" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long

Private Const R2_NOTXORPEN = 10

 

' glogal map

Dim m_map As MapObjects2.Map

 

' variables that keep track of moving the indicator

Dim m_hDC As Long         ' a DC to draw into

Dim m_hWnd As Long        ' window handle

Dim m_xMin As Integer, m_yMin As Integer  ' drag indicator

Dim m_xMax As Integer, m_yMax As Integer  ' drag indicator

Dim m_xPrev As Integer       ' click location

Dim m_yPrev As Integer       ' click location

 

Function DragFinish(x As Single, y As Single) As MapObjects2.Rectangle

  GdiRectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax

  ReleaseDC m_hWnd, m_hDC

 

  ' return the rectangle

  Dim r As New MapObjects2.Rectangle

  PixelsRectToMap m_xMin, m_yMin, m_xMax, m_yMax, r

  Set DragFinish = r

End Function

 

Sub DragMove(x As Single, y As Single)

  ' convert to pixels

  xNext = m_map.Parent.ScaleX(x, vbTwips, vbPixels)

  yNext = m_map.Parent.ScaleY(y, vbTwips, vbPixels)

   

  GdiRectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax

  m_xMin = m_xMin + (xNext - m_xPrev)

  m_xMax = m_xMax + (xNext - m_xPrev)

  m_yMin = m_yMin + (yNext - m_yPrev)

  m_yMax = m_yMax + (yNext - m_yPrev)

 

  GdiRectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax

  m_xPrev = xNext

  m_yPrev = yNext

End Sub

 

Sub DragStart(rect As MapObjects2.Rectangle, Map As MapObjects2.Map, x As Single, y As Single)

  Set m_map = Map

    ' initialize the hwnd and hdc variables

  m_hWnd = m_map.hwnd

  m_hDC = GetDC(m_hWnd)

  SetROP2 m_hDC, R2_NOTXORPEN   ' raster op for inverting

   

  MapRectToPixels rect, m_xMin, m_yMin, m_xMax, m_yMax

 

  ' draw the rectangle

  GdiRectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax

 

  ' remember the click position

  ' convert to pixels

  m_xPrev = m_map.Parent.ScaleX(x, vbTwips, vbPixels)

  m_yPrev = m_map.Parent.ScaleY(y, vbTwips, vbPixels)

End Sub

 

Private Sub MapRectToPixels(r As MapObjects2.Rectangle, xMin As Integer, yMin As Integer, xMax As Integer, yMax As Integer)

  Dim p As New Point

  Dim xc As Single, yc As Single

 

  p.x = r.Left

  p.y = r.Top

  m_map.FromMapPoint p, xc, yc

 

  ' convert to pixels

  xMin = m_map.Parent.ScaleX(xc, vbTwips, vbPixels)

  yMin = m_map.Parent.ScaleY(yc, vbTwips, vbPixels)

 

  p.x = r.Right

  p.y = r.Bottom

  m_map.FromMapPoint p, xc, yc

 

  ' convert to pixels

  xMax = m_map.Parent.ScaleX(xc, vbTwips, vbPixels)

  yMax = m_map.Parent.ScaleY(yc, vbTwips, vbPixels)

End Sub

 

Sub PixelsRectToMap(xMin As Integer, yMin As Integer, xMax As Integer, yMax As Integer, r As MapObjects2.Rectangle)

  Dim xc As Single, yc As Single

 

  ' convert to twips

  xc = m_map.Parent.ScaleX(xMin, vbPixels, vbTwips)

  yc = m_map.Parent.ScaleY(yMin, vbPixels, vbTwips)

 

  Set p = m_map.ToMapPoint(xc, yc)

  r.Left = p.x

  r.Top = p.y

 

  ' convert to twips

  xc = m_map.Parent.ScaleX(xMax, vbPixels, vbTwips)

  yc = m_map.Parent.ScaleY(yMax, vbPixels, vbTwips)

  Set p = m_map.ToMapPoint(xc, yc)

  r.Right = p.x

  r.Bottom = p.y

End Sub

窗体代码:

Option Explicit

Dim g_feedback As dragfeedback

 

Private Sub Map2_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

  '将点击转换为Map2上的点对象;

  Dim p As Point

  Set p = Map2.ToMapPoint(x, y)

 

  '如果点击发生在方框内,开始拖动;

  If Map1.Extent.IsPointIn(p) Then

    Set g_feedback = New dragfeedback

    g_feedback.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 g_feedback Is Nothing Then

    g_feedback.DragMove x, y

  End If

End Sub

 

'拖动完成,并在Map1中显示新位置;

Private Sub Map2_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

  If Not g_feedback Is Nothing Then

    Map1.Extent = g_feedback.DragFinish(x, y)

    Set g_feedback = Nothing

  End If

End Sub

 

'左键放大,右键缩小;

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

  Dim r As MapObjects2.Rectangle

  If Button = vbLeftButton Then

    Set Map1.Extent = Map1.TrackRectangle

  ElseIf Button = vbRightButton Then

    Set r = Map1.Extent

    r.ScaleRectangle 2

    Map1.Extent = r

  End If

End Sub

 

'使Map2Map1联动;

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

  End If

End Sub

 

'Map2上画红色指示框;

Private Sub Map2_AfterTrackingLayerDraw(ByVal hdc As stdole.OLE_HANDLE)

  Dim sym As New Symbol

  sym.OutlineColor = moRed

  sym.Size = 2

  sym.Style = moTransparentFill

  Map2.DrawShape Map1.Extent, sym

End Sub

 

Private Sub Form_Load()

  Dim dc As New DataConnection

  Dim layer As MapLayer

  dc.Database = App.Path + "\..\" + "world"

  If Not dc.Connect Then

    MsgBox "在指定的文件夹下没找到图层数据文件!"

    End

  End If

  Set layer = New MapLayer

  Set layer.GeoDataset = dc.FindGeoDataset("country")

  layer.Symbol.Color = moYellow

  Map1.Layers.Add layer

  Set layer = New MapLayer

  Set layer.GeoDataset = dc.FindGeoDataset("cities")

  layer.Symbol.Color = moRed

  Map1.Layers.Add layer

  Map1.Refresh

 

  Set layer = New MapLayer

  Set layer.GeoDataset = dc.FindGeoDataset("country")

  layer.Symbol.Color = moYellow

  Map2.Layers.Add layer

  Map2.Refresh

End Sub

 

posted @ 2007-05-22 16:53 GIS云中飞鹏 阅读(1549) 评论(14)  编辑 收藏 所属分类: MapObject开发

  回复  引用    
#1楼 2007-07-22 04:57 | hamada_abdelazeez [未注册用户]
7777777777777777777777777777777777777777777777777777
  回复  引用    
#2楼 2007-07-31 13:11 | jun [未注册用户]
'关于在MapObject计算多边形与多个地区相交的面积的问题
'运行时
'Set intersectshape(ri) = recselection(ri).Fields("shape").Value 出错
'不知道是什么原因?
Dim resultshape(32) As MapObjects2.Polygon
Dim recselection(32) As MapObjects2.Recordset
Dim rect As MapObjects2.Polygon
Private Sub Form_Load()
'预先加载一张墨西歌地图
Label1.Caption = "在地图上画多边形"
End Sub

Private Sub Map1_AfterLayerDraw(ByVal index As Integer, ByVal canceled As Boolean, ByVal hDC As stdole.OLE_HANDLE)
Dim sym(32) As New MapObjects2.Symbol
Dim sym1 As New MapObjects2.Symbol
Dim ri As Integer
If Not rect Is Nothing Then
sym1.Color = moYellow
Map1.DrawShape rect, sym1
End If
For ri = 1 To 22
If Not resultshape(ri) Is Nothing Then
sym(ri).Color = moRed
Map1.DrawShape resultshape(ri), sym(ri)
End If

End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim am As Single
Const ak = 1000
Dim intersectshape(32) As MapObjects2.Polygon
Dim strexpression As String
Dim ri As Integer
Set rect = Map1.TrackPolygon
am = 0
For ri = 1 To 32
strexpression = "state_id " & ri
Set recselection(ri) = Map1.Layers("states").SearchExpression(strexpression)
Set intersectshape(ri) = recselection(ri).Fields("shape").Value
Set resultshape(ri) = rect.Intersect(intersectshape(ri))
If Not resultshape(ri) Is Nothing Then
am = resultshape(ri).Area + am
End If
Next ri
If am < 0.001 Then
Label1.Caption = "没有相交。"
Else
Label1.Caption = "相交面积 = " & Format(am * ak, "0.00") & "平方公里。"
End If
Map1.Refresh
End Sub

  回复  引用    
#3楼 2007-08-01 18:45 | xiaoran [未注册用户]
在strexpression = "state_id " & ri 中,state_id 改为featureid就可以运行
在MapObject中id号用字段featureid表达

  回复  引用    
#4楼 2007-08-06 00:22 | xiaoran [未注册用户]
请教,怎么在mapobject 中实现三维漫游的功能?或者,在mapobject 中调用arcGIS的三维漫游模块?
  回复  引用    
#5楼 2007-08-06 08:21 | GIS云中飞鹏 [未注册用户]
mo中好像不那做三维啊~!
  回复  引用    
#6楼 2007-08-06 08:22 | GIS云中飞鹏 [未注册用户]
想用arcGIS的三维漫游模块,就用AE或AO吧!
  回复  引用    
#7楼 2007-08-09 21:34 | 福慧居士 [未注册用户]
我正在开发我们学校的地理信息系统,已经用mo+vb完成了浏览查询功能。boss说要做三维仿真漫游,三维图有现成的,请问接下来怎么做
  回复  引用    
#8楼 2007-08-10 08:55 | GIS云中飞鹏 [未注册用户]
mo中能做三维吗?!不知道啊!为什么不用ae做呢?!
  回复  引用    
#9楼 2007-08-10 12:07 | 福慧居士 [未注册用户]
Ao行不行啊?,能不能用vb调用arcGIS的的3d漫游模块
  回复  引用    
#10楼 2007-08-10 12:23 | GIS云中飞鹏 [未注册用户]
AO当然行啊 ao比ae接口还多那!
  回复  引用    
#11楼 2007-10-17 11:58 | 一佛 [未注册用户]
能给我发一份鹰眼的vb 代码吗(做好的程序)。我用您的代码,在vb上运行后总是报错。谢谢。我的邮箱是zzj32@126.com
  回复  引用  查看    
#12楼 [楼主]2007-10-17 16:52 | GIS云中飞鹏      
没有现成的程序!这些代码都调试通过了 仔细调试一下应该没有问题!
  回复  引用    
#13楼 2008-05-19 20:07 | xueni [未注册用户]
楼主,你有相关的VC代码吗?
  回复  引用  查看    
#14楼 [楼主]2008-05-20 10:45 | GIS云中飞鹏      
htmlMoView2-VB版+MoView2-VC版下载(源程序下载)

http://www.cnblogs.com/gispeng/archive/2008/04/18/1160158.html

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-05-23 10:12 编辑过


相关链接: