Dim shape1 As Boolean '判断是否已经获得一个几何形状
Dim shp As Object '第一个输入的形状
Dim shp2 As Object '第二个输入的形状
Private Sub Form_Load()
Option3.Caption = "差运算"
Option4.Caption = "交运算"
Option5.Caption = "并运算"
Option6.Caption = "异或运算"
Option7.Caption = "线"
Option8.Caption = "多边形"
shape1 = True
Dim dc As New MapObjects2.DataConnection
dc.Database = "D:Program FilesESRIMapObjects2SamplesDataUSA"
If Not dc.Connect Then
MsgBox "连接错误", vbCritical, "连接错误"
End
End If
Dim layer As New MapObjects2.MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("States")
If layer Is Nothing Then
MsgBox "找不到需要的图层"
End
Else
layer.Symbol.Color = moPaleYellow
Map1.BackColor = moNavy
Map1.Layers.Add layer
Dim r As New MapObjects2.Rectangle
Set r = Map1.FullExtent
Map1.Extent = r
Map1.ScrollBars = False
End If
'创建Trackinglayer的符号属性
Map1.TrackingLayer.SymbolCount = 6
With Map1.TrackingLayer.Symbol(0)
.SymbolType = moPointSymbol
.Style = moTriangleMarker
.Color = moRed
.Size = 5
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 = moGreen
.OutlineColor = moGreen
End With
With Map1.TrackingLayer.Symbol(4)
.SymbolType = moLineSymbol
.Style = moDotLine
.Color = moGreen
.Size = 3
End With
With Map1.TrackingLayer.Symbol(5)
.SymbolType = moPointSymbol
.Style = moTriangleMarker
.Color = moGreen
.Size = 5
End With
End Sub
Private Sub Command1_Click()
Map1.TrackingLayer.ClearEvents
Set shp = Nothing
Set shp2 = Nothing
shape1 = True
Label1.Caption = "更新Tracking Layer...无已获得的图形"
End Sub
Private Function trackShape() As Object '根据用户的选择在trackinglayer上创建图形
If Option7.Value Then
Dim line As New MapObjects2.line
Set line = Map1.TrackLine
Set trackShape = line
Dim evline As New MapObjects2.GeoEvent
Set evline = Map1.TrackingLayer.AddEvent(line, 1)
ElseIf Option8.Value Then
Dim poly As New MapObjects2.Polygon
Set poly = Map1.TrackPolygon
Set trackShape = poly
Dim evpoly As New MapObjects2.GeoEvent
Set evpoly = Map1.TrackingLayer.AddEvent(poly, 2)
End If
End Function
Private Sub drawRes(shape As Object) '在Trackinglayer上通过添加Geoevent的方法绘制shape
Dim res As New MapObjects2.GeoEvent
If shape.shapeType = moLine Then
Set res = Map1.TrackingLayer.AddEvent(shape, 4)
ElseIf shape.shapeType = moShapeTypePolygon Or shape.shapeType = moShapeTypeRectangle Then
Set res = Map1.TrackingLayer.AddEvent(shape, 3)
ElseIf shape.shapeType = moShapeTypePoint Or shape.shapeType = moShapeTypeMultipoint Then
Set res = Map1.TrackingLayer.AddEvent(shape, 5)
End If
End Sub
责任编辑:小草