Mapx中创建测距工具、自动滚屏、图元的拖拽

 

Mapx中创建测距工具示例
首先创建测距工具
global const calculatedistance=1
Private Sub Form_Load()
map1.CreateCustomTool(calcilatedistance,miToolTypepoly ,microsscursor)
End Sub
Private Sub Distances_Click()
map1.currenttool=calculatetool
End Sub


然后在mapx的PolyToolUsed事件中, 用Distance( x1,y1,x2,y2 )计算距离,由状态条中或label显示。
Private Sub Map1_PolyToolUsed(ByVal ToolNum As Integer, ByVal Flags As Long, ByVal points As Object, ByVal bShift As Boolean, ByVal bCtrl As Boolean, EnableDefault As Boolean)

Dim DisSum As Double
Dim Dis As Double
Dim n As Integer
Dim pts As New MapXLib.points
Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double

Set pts = points

DisSum = 0
MDIForm1.StatusBar1.Panels.Item(3).Text= Format(Str(DisSum), "#,##0.000000")

Select Case Flags
Case miPolyToolBegin
Case miPolyToolInProgress
If ToolNum = CalculateDistance Then
For i = 1 To pts.Count - 1
x1 = pts.Item(i).X
y1 = pts.Item(i).Y
x2 = pts.Item(i + 1).X
y3 = pts.Item(i + 1).Y
Dis = Map1.Distance(x1, y1, x2, y2)
DisSum = DisSum + Dis
MDIForm1.StatusBar1.Panels.Item(3).Text = Format(Str(DisSum), "#,##0.000000")
Next i
End If

Case miPolyToolEnd

End Select 回页首

在mapx中如何实现自动滚屏
mapx 支持 MouseMove 事件,可以在此事件中实现自动滚屏,示例如下:

Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If map_move = True Then

If X > Map1.MapScreenWidth - 10 Then

Map1.CenterX = Map1.CenterX + 0.05

Map1.Refresh

Else

If X < 10 Then

Map1.CenterX = Map1.CenterX - 0.05

Map1.Refresh

Else

If Y > Map1.MapScreenHeight - 10 Then

Map1.CenterY = Map1.CenterY - 0.05

Map1.Refresh

Else

If Y < 10 Then

Map1.CenterY = Map1.CenterY + 0.05

Map1.Refresh

End If

End If

End If

End If

End If

End Sub 回页首

在mapx中如何实现图元的拖拽
以下方法实现将选中图元移到点击处。
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ftr As Feature
Dim lyr As Layer
Dim MapX As Double
Dim MapY As Double
'convert where the mouse is clicked to the map's current coordinate system
Map1.ConvertCoord X, Y, MapX, MapY, miScreenToMap
'iterate through each selected feature in each layer
For Each lyr In Map1.Layers
For Each ftr In lyr.Selection

'change the offset of the feature
ftr.Offset MapX - ftr.CenterX, MapY - ftr.CenterY
'update the feature to make the change permanent
ftr.Update
Next
Next
End Sub

==================

以下代码创建选择工具(框选、圈选、多边形选择)而不使用mapx标准的tool,同时实现自动滚屏(效果不好)。

Dim pnt101 As New Point
Dim pnts103 As New Points
Dim lyr As Layer

Private Sub Command1_Click()
Map1.CurrentTool = 101
End Sub

Private Sub Command2_Click()
Map1.CurrentTool = 102
End Sub

Private Sub Command3_Click()
Map1.CurrentTool = 103
End Sub

Private Sub Form_Load()
'init lyr and the first point
pnt101.Set 0, 0
Set lyr = Map1.Layers.AddUserDrawLayer("DrawLyr", 1)
Map1.Layers.CreateLayer ("Temp")
Map1.Layers.Item("temp").Editable = True
Set Map1.Layers.InsertionLayer = Map1.Layers.Item("temp")
Map1.CreateCustomTool 101, miToolTypePoint, 2 'rect tool
Map1.CreateCustomTool 102, miToolTypePoint, 2 'radius tool
Map1.CreateCustomTool 103, miToolTypePoint, 2 'poly tool
End Sub

