gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:4165回复:5

MapX的“鹰眼”实现(vb)[转帖]

楼主#
更多 发布于:2003-10-15 12:44
新建一工程,放两个MapX控件:Map1(主),Map2(导航),放三个按钮用来放大、缩小和漫游:CmdZoomIn,CmdZoomOut,CmdPan

'本程序演示MapX的“鹰眼”窗口
'采用MapX的Feature方式实现
'如有问题,请和我联系 yz_zhang@263.net(张玉洲)

Dim m_TempLayer As Layer '导航图上临时图层
Dim m_Fea As MapXLib.Feature '导航图上反映主地图窗口位置的Feature
Dim bDown As Boolean '鼠标在导航图上按下的标志

Private Sub CmdPan_Click()
Map1.CurrentTool = miPanTool
End Sub

Private Sub CmdZoomIn_Click()
Map1.CurrentTool = miZoomInTool
End Sub

Private Sub CmdZoomOut_Click()
Map1.CurrentTool = miZoomOutTool
End Sub

Private Sub Form_Load()
''给Map2增加临时图层
Set m_TempLayer = Map2.Layers.CreateLayer("wewew"
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set m_Fea = Nothing
Set m_TempLayer = Nothing
End Sub

''根据map1的Bounds在Map2上绘制矩形
Private Sub Map1_MapViewChanged()
Dim tempFea As MapXLib.Feature
Dim tempPnts As MapXLib.Points
Dim tempStyle As MapXLib.Style

If m_TempLayer.AllFeatures.Count = 0 Then '矩形边框还没有
'设置矩形边框样式
Set tempStyle = New MapXLib.Style
tempStyle.RegionPattern = miPatternNoFill
tempStyle.RegionBorderColor = 255
tempStyle.RegionBorderWidth = 2
'在临时图层添加大小为Map1的边界的Rectangle对象
Set tempFea = Map2.FeatureFactory.CreateRegion(Map1.Bounds, tempStyle)
Set m_Fea = m_TempLayer.AddFeature(tempFea)
Set tempStyle = Nothing
Else '根据Map1的视野变化改变矩形边框的大小和位置
With m_Fea.Parts.Item(1)
.RemoveAll
.AddXY Map1.Bounds.XMin, Map1.Bounds.YMin
.AddXY Map1.Bounds.XMax, Map1.Bounds.YMin
.AddXY Map1.Bounds.XMax, Map1.Bounds.YMax
.AddXY Map1.Bounds.XMin, Map1.Bounds.YMax
End With
m_Fea.Update
End If
End Sub

'下面代码和"API方式实现"的一样
Private Sub Map2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MapX As Double
Dim MapY As Double
bDown = True
Map2.ConvertCoord X, Y, MapX, MapY, miScreenToMap
Map1.CenterX = MapX
Map1.CenterY = MapY

End Sub

Private Sub Map2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MapX As Double
Dim MapY As Double
If bDown Then
Map2.ConvertCoord X, Y, MapX, MapY, miScreenToMap
Map1.CenterX = MapX
Map1.CenterY = MapY
End If
End Sub

Private Sub Map2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bDown = False
End Sub
喜欢0 评分0
wangjh
论坛版主
论坛版主
  • 注册日期2003-08-22
  • 发帖数994
  • QQ55359982
  • 铜币2579枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2003-10-15 16:07
这个方法不错。但是我在应用中,经常出现:
    If m_TempLayer.AllFeatures.Count = 0 Then '矩形边框还没有
在这一句上有错误,执行不下去。
网 站: www.52xoo.com (3S,信息融合,数字图像处理,模式识别与人工智能等专业电子书、学术文章及源代码共享) E-mail: Jianhong72@163.com QQ: 88128745 (55359982用了近10年,最近被盗了,郁闷!!!)
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2003-10-21 11:13
我没实验过,期待你们调试了,呵呵
举报 回复(0) 喜欢(0)     评分
egis
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数73
  • QQ
  • 铜币427枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-04-06 08:59
If m_TempLayer.AllFeatures.Count = 0 Then '矩形边框还没有
在这一句上有错误,执行不下去。这个错误我解决了

就是把这一句的位置不对,应该放在打开图集的后面就行了,看我的


    Map1.Layers.AddGeoSetLayers App.Path + "\maps\梧州.GST"
    Map2.Layers.AddGeoSetLayers App.Path + "\maps\梧州1.GST"
    Set m_TempLayer = Map2.Layers.CreateLayer("Rectlayer")
举报 回复(0) 喜欢(0)     评分
egis
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数73
  • QQ
  • 铜币427枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2004-04-06 09:02
还有一个问题,为什么鹰眼窗口的矩形框我们不能自己用鼠标画啊,
只能拖动和单击定他的中心坐标,如果能自己画矩形框那多爽啊
举报 回复(0) 喜欢(0)     评分
frost_cc
路人甲
路人甲
  • 注册日期2009-10-12
  • 发帖数2
  • QQ
  • 铜币113枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2009-11-11 15:00
<P>顶,好东西啊</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部