Private Sub Map1_DblClick()
If Map1.CurrentTool = 103 And pnts103.Count > 1 Then
Set ftr = Map1.FeatureFactory.CreateRegion(pnts103)
ftr.Attach Map1
Set ftr = Map1.Layers.Item("temp").AddFeature(ftr)
Map1.Layers.Item("Us Capitals").Selection.ClearSelection
Map1.Layers.Item("US Capitals").Selection.SelectByRegion Map1.Layers.Item("temp"), ftr, miSelectionNew
pnts103.RemoveAll
Map1.Layers.Item("temp").DeleteFeature ftr
End If
End Sub

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 ftrs As Features
Dim rect As New Rectangle
If ToolNum = 101 Then
If pnt101.X = 0 And pnt101.Y = 0 Then
pnt101.Set X1, Y1
Else
rect.Set X1, Y1, pnt101.X, pnt101.Y
Set ftrs = Map1.Layers.Item("US Capitals").SearchWithinRectangle(rect, miSearchTypePartiallyWithin)
Map1.Layers.Item("Us Capitals").Selection.ClearSelection
Map1.Layers.Item("Us Capitals").Selection.Add ftrs
pnt101.Set 0, 0
End If
End If
If ToolNum = 102 Then
If pnt101.X = 0 And pnt101.Y = 0 Then
pnt101.Set X1, Y1
Else
Dim dist As Double
dist = Map1.Distance(X1, Y1, pnt101.X, pnt101.Y)
Set ftrs = Map1.Layers.Item("US Capitals").SearchWithinDistance(pnt101, dist, Map1.MapUnit, miSearchTypePartiallyWithin)
Map1.Layers.Item("Us Capitals").Selection.ClearSelection
Map1.Layers.Item("Us Capitals").Selection.Add ftrs
pnt101.Set 0, 0
End If
End If
If ToolNum = 103 Then
pnts103.AddXY X1, Y1
End If
End Sub


Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > Map1.MapScreenWidth - 10 Then
Map1.CenterX = Map1.CenterX + 0.5
Else
If X < 10 Then
Map1.CenterX = Map1.CenterX - 0.5
Else
If Y > Map1.MapScreenHeight - 10 Then
Map1.CenterY = Map1.CenterY - 0.5
Else
If Y < 10 Then
Map1.CenterY = Map1.CenterY + 0.5
End If
End If
End If
End If
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dephi MapX 是一种基于 Delphi 编程语言的地图处理组件库。该组件库提供了丰富的地图操作功能,可以方便地实现地图显示、编辑、导航和查询等功能。Dephi MapX 使用了面向对象的设计思想,将地图操作封装成不同的对象,开发者可以通过调用这些对象的方法来完成相应的地图操作。 Dephi MapX 提供了多种地图数据源的支持,包括各种常见的地图格式,如 Shapefile、DWG/DXF、GeoJSON、KML 等。通过这些数据源,可以加载地图数据并在界面上显示出来。在地图显示方面,Dephi MapX 提供了多种样式和符号,开发者可以根据需求自定义地图的风格。 在地图编辑方面,Dephi MapX 提供了丰富的工具和功能,可以进行地图对象的创建、修改和删除等操作。开发者可以在界面上绘制多边形、点、线等地图对象,并对其进行编辑。此外,Dephi MapX 还支持地图对象的选择和拖拽操作,方便地进行地图编辑。 Dephi MapX 还提供了地图导航和查询功能。通过地图导航功能,可以实现地图的平移、缩放、旋转等操作。而地图查询功能可以根据指定的条件在地图上进行查询,并将查询结果以图形化的方式展示出来。 总之,Dephi MapX 是一个功能强大且易于使用的地图处理组件库。不仅可以实现地图显示、编辑、导航和查询等常见功能,还提供了丰富的样式和符号供开发者使用。无论是开发一个地图应用程序还是集成地图功能到现有的应用程序,Dephi MapX 都是一个很好的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值